Esempio n. 1
0
        private static ITrigger DefineIntervalTrigger(string identity, DateTime startTime, IntervalType intervalType, int span, int count)
        {
            var trigger = TriggerBuilder.Create()
                          .WithIdentity(identity, Guid.NewGuid().ToString());

            trigger.StartAt(startTime);
            switch (intervalType)
            {
            case IntervalType.Hourly:
                trigger.WithSchedule(count == 0
                        ? SimpleScheduleBuilder.RepeatHourlyForever(span)
                        : SimpleScheduleBuilder.RepeatHourlyForTotalCount(count, span));
                break;

            case IntervalType.Minutely:
                trigger.WithSchedule(count == 0
                        ? SimpleScheduleBuilder.RepeatMinutelyForever(span)
                        : SimpleScheduleBuilder.RepeatMinutelyForTotalCount(count, span));
                break;

            case IntervalType.Secondly:
                trigger.WithSchedule(count == 0
                        ? SimpleScheduleBuilder.RepeatSecondlyForever(span)
                        : SimpleScheduleBuilder.RepeatSecondlyForTotalCount(count, span));
                break;

            case IntervalType.None:
                break;

            default:
                break;
            }
            return(trigger.Build());
        }
Esempio n. 2
0
    public void Run(object input)
    {
        // Create the schedule for the 'Execute' method.
        var job      = JobBuilder.Create <ScheduledWork>().Build();
        var schedule = SimpleScheduleBuilder.RepeatHourlyForTotalCount(10);
        var trigger  = TriggerBuilder.Create().WithSchedule(schedule).StartNow().Build();

        ScheduleManager.Instance.ScheduleJob(job, trigger);
    }
Esempio n. 3
0
        private static ITrigger DefineIntervalTrigger(string _identity, DateTime _startTime, IntervalType _intervalType, int span, int count)
        {
            ITrigger trigger;
            var      _trigger = TriggerBuilder.Create()
                                .WithIdentity(_identity, Guid.NewGuid().ToString());

            _trigger.StartAt(_startTime);
            switch (_intervalType)
            {
            case IntervalType.Hourly:
                if (count == 0)
                {
                    _trigger.WithSchedule(SimpleScheduleBuilder.RepeatHourlyForever(span));
                }
                else
                {
                    _trigger.WithSchedule(SimpleScheduleBuilder.RepeatHourlyForTotalCount(count, span));
                }
                break;

            case IntervalType.Minutely:
                if (count == 0)
                {
                    _trigger.WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForever(span));
                }
                else
                {
                    _trigger.WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForTotalCount(count, span));
                }
                break;

            case IntervalType.Secondly:
                if (count == 0)
                {
                    _trigger.WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForever(span));
                }
                else
                {
                    _trigger.WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForTotalCount(count, span));
                }
                break;

            default:
                break;
            }
            trigger = _trigger.Build();
            return(trigger);
        }
        public void AddAndScheduleGenericJob <T>(string jobName, string jobGroupName, string triggerName, string triggerGroupName, QuickRepeatIntervals quickRepeatInterval, int intervalValue, int?nTimes) where T : class
        {
            IScheduler scheduler = GetScheduler();

            JobDetailImpl jobDetail = new JobDetailImpl(jobName, jobGroupName, typeof(T));

            ITrigger trigger = null;

            switch (quickRepeatInterval)
            {
            case QuickRepeatIntervals.EverySecond:
                trigger = TriggerBuilder.Create()
                          .StartNow()
                          .WithIdentity(triggerName, triggerGroupName)
                          .WithSchedule(nTimes.HasValue ? SimpleScheduleBuilder.RepeatSecondlyForTotalCount(nTimes.Value, intervalValue) : SimpleScheduleBuilder.RepeatSecondlyForever(intervalValue))
                          .Build();
                break;

            case QuickRepeatIntervals.EveryMinute:
                trigger = TriggerBuilder.Create()
                          .StartNow()
                          .WithIdentity(triggerName, triggerGroupName)
                          .WithSchedule(nTimes.HasValue ? SimpleScheduleBuilder.RepeatMinutelyForTotalCount(nTimes.Value, intervalValue) : SimpleScheduleBuilder.RepeatMinutelyForever(intervalValue))
                          .Build();
                break;

            case QuickRepeatIntervals.EveryHour:
                trigger = TriggerBuilder.Create()
                          .StartNow()
                          .WithIdentity(triggerName, triggerGroupName)
                          .WithSchedule(nTimes.HasValue ? SimpleScheduleBuilder.RepeatHourlyForTotalCount(nTimes.Value, intervalValue) : SimpleScheduleBuilder.RepeatHourlyForever(intervalValue))
                          .Build();
                break;
            }

            scheduler.ScheduleJob(jobDetail, trigger);
            //scheduler.Shutdown();
        }