예제 #1
0
 /// <summary>
 /// 创建类型Cron的触发器
 /// </summary>
 /// <param name="m"></param>
 /// <returns></returns>
 private static ITrigger CreateCronTrigger(this QuartzOption QuartzOptions)
 {
     if (QuartzOptions is null)
     {
         throw new ArgumentNullException(nameof(QuartzOptions));
     }
     return(QuartzOptions.GetTriggerBuilder()
            .WithCronSchedule(QuartzOptions.Interval, x => x.WithMisfireHandlingInstructionDoNothing()).Build());
 }
예제 #2
0
        /// <summary>
        /// 创建一个SimpleTrigger
        /// </summary>
        /// <param name="QuartzOptions"></param>
        /// <returns></returns>
        private static ITrigger CreateSimpleTrigger(this QuartzOption QuartzOptions)
        {
            if (QuartzOptions is null)
            {
                throw new ArgumentNullException(nameof(QuartzOptions));
            }

            var intervalArr = QuartzOptions.Interval.Split(',');

            if (intervalArr.Length < 2 || !SimpleStrategy.Contains(intervalArr[0]) || !int.TryParse(intervalArr[1], out int time))
            {
                throw new IndexOutOfRangeException("CreateSimpleTrigger  轮询策略 错误,必须为 ss,时间,mm,时间,HH,时间 ");
            }
            var timeType = intervalArr[0];

            return(QuartzOptions.GetTriggerBuilder()
                   .WithSimpleSchedule(scheduleBuilder =>
            {
                switch (timeType)
                {
                case "ss":
                    scheduleBuilder.WithIntervalInSeconds(time);
                    break;

                case "mm":
                    scheduleBuilder.WithIntervalInMinutes(time);
                    break;

                case "HH":
                    scheduleBuilder.WithIntervalInHours(time);
                    break;

                default:
                    throw new NotImplementedException();
                }
                if (QuartzOptions.RunTimes > 0)
                {
                    scheduleBuilder.WithRepeatCount(QuartzOptions.RunTimes);
                }
                else
                {
                    scheduleBuilder.RepeatForever();
                }
            }).Build());
        }