Beispiel #1
0
        public override void ScheduleTask(Task task)
        {
            RecurringSchedule schedule = task.Schedule as RecurringSchedule;

            if (schedule == null)
            {
                return;
            }

            DateTime executionTime = (schedule.MissedPreviousSchedule &&
                                      ManagerLibrary.Instance.Settings.ExecuteMissedTasksImmediately) ?
                                     DateTime.Now : schedule.NextRun;

            lock (tasksLock)
            {
                if (!scheduledTasks.ContainsKey(executionTime))
                {
                    scheduledTasks.Add(executionTime, new List <Task>());
                }
                scheduledTasks[executionTime].Add(task);
            }
        }
 private void UpdateTaskFromUI()
 {
     task.Name = name.Text;
        if (typeManual.Checked)
        {
     task.Schedule = Schedule.RunManually;
        }
        else if (typeImmediate.Checked)
        {
     task.Schedule = Schedule.RunNow;
        }
        else if (typeRestart.Checked)
        {
     task.Schedule = Schedule.RunOnRestart;
        }
        else if (typeRecurring.Checked)
        {
     RecurringSchedule schedule = new RecurringSchedule();
     task.Schedule = schedule;
     schedule.ExecutionTime = new DateTime(1, 1, 1, scheduleTime.Value.Hour,
      scheduleTime.Value.Minute, scheduleTime.Value.Second);
     if (scheduleDaily.Checked)
     {
      if (scheduleDailyByDay.Checked)
      {
       schedule.ScheduleType = RecurringScheduleUnit.Daily;
       schedule.Frequency = (int)scheduleDailyByDayFreq.Value;
      }
      else
      {
       schedule.ScheduleType = RecurringScheduleUnit.Weekdays;
      }
     }
     else if (scheduleWeekly.Checked)
     {
      schedule.ScheduleType = RecurringScheduleUnit.Weekly;
      schedule.Frequency = (int)scheduleWeeklyFreq.Value;
      DaysOfWeek weeklySchedule = 0;
      if (scheduleWeeklyMonday.Checked)
       weeklySchedule |= DaysOfWeek.Monday;
      if (scheduleWeeklyTuesday.Checked)
       weeklySchedule |= DaysOfWeek.Tuesday;
      if (scheduleWeeklyWednesday.Checked)
       weeklySchedule |= DaysOfWeek.Wednesday;
      if (scheduleWeeklyThursday.Checked)
       weeklySchedule |= DaysOfWeek.Thursday;
      if (scheduleWeeklyFriday.Checked)
       weeklySchedule |= DaysOfWeek.Friday;
      if (scheduleWeeklySaturday.Checked)
       weeklySchedule |= DaysOfWeek.Saturday;
      if (scheduleWeeklySunday.Checked)
       weeklySchedule |= DaysOfWeek.Sunday;
      schedule.WeeklySchedule = weeklySchedule;
     }
     else if (scheduleMonthly.Checked)
     {
      schedule.ScheduleType = RecurringScheduleUnit.Monthly;
      schedule.Frequency = (int)scheduleMonthlyFreq.Value;
      schedule.MonthlySchedule = (int)scheduleMonthlyDayNumber.Value;
     }
     else
      throw new ArgumentException("No such scheduling method.");
        }
 }