/// <summary>
        /// use SettingCronJobBuilder for preparing SettingCronJob
        /// </summary>
        /// <param name="recurringJobManager"></param>
        /// <param name="settingsManager"></param>
        /// <param name="settingCronJob"></param>
        /// <returns></returns>
        public static Task WatchJobSettingAsync(this IRecurringJobManager recurringJobManager,
                                                ISettingsManager settingsManager,
                                                SettingCronJob settingCronJob)
        {
            if (recurringJobManager == null)
            {
                throw new ArgumentNullException(nameof(recurringJobManager));
            }
            if (settingsManager == null)
            {
                throw new ArgumentNullException(nameof(settingsManager));
            }

            _observedSettingsDict.AddOrUpdate(settingCronJob.EnableSetting.Name, settingCronJob, (settingName, сronJob) => settingCronJob);
            _observedSettingsDict.AddOrUpdate(settingCronJob.CronSetting.Name, settingCronJob, (settingName, сronJob) => settingCronJob);

            return(RunOrRemoveJobAsync(recurringJobManager, settingsManager, settingCronJob));
        }
 public SettingCronJobBuilder(SettingCronJob settingCronJob)
 {
     _settingCronJob = settingCronJob;
 }
 public SettingCronJobBuilder()
 {
     _settingCronJob = new SettingCronJob();
 }
 /// <summary>
 /// use SettingCronJobBuilder for preparing SettingCronJob
 /// </summary>
 /// <param name="recurringJobManager"></param>
 /// <param name="settingsManager"></param>
 /// <param name="settingCronJob"></param>
 /// <returns></returns>
 public static void WatchJobSetting(this IRecurringJobManager recurringJobManager,
                                    ISettingsManager settingsManager,
                                    SettingCronJob settingCronJob)
 {
     WatchJobSettingAsync(recurringJobManager, settingsManager, settingCronJob).GetAwaiter().GetResult();
 }
        private static async Task RunOrRemoveJobAsync(this IRecurringJobManager recurringJobManager, ISettingsManager settingsManager, SettingCronJob settingCronJob)
        {
            var processJobEnable = await settingsManager.GetValueAsync(settingCronJob.EnableSetting.Name, (bool)settingCronJob.EnableSetting.DefaultValue);

            if (processJobEnable)
            {
                var cronExpression = await settingsManager.GetValueAsync(settingCronJob.CronSetting.Name, settingCronJob.CronSetting.DefaultValue.ToString());

                recurringJobManager.AddOrUpdate(
                    settingCronJob.RecurringJobId,
                    settingCronJob.Job,
                    cronExpression,
                    settingCronJob.TimeZone,
                    settingCronJob.Queue);
            }
            else
            {
                recurringJobManager.RemoveIfExists(settingCronJob.RecurringJobId);
            }
        }