/// <summary> /// Creates a new task for the <see cref="TaskScheduler"/> based on the given task. /// Used for the <see cref="ICloneable"/> implementation. /// </summary> /// <param name="task">The new task should be based upon.</param> public Task(Task task) { _taskID = task.ID; _owner = task.Owner; _schedule.Minute = task.Schedule.Minute; _schedule.Hour = task.Schedule.Hour; _schedule.Day = task.Schedule.Day; _schedule.Interval = task.Schedule.Interval; _schedule.Type = task.Schedule.Type; _expires = task.Expires; _forceRun = task.ForceRun; _wakeup = task.WakeupSystem; }
public Guid AddTask(Task newTask) { lock (_syncObj) { newTask.ID = Guid.NewGuid(); _settings.TaskCollection.Add(newTask); SaveChanges(false); } return newTask.ID; }
public void UpdateTask(Guid taskId, Task updatedTask) { lock (_syncObj) { updatedTask.ID = taskId; _settings.TaskCollection.Replace(taskId, updatedTask); SaveChanges(false); TaskSchedulerMessaging.SendTaskSchedulerMessage(TaskSchedulerMessaging.MessageType.CHANGED, updatedTask); } }
/// <summary> /// Handles expired tasks: Sends out a message that a particular task is expired, removes the task from the /// registered task collection and sends out a message that the task is deleted. This method gets called /// from the DoWork() method. /// </summary> /// <param name="task">Task to expire</param> private void ExpireTask(Task task) { Task tc = (Task) task.Clone(); TaskSchedulerMessaging.SendTaskSchedulerMessage(TaskSchedulerMessaging.MessageType.EXPIRED, tc); _settings.TaskCollection.Remove(task); TaskSchedulerMessaging.SendTaskSchedulerMessage(TaskSchedulerMessaging.MessageType.DELETED, tc); SaveChanges(false); }
/// <summary> /// Handles processing of due tasks. Sends out a message that a task is due, updates the tasks properties and /// removes the task if it was scheduled to run only once. This method gets called from the DoWork() method. /// </summary> /// <param name="task">Task to process.</param> private void ProcessTask(Task task) { Task tc = (Task) task.Clone(); TaskSchedulerMessaging.SendTaskSchedulerMessage(TaskSchedulerMessaging.MessageType.DUE, tc); task.LastRun = task.NextRun; if (task.Occurrence == Occurrence.Once) { _settings.TaskCollection.Remove(task); TaskSchedulerMessaging.SendTaskSchedulerMessage(TaskSchedulerMessaging.MessageType.DELETED, tc); } }
public const string TASK = "Task"; // Stores the task of this message /// <summary> /// Sends a message in the <see cref="CHANNEL"/>. /// </summary> /// <param name="type">The type of the message to send.</param> /// <param name="task">The task of the message to send.</param> public static void SendTaskSchedulerMessage(MessageType type, Task task) { SystemMessage msg = new SystemMessage(type); msg.MessageData[TASK] = task; ServiceRegistration.Get<IMessageBroker>().Send(CHANNEL, msg); }
public void UpdateTask(Guid taskId, Task updatedTask) { lock (_syncObj) { updatedTask.ID = taskId; ServiceRegistration.Get<ILogger>().Debug("TaskScheduler: UpdateTask: {0}", updatedTask); _settings.TaskCollection.Replace(taskId, updatedTask); SaveChanges(false); TaskSchedulerMessaging.SendTaskSchedulerMessage(TaskSchedulerMessaging.MessageType.CHANGED, updatedTask); } }
public Guid AddTask(Task newTask) { lock (_syncObj) { newTask.ID = Guid.NewGuid(); ServiceRegistration.Get<ILogger>().Debug("TaskScheduler: AddTask: {0}", newTask); _settings.TaskCollection.Add(newTask); SaveChanges(false); } return newTask.ID; }
/// <summary> /// Handles processing of due tasks. Sends out a message that a task is due, updates the tasks properties and /// removes the task if it was scheduled to run only once. This method gets called from the DoWork() method. /// </summary> /// <param name="task">Task to process.</param> private void ProcessTask(Task task) { ServiceRegistration.Get<ILogger>().Debug("TaskScheduler: ProcessTask: {0}", task.ToString()); Task tc = (Task) task.Clone(); TaskSchedulerMessaging.SendTaskSchedulerMessage(TaskSchedulerMessaging.MessageType.DUE, tc); task.LastRun = task.NextRun; if (task.Occurrence == Occurrence.Once) { _settings.TaskCollection.Remove(task); TaskSchedulerMessaging.SendTaskSchedulerMessage(TaskSchedulerMessaging.MessageType.DELETED, tc); } }
/// <summary> /// Handles expired tasks: Sends out a message that a particular task is expired, removes the task from the /// registered task collection and sends out a message that the task is deleted. This method gets called /// from the DoWork() method. /// </summary> /// <param name="task">Task to expire</param> private void ExpireTask(Task task) { ServiceRegistration.Get<ILogger>().Debug("TaskScheduler: ExpireTask: {0}", task.ToString()); Task tc = (Task) task.Clone(); TaskSchedulerMessaging.SendTaskSchedulerMessage(TaskSchedulerMessaging.MessageType.EXPIRED, tc); _settings.TaskCollection.Remove(task); TaskSchedulerMessaging.SendTaskSchedulerMessage(TaskSchedulerMessaging.MessageType.DELETED, tc); SaveChanges(false); }