Exemple #1
0
        /// <summary>
        /// Schedules the Task to Begin based on the Trigger including the DataMap
        /// </summary>
        /// <param name="Trigger">Trigger for the Task</param>
        /// <param name="DataMap">DataMap passed into the executing Task</param>
        /// <returns></returns>
        protected ScheduledTaskStatus ScheduleTask(TriggerBuilder Trigger, JobDataMap DataMap)
        {
            if (Trigger == null)
                Trigger = TriggerBuilder.Create(); // Defaults to Start Immediately

            if (DataMap != null)
                Trigger = Trigger.UsingJobData(DataMap);

            return ScheduledTasks.RegisterTask(this, Trigger);
        }
Exemple #2
0
        public static ScheduledTaskStatus RegisterTask(ScheduledTask Task, TriggerBuilder TaskBuilder)
        {
            var sessionId = Guid.NewGuid().ToString("D");
            var triggerKey = GenerateTriggerKey();
            var taskType = Task.GetType();

            var taskStatus = new ScheduledTaskStatus(Task, sessionId, triggerKey.Name);

            lock (_RunningTasksLock)
            {
                if (Task.SingleInstanceTask)
                {
                    var existingGuid = _RunningTasks.Where(t => t.IsRunning && t.TaskType == taskType).Select(t => t.SessionId).FirstOrDefault();
                    if (existingGuid != null)
                        throw new InvalidOperationException(string.Format("This Single-Instance Task is already running, SessionId: {0}", existingGuid));
                }
                _RunningTasks.Add(taskStatus);
            }

            if (TaskBuilder != null)
            {
                ITrigger trigger = TaskBuilder.WithIdentity(triggerKey).Build();
                IJobDetail jobDetails = new JobDetailImpl(sessionId, taskType)
                {
                    Description = Task.TaskName,
                    JobDataMap = trigger.JobDataMap
                };

                _TaskScheduler.ScheduleJob(jobDetails, trigger);

                var nextTriggerTime = trigger.GetNextFireTimeUtc();
                if (nextTriggerTime.HasValue)
                    taskStatus.SetNextScheduledTimestamp(nextTriggerTime.Value.LocalDateTime);
            }

            return taskStatus;
        }
        public static TriggerBuilder WithDailyTimeIntervalSchedule(this TriggerBuilder triggerBuilder)
        {
            DailyTimeIntervalScheduleBuilder builder = DailyTimeIntervalScheduleBuilder.Create();

            return(triggerBuilder.WithSchedule(builder));
        }
 /// <summary>
 /// Adds the specified trigger and calendar as a pair.
 /// </summary>
 /// <param name="trigger">The trigger.</param>
 /// <param name="calendar">The calendar.</param>
 public void Add(TriggerBuilder trigger, ICalendar calendar)
 {
     RegisterGroups.Add(new RegisterGroup(trigger, calendar));
 }
 /// <summary>
 /// Adds the specified trigger builder.
 /// </summary>
 /// <param name="triggerBuilder">The trigger builder.</param>
 public void Add(TriggerBuilder triggerBuilder)
 {
     RegisterGroups.Add(new RegisterGroup(triggerBuilder));
 }
 public RegisterGroup(TriggerBuilder trigger, ICalendar calendar)
 {
     TriggerBuilder = trigger;
     Calendar = calendar;
 }
 public RegisterGroup(TriggerBuilder trigger)
 {
     TriggerBuilder = trigger;
 }
        public static TriggerBuilder WithCalendarIntervalSchedule(this TriggerBuilder triggerBuilder)
        {
            CalendarIntervalScheduleBuilder builder = CalendarIntervalScheduleBuilder.Create();

            return(triggerBuilder.WithSchedule(builder));
        }
        public static TriggerBuilder WithSimpleSchedule(this TriggerBuilder triggerBuilder)
        {
            SimpleScheduleBuilder builder = SimpleScheduleBuilder.Create();

            return(triggerBuilder.WithSchedule(builder));
        }
        public static TriggerBuilder WithCronSchedule(this TriggerBuilder triggerBuilder, string cronExpression)
        {
            CronScheduleBuilder builder = CronScheduleBuilder.CronSchedule(cronExpression);

            return(triggerBuilder.WithSchedule(builder));
        }
Exemple #11
0
 /// <summary>
 /// Schedules the Task to Begin based on the Trigger
 /// </summary>
 /// <param name="Trigger">Trigger for the Task</param>
 protected ScheduledTaskStatus ScheduleTask(TriggerBuilder Trigger)
 {
     return ScheduleTask(Trigger, null);
 }