using DigitalData.Modules.Base; using DigitalData.Modules.Logging; using EnvelopeGenerator.Common; using Quartz; using System; using System.Collections.Specialized; using System.ComponentModel.DataAnnotations; namespace EnvelopeGenerator.Web { public class Scheduler : BaseClass { private const string DATABASE = "DATABASE"; private const string LOGCONFIG = "LOGCONFIG"; private string ConnectionString; public Scheduler(LogConfig logConfig, string connectionString) : base(logConfig) { this.ConnectionString = connectionString; } public void ScheduleJob(IServiceCollectionQuartzConfigurator q, string name, int interval) where TJob : IJob { var jobKey = new JobKey(name); var jobData = new JobDataMap { { DATABASE, ConnectionString }, { LOGCONFIG, LogConfig } }; q.AddJob(opts => opts .WithIdentity(jobKey) .UsingJobData(jobData)); q.AddTrigger(opts => opts .ForJob(jobKey) .WithIdentity($"{name}-trigger") .WithSimpleSchedule(s => s .RepeatForever() .WithIntervalInMinutes(interval))); } } }