コード例 #1
0
        private void ValidateJsonOptions(RecurringJobJsonOptions option)
        {
            if (option == null)
            {
                throw new ArgumentNullException(nameof(option));
            }

            if (string.IsNullOrWhiteSpace(option.JobName))
            {
                throw new Exception($"The json token 'job-name' is null, empty, or consists only of white-space.");
            }

            if (!option.JobType.GetTypeInfo().ImplementedInterfaces.Contains(typeof(IRecurringJob)))
            {
                throw new Exception($"job-type: {option.JobType} must impl the interface {typeof(IRecurringJob)}.");
            }
        }
コード例 #2
0
        private RecurringJobInfo Convert(RecurringJobJsonOptions option)
        {
            ValidateJsonOptions(option);

            return(new RecurringJobInfo
            {
                RecurringJobId = option.JobName,
#if NET45
                Method = option.JobType.GetMethod(nameof(IRecurringJob.Execute)),
#else
                Method = option.JobType.GetTypeInfo().GetDeclaredMethod(nameof(IRecurringJob.Execute)),
#endif
                Cron = option.Cron,
                Queue = option.Queue ?? EnqueuedState.DefaultQueue,
                TimeZone = option.TimeZone ?? TimeZoneInfo.Utc,
                ExtendedData = option.ExtendedData,
                Enable = option.Enable ?? true
            });
        }
        private RecurringJobInfo Convert(RecurringJobJsonOptions option)
        {
            ValidateJsonOptions(option);
            var method = option.JobType.GetMethod(nameof(IRecurringJob.Execute));

            if (method == null)
            {
                throw new Exception($"The job object {option.JobName} does not have the method {nameof(IRecurringJob.Execute)}.");
            }
            return(new RecurringJobInfo
            {
                RecurringJobId = option.JobName,
                Method = method,
                Cron = option.Cron,
                Queue = option.Queue ?? EnqueuedState.DefaultQueue,
                TimeZone = option.TimeZone ?? TimeZoneInfo.Utc,
                JobData = option.JobData,
                Enable = option.Enable ?? true
            });
        }