Esempio n. 1
0
        private static TriggerBuilder addTriger(Config item)
        {
            var trigger = TriggerBuilder.Create()
                          .WithIdentity(item.jobname + "trigger", "触发器组");

            //con语法
            if (!string.IsNullOrEmpty(item.cronschedule))
            {
                trigger = trigger.WithCronSchedule(item.cronschedule);
            }
            else
            {

                if (item.starttime.HasValue)
                {
                    trigger = trigger.StartAt(item.starttime.Value);
                }
                else
                {
                    trigger = trigger.StartNow();
                }

                if (item.endtime.HasValue)
                {
                    trigger = trigger.EndAt(item.endtime.Value);
                }

                //SimpleSchedule

                Action<SimpleScheduleBuilder> action;

                if (item.isrepeat)
                {
                    action = (x) => { x.WithIntervalInSeconds(item.interval.Value); x.RepeatForever(); };
                }
                else
                {
                    action = (x) => { x.WithRepeatCount(item.repeatcoount.Value); x.WithIntervalInSeconds(item.interval.Value); };
                }

                trigger = trigger.WithSimpleSchedule(action);

            }
            return trigger;
        }