StationConfigPollingJob.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using EVCB_OCPP.WSServer.Service.DbService;
  2. using Quartz;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace EVCB_OCPP.WSServer.Jobs
  9. {
  10. [DisallowConcurrentExecution]
  11. internal class StationConfigPollingJob : IJob
  12. {
  13. public StationConfigPollingJob(
  14. ProtalServer protalServer,
  15. WebDbService webDbService)
  16. {
  17. this.protalServer = protalServer;
  18. this.webDbService = webDbService;
  19. }
  20. private readonly ProtalServer protalServer;
  21. private readonly WebDbService webDbService;
  22. public async Task Execute(IJobExecutionContext context)
  23. {
  24. var connectedEvses = protalServer.GetClientDic();
  25. connectedEvses = connectedEvses.Where(x => x.Value.IsCheckIn = true).ToDictionary(x=>x.Key, x=>x.Value);
  26. Dictionary<int, Dictionary<string, string>> stationEvseConfigs = await webDbService.GetStationEvseConfigs();
  27. Dictionary<string, int> evseStationPair = await webDbService.GetEvseStationPair(connectedEvses.Keys.ToList());
  28. foreach ( var chargboxId in connectedEvses.Keys )
  29. {
  30. if (!evseStationPair.ContainsKey(chargboxId))
  31. {
  32. continue;
  33. }
  34. var stationId = evseStationPair[chargboxId];
  35. var configs = stationEvseConfigs[stationId];
  36. await protalServer.CheckandUpdateConfig(chargboxId, configs);
  37. }
  38. }
  39. }
  40. }