HostedProtalServer.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using EVCB_OCPP.WSServer.Jobs;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using Quartz;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace EVCB_OCPP.WSServer
  10. {
  11. public static class HostedProtalServer
  12. {
  13. public static void AddProtalServer(this IServiceCollection services)
  14. {
  15. services.AddSingleton<ProtalServer>();
  16. services.AddHostedService<ProtalServer>(p => p.GetRequiredService<ProtalServer>());
  17. services.AddProtalServerJob();
  18. }
  19. public static void AddProtalServerJob(this IServiceCollection services)
  20. {
  21. services.AddQuartz(q => {
  22. q.UseMicrosoftDependencyInjectionJobFactory();
  23. var ServerUpdateJobKey = new JobKey("job1", "group1");
  24. q.AddJob<ServerUpdateJob>(opts => { opts.WithIdentity(ServerUpdateJobKey); });
  25. q.AddTrigger(opts =>
  26. {
  27. opts
  28. .ForJob(ServerUpdateJobKey)
  29. .WithIdentity("trigger1", "group1")
  30. .StartNow()
  31. .WithSimpleSchedule(x => x
  32. .WithIntervalInMinutes(3)
  33. .RepeatForever());
  34. });
  35. var ServerSetFeeJobKey = new JobKey("job2", "group1");
  36. q.AddJob<ServerSetFeeJob>(opts => { opts.WithIdentity(ServerSetFeeJobKey); });
  37. q.AddTrigger(opts =>
  38. {
  39. opts
  40. .ForJob(ServerSetFeeJobKey)
  41. .WithIdentity("trigger2", "group1")
  42. .StartNow()
  43. .WithSimpleSchedule(x => x
  44. .WithIntervalInMinutes(1)
  45. .RepeatForever());
  46. });
  47. var ServerMessageJobKey = new JobKey("job3", "group1");
  48. q.AddJob<ServerMessageJob>(opts => { opts.WithIdentity(ServerMessageJobKey); });
  49. q.AddTrigger(opts =>
  50. {
  51. opts
  52. .ForJob(ServerMessageJobKey)
  53. .WithIdentity("trigger3", "group1")
  54. .StartNow()
  55. .WithSimpleSchedule(x => x
  56. .WithInterval(TimeSpan.FromMilliseconds(500))
  57. .RepeatForever());
  58. });
  59. var HeartBeatCheckJobbKey = new JobKey("job4", "group1");
  60. q.AddJob<HeartBeatCheckJob>(opts => { opts.WithIdentity(HeartBeatCheckJobbKey); });
  61. q.AddTrigger(opts =>
  62. {
  63. opts
  64. .ForJob(HeartBeatCheckJobbKey)
  65. .WithIdentity("trigger4", "group1")
  66. .StartNow()
  67. .WithSimpleSchedule(x => x
  68. .WithIntervalInSeconds(30)
  69. .RepeatForever());
  70. });
  71. var ServerWeatherNotificationJobKey = new JobKey("job5", "group1");
  72. q.AddJob<ServerWeatherNotificationJob>(opts => { opts.WithIdentity(ServerWeatherNotificationJobKey); });
  73. q.AddTrigger(opts =>
  74. {
  75. opts
  76. .ForJob(ServerWeatherNotificationJobKey)
  77. .WithIdentity("trigger5", "group1")
  78. .StartNow()
  79. .WithSimpleSchedule(x => x
  80. .WithIntervalInMinutes(1)
  81. .RepeatForever());
  82. });
  83. var HealthCheckTriggerJobKey = new JobKey("job6", "group1");
  84. q.AddJob<HealthCheckTriggerJob>(opts => { opts.WithIdentity(HealthCheckTriggerJobKey); });
  85. q.AddTrigger(opts =>
  86. {
  87. opts
  88. .ForJob(HealthCheckTriggerJobKey)
  89. .WithIdentity("trigger6", "group1")
  90. .StartNow()
  91. .WithSimpleSchedule(x => x
  92. .WithIntervalInMinutes(1)
  93. .RepeatForever());
  94. });
  95. var SmartChargingJobKey = new JobKey("job7", "group1");
  96. q.AddJob<SmartChargingJob>(opts => { opts.WithIdentity(SmartChargingJobKey); });
  97. q.AddTrigger(opts =>
  98. {
  99. opts
  100. .ForJob(SmartChargingJobKey)
  101. .WithIdentity("trigger7", "group1")
  102. .StartNow()
  103. .WithSimpleSchedule(x => x
  104. .WithIntervalInMinutes(1)
  105. .RepeatForever());
  106. });
  107. //var DenyModelCheckJobKey = new JobKey("job8", "group1");
  108. //q.AddJob<DenyModelCheckJob>(opts => { opts.WithIdentity(DenyModelCheckJobKey); });
  109. //q.AddTrigger(opts =>
  110. //{
  111. // opts
  112. // .ForJob(DenyModelCheckJobKey)
  113. // .WithIdentity("trigger8", "group1")
  114. // .StartNow()
  115. // .WithSimpleSchedule(x => x
  116. // .WithIntervalInMinutes(5)
  117. // .RepeatForever());
  118. //});
  119. });
  120. services.AddQuartzHostedService(opt =>
  121. {
  122. opt.WaitForJobsToComplete = true;
  123. });
  124. }
  125. }
  126. }