DeleteServerMessageJob.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using Dapper;
  2. using EVCB_OCPP.Domain;
  3. using EVCB_OCPP.TaskScheduler.Helper;
  4. using Microsoft.Data.SqlClient;
  5. using Microsoft.Extensions.Logging;
  6. using Quartz;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace EVCB_OCPP.TaskScheduler.Jobs
  13. {
  14. [DisallowConcurrentExecution]
  15. public class DeleteServerMessageJob : IJob
  16. {
  17. public DeleteServerMessageJob(ILogger<DeleteServerMessageJob> logger, SqlConnectionFactory<MainDBContext> mainDBConnectionFactory)
  18. {
  19. this.logger = logger;
  20. this.mainDBConnectionFactory = mainDBConnectionFactory;
  21. }
  22. private readonly ILogger<DeleteServerMessageJob> logger;
  23. private readonly SqlConnectionFactory<MainDBContext> mainDBConnectionFactory;
  24. public async Task Execute(IJobExecutionContext context)
  25. {
  26. logger.LogDebug(this.ToString() + " :Start........");
  27. int counter = 0;
  28. while (counter < 5)
  29. {
  30. counter++;
  31. using (var dbConn = await mainDBConnectionFactory.CreateAsync())
  32. {
  33. dbConn.Open();
  34. string sqlstring = "Delete Top(10000) from ServerMessage";
  35. await dbConn.ExecuteAsync(sqlstring);
  36. }
  37. }
  38. logger.LogDebug(this.ToString() + " :Finished........");
  39. }
  40. }
  41. }