diff options
Diffstat (limited to 'MediaBrowser.Model/Tasks')
| -rw-r--r-- | MediaBrowser.Model/Tasks/IScheduledTaskWorker.cs | 76 | ||||
| -rw-r--r-- | MediaBrowser.Model/Tasks/ITaskManager.cs | 80 | ||||
| -rw-r--r-- | MediaBrowser.Model/Tasks/ITaskTrigger.cs | 35 | ||||
| -rw-r--r-- | MediaBrowser.Model/Tasks/ScheduledTaskHelpers.cs | 52 | ||||
| -rw-r--r-- | MediaBrowser.Model/Tasks/TaskCompletionEventArgs.cs | 11 |
5 files changed, 254 insertions, 0 deletions
diff --git a/MediaBrowser.Model/Tasks/IScheduledTaskWorker.cs b/MediaBrowser.Model/Tasks/IScheduledTaskWorker.cs new file mode 100644 index 000000000..415207f8f --- /dev/null +++ b/MediaBrowser.Model/Tasks/IScheduledTaskWorker.cs @@ -0,0 +1,76 @@ +using System; +using MediaBrowser.Model.Events; + +namespace MediaBrowser.Model.Tasks +{ + /// <summary> + /// Interface IScheduledTaskWorker + /// </summary> + public interface IScheduledTaskWorker : IDisposable + { + /// <summary> + /// Occurs when [task progress]. + /// </summary> + event EventHandler<GenericEventArgs<double>> TaskProgress; + + /// <summary> + /// Gets or sets the scheduled task. + /// </summary> + /// <value>The scheduled task.</value> + IScheduledTask ScheduledTask { get; } + + /// <summary> + /// Gets the last execution result. + /// </summary> + /// <value>The last execution result.</value> + TaskResult LastExecutionResult { get; } + + /// <summary> + /// Gets the name. + /// </summary> + /// <value>The name.</value> + string Name { get; } + + /// <summary> + /// Gets the description. + /// </summary> + /// <value>The description.</value> + string Description { get; } + + /// <summary> + /// Gets the category. + /// </summary> + /// <value>The category.</value> + string Category { get; } + + /// <summary> + /// Gets the state. + /// </summary> + /// <value>The state.</value> + TaskState State { get; } + + /// <summary> + /// Gets the current progress. + /// </summary> + /// <value>The current progress.</value> + double? CurrentProgress { get; } + + /// <summary> + /// Gets the triggers that define when the task will run + /// </summary> + /// <value>The triggers.</value> + /// <exception cref="ArgumentNullException">value</exception> + TaskTriggerInfo[] Triggers { get; set; } + + /// <summary> + /// Gets the unique id. + /// </summary> + /// <value>The unique id.</value> + string Id { get; } + + /// <summary> + /// Reloads the trigger events. + /// </summary> + void ReloadTriggerEvents(); + } +}
\ No newline at end of file diff --git a/MediaBrowser.Model/Tasks/ITaskManager.cs b/MediaBrowser.Model/Tasks/ITaskManager.cs new file mode 100644 index 000000000..b6f847feb --- /dev/null +++ b/MediaBrowser.Model/Tasks/ITaskManager.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using MediaBrowser.Model.Events; + +namespace MediaBrowser.Model.Tasks +{ + public interface ITaskManager : IDisposable + { + /// <summary> + /// Gets the list of Scheduled Tasks + /// </summary> + /// <value>The scheduled tasks.</value> + IScheduledTaskWorker[] ScheduledTasks { get; } + + /// <summary> + /// Cancels if running and queue. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="options">Task options.</param> + void CancelIfRunningAndQueue<T>(TaskExecutionOptions options) + where T : IScheduledTask; + + /// <summary> + /// Cancels if running and queue. + /// </summary> + /// <typeparam name="T"></typeparam> + void CancelIfRunningAndQueue<T>() + where T : IScheduledTask; + + /// <summary> + /// Cancels if running. + /// </summary> + /// <typeparam name="T"></typeparam> + void CancelIfRunning<T>() + where T : IScheduledTask; + + /// <summary> + /// Queues the scheduled task. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="options">Task options.</param> + void QueueScheduledTask<T>(TaskExecutionOptions options) + where T : IScheduledTask; + + /// <summary> + /// Queues the scheduled task. + /// </summary> + /// <typeparam name="T"></typeparam> + void QueueScheduledTask<T>() + where T : IScheduledTask; + + void QueueIfNotRunning<T>() + where T : IScheduledTask; + + /// <summary> + /// Queues the scheduled task. + /// </summary> + /// <param name="task">The task.</param> + /// <param name="options">The task run options.</param> + void QueueScheduledTask(IScheduledTask task, TaskExecutionOptions options = null); + + /// <summary> + /// Adds the tasks. + /// </summary> + /// <param name="tasks">The tasks.</param> + void AddTasks(IEnumerable<IScheduledTask> tasks); + + void Cancel(IScheduledTaskWorker task); + Task Execute(IScheduledTaskWorker task, TaskExecutionOptions options = null); + + void Execute<T>() + where T : IScheduledTask; + + event EventHandler<GenericEventArgs<IScheduledTaskWorker>> TaskExecuting; + event EventHandler<TaskCompletionEventArgs> TaskCompleted; + + bool SuspendTriggers { get; set; } + } +}
\ No newline at end of file diff --git a/MediaBrowser.Model/Tasks/ITaskTrigger.cs b/MediaBrowser.Model/Tasks/ITaskTrigger.cs new file mode 100644 index 000000000..3beca569c --- /dev/null +++ b/MediaBrowser.Model/Tasks/ITaskTrigger.cs @@ -0,0 +1,35 @@ +using System; +using MediaBrowser.Model.Events; +using MediaBrowser.Model.Logging; + +namespace MediaBrowser.Model.Tasks +{ + /// <summary> + /// Interface ITaskTrigger + /// </summary> + public interface ITaskTrigger + { + /// <summary> + /// Fires when the trigger condition is satisfied and the task should run + /// </summary> + event EventHandler<GenericEventArgs<TaskExecutionOptions>> Triggered; + + /// <summary> + /// Stars waiting for the trigger action + /// </summary> + void Start(TaskResult lastResult, ILogger logger, string taskName, bool isApplicationStartup); + + /// <summary> + /// Stops waiting for the trigger action + /// </summary> + void Stop(); + + /// <summary> + /// Gets or sets the execution properties of this task. + /// </summary> + /// <value> + /// The execution properties of this task. + /// </value> + TaskExecutionOptions TaskOptions { get; set; } + } +}
\ No newline at end of file diff --git a/MediaBrowser.Model/Tasks/ScheduledTaskHelpers.cs b/MediaBrowser.Model/Tasks/ScheduledTaskHelpers.cs new file mode 100644 index 000000000..66f5294e7 --- /dev/null +++ b/MediaBrowser.Model/Tasks/ScheduledTaskHelpers.cs @@ -0,0 +1,52 @@ +using System; +using System.Linq; + +namespace MediaBrowser.Model.Tasks +{ + /// <summary> + /// Class ScheduledTaskHelpers + /// </summary> + public static class ScheduledTaskHelpers + { + /// <summary> + /// Gets the task info. + /// </summary> + /// <param name="task">The task.</param> + /// <returns>TaskInfo.</returns> + public static TaskInfo GetTaskInfo(IScheduledTaskWorker task) + { + var isHidden = false; + + var configurableTask = task.ScheduledTask as IConfigurableScheduledTask; + + if (configurableTask != null) + { + isHidden = configurableTask.IsHidden; + } + + string key = task.ScheduledTask.Key; + + var triggers = task.Triggers + .OrderBy(i => i.Type) + .ThenBy(i => i.DayOfWeek ?? DayOfWeek.Sunday) + .ThenBy(i => i.TimeOfDayTicks ?? 0) + .ToList(); + + return new TaskInfo + { + Name = task.Name, + CurrentProgressPercentage = task.CurrentProgress, + State = task.State, + Id = task.Id, + LastExecutionResult = task.LastExecutionResult, + + Triggers = triggers, + + Description = task.Description, + Category = task.Category, + IsHidden = isHidden, + Key = key + }; + } + } +} diff --git a/MediaBrowser.Model/Tasks/TaskCompletionEventArgs.cs b/MediaBrowser.Model/Tasks/TaskCompletionEventArgs.cs new file mode 100644 index 000000000..be9eaa613 --- /dev/null +++ b/MediaBrowser.Model/Tasks/TaskCompletionEventArgs.cs @@ -0,0 +1,11 @@ +using System; + +namespace MediaBrowser.Model.Tasks +{ + public class TaskCompletionEventArgs : EventArgs + { + public IScheduledTaskWorker Task { get; set; } + + public TaskResult Result { get; set; } + } +} |
