public void Reload() { var newConfig = new Config(Filename); LastFileDate = newConfig.FileDate; // It's important to compare Config.Jobs first, since the "both" result will have items // from the first List - and the first list has all the Process identifiers, not newConfig. var result = ListHelper.Intersect(Config.Jobs, newConfig.Jobs, (job1, job2) => string.Compare(job1.GetJobCode(), job2.GetJobCode(), StringComparison.InvariantCulture)); Config.Jobs.Clear(); // Add jobs that exist in both new and old Config.Jobs.AddRange(result.Both); // Add new jobs foreach (var job in result.Right) { Logger.Log("Found new " + job.GetType().Name + ": " + job.Command); Config.Jobs.Add(job); } // End service jobs no longer existing foreach (var job in result.Left) { Logger.Log("Removing old " + job.GetType().Name + ": " + job.Command); if (job is ServiceJob) ((ServiceJob)job).Terminate(); } }
public CronManager(string filename) { Filename = filename; Config = new Config(Filename); LastFileDate = Config.FileDate; Logger.Log("{0} jobs in job list", Config.Jobs.Count); RunBootJobs(); if (Config.Settings.RunMissedJobs) Logger.Catch(delegate { var last = Registry.GetValue(RegKey, "LastRunTime", null) as string; DateTime lastDt; if (string.IsNullOrWhiteSpace(last) || !DateTime.TryParse(last, out lastDt) || lastDt >= DateTime.Now) return; Logger.Debug("Run missed jobs mode - recalculating jobs execution time from last activity..."); foreach (var job in Config.CronJobs) job.RecalcNextExecTime(lastDt); }); }