diff options
Diffstat (limited to 'MediaBrowser.Model/Tasks')
| -rw-r--r-- | MediaBrowser.Model/Tasks/IConfigurableScheduledTask.cs | 18 | ||||
| -rw-r--r-- | MediaBrowser.Model/Tasks/IScheduledTask.cs | 47 | ||||
| -rw-r--r-- | MediaBrowser.Model/Tasks/IScheduledTaskWorker.cs | 76 | ||||
| -rw-r--r-- | MediaBrowser.Model/Tasks/ITaskManager.cs | 78 | ||||
| -rw-r--r-- | MediaBrowser.Model/Tasks/ITaskTrigger.cs | 32 | ||||
| -rw-r--r-- | MediaBrowser.Model/Tasks/ScheduledTaskHelpers.cs | 44 | ||||
| -rw-r--r-- | MediaBrowser.Model/Tasks/SystemEvent.cs | 14 | ||||
| -rw-r--r-- | MediaBrowser.Model/Tasks/TaskCompletionEventArgs.cs | 11 | ||||
| -rw-r--r-- | MediaBrowser.Model/Tasks/TaskCompletionStatus.cs | 29 | ||||
| -rw-r--r-- | MediaBrowser.Model/Tasks/TaskInfo.cs | 78 | ||||
| -rw-r--r-- | MediaBrowser.Model/Tasks/TaskOptions.cs | 8 | ||||
| -rw-r--r-- | MediaBrowser.Model/Tasks/TaskResult.cs | 58 | ||||
| -rw-r--r-- | MediaBrowser.Model/Tasks/TaskState.cs | 22 | ||||
| -rw-r--r-- | MediaBrowser.Model/Tasks/TaskTriggerInfo.cs | 52 |
14 files changed, 567 insertions, 0 deletions
diff --git a/MediaBrowser.Model/Tasks/IConfigurableScheduledTask.cs b/MediaBrowser.Model/Tasks/IConfigurableScheduledTask.cs new file mode 100644 index 000000000..ed981a905 --- /dev/null +++ b/MediaBrowser.Model/Tasks/IConfigurableScheduledTask.cs @@ -0,0 +1,18 @@ +namespace MediaBrowser.Model.Tasks +{ + public interface IConfigurableScheduledTask + { + /// <summary> + /// Gets a value indicating whether this instance is hidden. + /// </summary> + /// <value><c>true</c> if this instance is hidden; otherwise, <c>false</c>.</value> + bool IsHidden { get; } + /// <summary> + /// Gets a value indicating whether this instance is enabled. + /// </summary> + /// <value><c>true</c> if this instance is enabled; otherwise, <c>false</c>.</value> + bool IsEnabled { get; } + + bool IsLogged { get; } + } +}
\ No newline at end of file diff --git a/MediaBrowser.Model/Tasks/IScheduledTask.cs b/MediaBrowser.Model/Tasks/IScheduledTask.cs new file mode 100644 index 000000000..81ba239ad --- /dev/null +++ b/MediaBrowser.Model/Tasks/IScheduledTask.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Model.Tasks +{ + /// <summary> + /// Interface IScheduledTaskWorker + /// </summary> + public interface IScheduledTask + { + /// <summary> + /// Gets the name of the task + /// </summary> + /// <value>The name.</value> + string Name { get; } + + string Key { 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> + /// Executes the task + /// </summary> + /// <param name="cancellationToken">The cancellation token.</param> + /// <param name="progress">The progress.</param> + /// <returns>Task.</returns> + Task Execute(CancellationToken cancellationToken, IProgress<double> progress); + + /// <summary> + /// Gets the default triggers. + /// </summary> + /// <returns>IEnumerable{BaseTaskTrigger}.</returns> + IEnumerable<TaskTriggerInfo> GetDefaultTriggers(); + } +} 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..cbc18032c --- /dev/null +++ b/MediaBrowser.Model/Tasks/ITaskManager.cs @@ -0,0 +1,78 @@ +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>(TaskOptions 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>(TaskOptions 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> + void QueueScheduledTask(IScheduledTask task, TaskOptions options); + + /// <summary> + /// Adds the tasks. + /// </summary> + /// <param name="tasks">The tasks.</param> + void AddTasks(IEnumerable<IScheduledTask> tasks); + + void Cancel(IScheduledTaskWorker task); + Task Execute(IScheduledTaskWorker task, TaskOptions options); + + void Execute<T>() + where T : IScheduledTask; + + event EventHandler<GenericEventArgs<IScheduledTaskWorker>> TaskExecuting; + event EventHandler<TaskCompletionEventArgs> TaskCompleted; + + void RunTaskOnNextStartup(string key); + } +}
\ 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..7c804348a --- /dev/null +++ b/MediaBrowser.Model/Tasks/ITaskTrigger.cs @@ -0,0 +1,32 @@ +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<EventArgs> Triggered; + + /// <summary> + /// Gets or sets the options of this task. + /// </summary> + TaskOptions TaskOptions { get; set; } + + /// <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(); + } +}
\ 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..2dec79e93 --- /dev/null +++ b/MediaBrowser.Model/Tasks/ScheduledTaskHelpers.cs @@ -0,0 +1,44 @@ + +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; + + return new TaskInfo + { + Name = task.Name, + CurrentProgressPercentage = task.CurrentProgress, + State = task.State, + Id = task.Id, + LastExecutionResult = task.LastExecutionResult, + + Triggers = task.Triggers, + + Description = task.Description, + Category = task.Category, + IsHidden = isHidden, + Key = key + }; + } + } +} diff --git a/MediaBrowser.Model/Tasks/SystemEvent.cs b/MediaBrowser.Model/Tasks/SystemEvent.cs new file mode 100644 index 000000000..4d49a38cc --- /dev/null +++ b/MediaBrowser.Model/Tasks/SystemEvent.cs @@ -0,0 +1,14 @@ + +namespace MediaBrowser.Model.Tasks +{ + /// <summary> + /// Enum SystemEvent + /// </summary> + public enum SystemEvent + { + /// <summary> + /// The wake from sleep + /// </summary> + WakeFromSleep = 0 + } +} 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; } + } +} diff --git a/MediaBrowser.Model/Tasks/TaskCompletionStatus.cs b/MediaBrowser.Model/Tasks/TaskCompletionStatus.cs new file mode 100644 index 000000000..6ba5ba5e4 --- /dev/null +++ b/MediaBrowser.Model/Tasks/TaskCompletionStatus.cs @@ -0,0 +1,29 @@ + +namespace MediaBrowser.Model.Tasks +{ + /// <summary> + /// Enum TaskCompletionStatus + /// </summary> + public enum TaskCompletionStatus + { + /// <summary> + /// The completed + /// </summary> + Completed, + + /// <summary> + /// The failed + /// </summary> + Failed, + + /// <summary> + /// Manually cancelled by the user + /// </summary> + Cancelled, + + /// <summary> + /// Aborted due to a system failure or shutdown + /// </summary> + Aborted + } +} diff --git a/MediaBrowser.Model/Tasks/TaskInfo.cs b/MediaBrowser.Model/Tasks/TaskInfo.cs new file mode 100644 index 000000000..8792ce952 --- /dev/null +++ b/MediaBrowser.Model/Tasks/TaskInfo.cs @@ -0,0 +1,78 @@ +using System.Collections.Generic; + +namespace MediaBrowser.Model.Tasks +{ + /// <summary> + /// Class TaskInfo + /// </summary> + public class TaskInfo + { + /// <summary> + /// Gets or sets the name. + /// </summary> + /// <value>The name.</value> + public string Name { get; set; } + + /// <summary> + /// Gets or sets the state of the task. + /// </summary> + /// <value>The state of the task.</value> + public TaskState State { get; set; } + + /// <summary> + /// Gets or sets the progress. + /// </summary> + /// <value>The progress.</value> + public double? CurrentProgressPercentage { get; set; } + + /// <summary> + /// Gets or sets the id. + /// </summary> + /// <value>The id.</value> + public string Id { get; set; } + + /// <summary> + /// Gets or sets the last execution result. + /// </summary> + /// <value>The last execution result.</value> + public TaskResult LastExecutionResult { get; set; } + + /// <summary> + /// Gets or sets the triggers. + /// </summary> + /// <value>The triggers.</value> + public TaskTriggerInfo[] Triggers { get; set; } + + /// <summary> + /// Gets or sets the description. + /// </summary> + /// <value>The description.</value> + public string Description { get; set; } + + /// <summary> + /// Gets or sets the category. + /// </summary> + /// <value>The category.</value> + public string Category { get; set; } + + /// <summary> + /// Gets or sets a value indicating whether this instance is hidden. + /// </summary> + /// <value><c>true</c> if this instance is hidden; otherwise, <c>false</c>.</value> + public bool IsHidden { get; set; } + + /// <summary> + /// Gets or sets the key. + /// </summary> + /// <value>The key.</value> + public string Key { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="TaskInfo"/> class. + /// </summary> + public TaskInfo() + { + Triggers = new TaskTriggerInfo[]{}; + } + } +} diff --git a/MediaBrowser.Model/Tasks/TaskOptions.cs b/MediaBrowser.Model/Tasks/TaskOptions.cs new file mode 100644 index 000000000..caca154a9 --- /dev/null +++ b/MediaBrowser.Model/Tasks/TaskOptions.cs @@ -0,0 +1,8 @@ + +namespace MediaBrowser.Model.Tasks +{ + public class TaskOptions + { + public long? MaxRuntimeTicks { get; set; } + } +} diff --git a/MediaBrowser.Model/Tasks/TaskResult.cs b/MediaBrowser.Model/Tasks/TaskResult.cs new file mode 100644 index 000000000..39eacdf66 --- /dev/null +++ b/MediaBrowser.Model/Tasks/TaskResult.cs @@ -0,0 +1,58 @@ +using System; + +namespace MediaBrowser.Model.Tasks +{ + /// <summary> + /// Class TaskExecutionInfo + /// </summary> + public class TaskResult + { + /// <summary> + /// Gets or sets the start time UTC. + /// </summary> + /// <value>The start time UTC.</value> + public DateTime StartTimeUtc { get; set; } + + /// <summary> + /// Gets or sets the end time UTC. + /// </summary> + /// <value>The end time UTC.</value> + public DateTime EndTimeUtc { get; set; } + + /// <summary> + /// Gets or sets the status. + /// </summary> + /// <value>The status.</value> + public TaskCompletionStatus Status { get; set; } + + /// <summary> + /// Gets or sets the name. + /// </summary> + /// <value>The name.</value> + public string Name { get; set; } + + /// <summary> + /// Gets or sets the key. + /// </summary> + /// <value>The key.</value> + public string Key { get; set; } + + /// <summary> + /// Gets or sets the id. + /// </summary> + /// <value>The id.</value> + public string Id { get; set; } + + /// <summary> + /// Gets or sets the error message. + /// </summary> + /// <value>The error message.</value> + public string ErrorMessage { get; set; } + + /// <summary> + /// Gets or sets the long error message. + /// </summary> + /// <value>The long error message.</value> + public string LongErrorMessage { get; set; } + } +} diff --git a/MediaBrowser.Model/Tasks/TaskState.cs b/MediaBrowser.Model/Tasks/TaskState.cs new file mode 100644 index 000000000..889ce6875 --- /dev/null +++ b/MediaBrowser.Model/Tasks/TaskState.cs @@ -0,0 +1,22 @@ + +namespace MediaBrowser.Model.Tasks +{ + /// <summary> + /// Enum TaskState + /// </summary> + public enum TaskState + { + /// <summary> + /// The idle + /// </summary> + Idle, + /// <summary> + /// The cancelling + /// </summary> + Cancelling, + /// <summary> + /// The running + /// </summary> + Running + } +} diff --git a/MediaBrowser.Model/Tasks/TaskTriggerInfo.cs b/MediaBrowser.Model/Tasks/TaskTriggerInfo.cs new file mode 100644 index 000000000..901a300d0 --- /dev/null +++ b/MediaBrowser.Model/Tasks/TaskTriggerInfo.cs @@ -0,0 +1,52 @@ +using System; + +namespace MediaBrowser.Model.Tasks +{ + /// <summary> + /// Class TaskTriggerInfo + /// </summary> + public class TaskTriggerInfo + { + /// <summary> + /// Gets or sets the type. + /// </summary> + /// <value>The type.</value> + public string Type { get; set; } + + /// <summary> + /// Gets or sets the time of day. + /// </summary> + /// <value>The time of day.</value> + public long? TimeOfDayTicks { get; set; } + + /// <summary> + /// Gets or sets the interval. + /// </summary> + /// <value>The interval.</value> + public long? IntervalTicks { get; set; } + + /// <summary> + /// Gets or sets the system event. + /// </summary> + /// <value>The system event.</value> + public SystemEvent? SystemEvent { get; set; } + + /// <summary> + /// Gets or sets the day of week. + /// </summary> + /// <value>The day of week.</value> + public DayOfWeek? DayOfWeek { get; set; } + + /// <summary> + /// Gets or sets the maximum runtime ticks. + /// </summary> + /// <value>The maximum runtime ticks.</value> + public long? MaxRuntimeTicks { get; set; } + + public const string TriggerDaily = "DailyTrigger"; + public const string TriggerWeekly = "WeeklyTrigger"; + public const string TriggerInterval = "IntervalTrigger"; + public const string TriggerSystemEvent = "SystemEventTrigger"; + public const string TriggerStartup = "StartupTrigger"; + } +} |
