/// <summary> /// Initialize the cache by performing the initial data population and setting up the scheduler. /// </summary> public static void Initialize() { if (startHour < 0 || startHour > 23) { throw new ConfigurationErrorsException("cache:RefreshHourOfDay must be between 0 and 23."); } if (interval < 1) { throw new ConfigurationErrorsException("cache:RefreshIntervalHours must be greater than 1."); } // Performs initial data population ContactMap.Refresh(); // Setting up the scheduler IScheduler scheduler = Quartz.Impl.StdSchedulerFactory.GetDefaultScheduler(); scheduler.Start(); IJobDetail job = JobBuilder.Create <ContactMapRefreshJob>().Build(); ITrigger trigger = TriggerBuilder.Create() .WithDailyTimeIntervalSchedule (s => s.WithIntervalInHours(interval) .OnEveryDay() .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(startHour, 0)) ) .Build(); scheduler.ScheduleJob(job, trigger); }
/// <summary> /// Callback for scheduled execution. /// </summary> /// <param name="context">The execution context</param> public void Execute(IJobExecutionContext context) { ContactMap.Refresh(); }