StopTransacionReportJob.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using EVCB_OCPP.TaskScheduler.Helper;
  2. using EVCB_OCPP.TaskScheduler.Services;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using Microsoft.Extensions.Logging;
  5. using Quartz;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace EVCB_OCPP.TaskScheduler.Jobs
  12. {
  13. [DisallowConcurrentExecution]
  14. public class StopTransacionReportJob : IJob
  15. {
  16. private readonly ICustomersService customersService;
  17. private readonly ILogger logger;
  18. public StopTransacionReportJob(ICustomersService customersService, ILogger<StopTransacionReportJob> logger)
  19. {
  20. this.customersService = customersService;
  21. this.logger = logger;
  22. }
  23. public async Task Execute(IJobExecutionContext context)
  24. {
  25. using var timer = TimerHelper.Start(this.ToString(), logger);
  26. List<Task> tList = new List<Task>();
  27. var cList = customersService.GetNotifyStopTransactionCustomers();
  28. foreach (var customerId in cList)
  29. {
  30. ICustomerService s = await customersService.GetCustomerService(customerId);
  31. tList.Add(DoMainTask(s));
  32. }
  33. await Task.WhenAll(tList.ToArray());
  34. logger.LogInformation("{0} complete", this.ToString());
  35. }
  36. private Task DoMainTask(ICustomerService _service)
  37. {
  38. return _service.ReportStopTransaction();
  39. }
  40. }
  41. }