123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- using EVCB_OCPP.WSServer.Jobs;
- using Microsoft.Extensions.DependencyInjection;
- using OCPPServer.Protocol;
- using Quartz;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace EVCB_OCPP.WSServer
- {
- public static class HostedProtalServer
- {
- public static void AddProtalServer(this IServiceCollection services)
- {
- services.AddTransient<OCPPWSServer>();
- services.AddTransient<IOCPPWSServerFactory, OCPPWSServerFactory>();
- services.AddSingleton<ProtalServer>();
- services.AddHostedService<ProtalServer>(p => p.GetRequiredService<ProtalServer>());
- services.AddProtalServerJob();
- }
- public static void AddProtalServerJob(this IServiceCollection services)
- {
- services.AddQuartz(q => {
- q.UseMicrosoftDependencyInjectionJobFactory();
- var ServerUpdateJobKey = new JobKey("job1", "group1");
- q.AddJob<ServerUpdateJob>(opts => { opts.WithIdentity(ServerUpdateJobKey); });
- q.AddTrigger(opts =>
- {
- opts
- .ForJob(ServerUpdateJobKey)
- .WithIdentity("trigger1", "group1")
- .StartNow()
- .WithSimpleSchedule(x => x
- .WithIntervalInMinutes(3)
- .RepeatForever());
- });
- var ServerSetFeeJobKey = new JobKey("job2", "group1");
- q.AddJob<ServerSetFeeJob>(opts => { opts.WithIdentity(ServerSetFeeJobKey); });
- q.AddTrigger(opts =>
- {
- opts
- .ForJob(ServerSetFeeJobKey)
- .WithIdentity("trigger2", "group1")
- .StartNow()
- .WithSimpleSchedule(x => x
- .WithIntervalInMinutes(1)
- .RepeatForever());
- });
- var ServerMessageJobKey = new JobKey("job3", "group1");
- q.AddJob<ServerMessageJob>(opts => { opts.WithIdentity(ServerMessageJobKey); });
- q.AddTrigger(opts =>
- {
- opts
- .ForJob(ServerMessageJobKey)
- .WithIdentity("trigger3", "group1")
- .StartNow()
- .WithSimpleSchedule(x => x
- .WithInterval(TimeSpan.FromMilliseconds(500))
- .RepeatForever());
- });
- var HeartBeatCheckJobbKey = new JobKey("job4", "group1");
- q.AddJob<HeartBeatCheckJob>(opts => { opts.WithIdentity(HeartBeatCheckJobbKey); });
- q.AddTrigger(opts =>
- {
- opts
- .ForJob(HeartBeatCheckJobbKey)
- .WithIdentity("trigger4", "group1")
- .StartNow()
- .WithSimpleSchedule(x => x
- .WithIntervalInSeconds(30)
- .RepeatForever());
- });
- var ServerWeatherNotificationJobKey = new JobKey("job5", "group1");
- q.AddJob<ServerWeatherNotificationJob>(opts => { opts.WithIdentity(ServerWeatherNotificationJobKey); });
- q.AddTrigger(opts =>
- {
- opts
- .ForJob(ServerWeatherNotificationJobKey)
- .WithIdentity("trigger5", "group1")
- .StartNow()
- .WithSimpleSchedule(x => x
- .WithIntervalInMinutes(1)
- .RepeatForever());
- });
- var HealthCheckTriggerJobKey = new JobKey("job6", "group1");
- q.AddJob<HealthCheckTriggerJob>(opts => { opts.WithIdentity(HealthCheckTriggerJobKey); });
- q.AddTrigger(opts =>
- {
- opts
- .ForJob(HealthCheckTriggerJobKey)
- .WithIdentity("trigger6", "group1")
- .StartNow()
- .WithSimpleSchedule(x => x
- .WithIntervalInMinutes(1)
- .RepeatForever());
- });
- var SmartChargingJobKey = new JobKey("job7", "group1");
- q.AddJob<SmartChargingJob>(opts => { opts.WithIdentity(SmartChargingJobKey); });
- q.AddTrigger(opts =>
- {
- opts
- .ForJob(SmartChargingJobKey)
- .WithIdentity("trigger7", "group1")
- .StartNow()
- .WithSimpleSchedule(x => x
- .WithIntervalInMinutes(1)
- .RepeatForever());
- });
- //var DenyModelCheckJobKey = new JobKey("job8", "group1");
- //q.AddJob<DenyModelCheckJob>(opts => { opts.WithIdentity(DenyModelCheckJobKey); });
- //q.AddTrigger(opts =>
- //{
- // opts
- // .ForJob(DenyModelCheckJobKey)
- // .WithIdentity("trigger8", "group1")
- // .StartNow()
- // .WithSimpleSchedule(x => x
- // .WithIntervalInMinutes(5)
- // .RepeatForever());
- //});
- });
- services.AddQuartzHostedService(opt =>
- {
- opt.WaitForJobsToComplete = true;
- });
- }
- }
- }
|