From a86b71899ec52c44ddc6c3018e8cc5e9d7ff4d62 Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Thu, 27 Dec 2018 18:27:57 -0500 Subject: Add GPL modules --- .../Tasks/IConfigurableScheduledTask.cs | 18 +++++ MediaBrowser.Model/Tasks/IScheduledTask.cs | 47 +++++++++++++ MediaBrowser.Model/Tasks/IScheduledTaskWorker.cs | 76 +++++++++++++++++++++ MediaBrowser.Model/Tasks/ITaskManager.cs | 78 ++++++++++++++++++++++ MediaBrowser.Model/Tasks/ITaskTrigger.cs | 32 +++++++++ MediaBrowser.Model/Tasks/ScheduledTaskHelpers.cs | 44 ++++++++++++ MediaBrowser.Model/Tasks/SystemEvent.cs | 14 ++++ .../Tasks/TaskCompletionEventArgs.cs | 11 +++ MediaBrowser.Model/Tasks/TaskCompletionStatus.cs | 29 ++++++++ MediaBrowser.Model/Tasks/TaskInfo.cs | 78 ++++++++++++++++++++++ MediaBrowser.Model/Tasks/TaskOptions.cs | 8 +++ MediaBrowser.Model/Tasks/TaskResult.cs | 58 ++++++++++++++++ MediaBrowser.Model/Tasks/TaskState.cs | 22 ++++++ MediaBrowser.Model/Tasks/TaskTriggerInfo.cs | 52 +++++++++++++++ 14 files changed, 567 insertions(+) create mode 100644 MediaBrowser.Model/Tasks/IConfigurableScheduledTask.cs create mode 100644 MediaBrowser.Model/Tasks/IScheduledTask.cs create mode 100644 MediaBrowser.Model/Tasks/IScheduledTaskWorker.cs create mode 100644 MediaBrowser.Model/Tasks/ITaskManager.cs create mode 100644 MediaBrowser.Model/Tasks/ITaskTrigger.cs create mode 100644 MediaBrowser.Model/Tasks/ScheduledTaskHelpers.cs create mode 100644 MediaBrowser.Model/Tasks/SystemEvent.cs create mode 100644 MediaBrowser.Model/Tasks/TaskCompletionEventArgs.cs create mode 100644 MediaBrowser.Model/Tasks/TaskCompletionStatus.cs create mode 100644 MediaBrowser.Model/Tasks/TaskInfo.cs create mode 100644 MediaBrowser.Model/Tasks/TaskOptions.cs create mode 100644 MediaBrowser.Model/Tasks/TaskResult.cs create mode 100644 MediaBrowser.Model/Tasks/TaskState.cs create mode 100644 MediaBrowser.Model/Tasks/TaskTriggerInfo.cs (limited to 'MediaBrowser.Model/Tasks') diff --git a/MediaBrowser.Model/Tasks/IConfigurableScheduledTask.cs b/MediaBrowser.Model/Tasks/IConfigurableScheduledTask.cs new file mode 100644 index 0000000000..ed981a905b --- /dev/null +++ b/MediaBrowser.Model/Tasks/IConfigurableScheduledTask.cs @@ -0,0 +1,18 @@ +namespace MediaBrowser.Model.Tasks +{ + public interface IConfigurableScheduledTask + { + /// + /// Gets a value indicating whether this instance is hidden. + /// + /// true if this instance is hidden; otherwise, false. + bool IsHidden { get; } + /// + /// Gets a value indicating whether this instance is enabled. + /// + /// true if this instance is enabled; otherwise, false. + 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 0000000000..81ba239ad8 --- /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 +{ + /// + /// Interface IScheduledTaskWorker + /// + public interface IScheduledTask + { + /// + /// Gets the name of the task + /// + /// The name. + string Name { get; } + + string Key { get; } + + /// + /// Gets the description. + /// + /// The description. + string Description { get; } + + /// + /// Gets the category. + /// + /// The category. + string Category { get; } + + /// + /// Executes the task + /// + /// The cancellation token. + /// The progress. + /// Task. + Task Execute(CancellationToken cancellationToken, IProgress progress); + + /// + /// Gets the default triggers. + /// + /// IEnumerable{BaseTaskTrigger}. + IEnumerable GetDefaultTriggers(); + } +} diff --git a/MediaBrowser.Model/Tasks/IScheduledTaskWorker.cs b/MediaBrowser.Model/Tasks/IScheduledTaskWorker.cs new file mode 100644 index 0000000000..415207f8f0 --- /dev/null +++ b/MediaBrowser.Model/Tasks/IScheduledTaskWorker.cs @@ -0,0 +1,76 @@ +using System; +using MediaBrowser.Model.Events; + +namespace MediaBrowser.Model.Tasks +{ + /// + /// Interface IScheduledTaskWorker + /// + public interface IScheduledTaskWorker : IDisposable + { + /// + /// Occurs when [task progress]. + /// + event EventHandler> TaskProgress; + + /// + /// Gets or sets the scheduled task. + /// + /// The scheduled task. + IScheduledTask ScheduledTask { get; } + + /// + /// Gets the last execution result. + /// + /// The last execution result. + TaskResult LastExecutionResult { get; } + + /// + /// Gets the name. + /// + /// The name. + string Name { get; } + + /// + /// Gets the description. + /// + /// The description. + string Description { get; } + + /// + /// Gets the category. + /// + /// The category. + string Category { get; } + + /// + /// Gets the state. + /// + /// The state. + TaskState State { get; } + + /// + /// Gets the current progress. + /// + /// The current progress. + double? CurrentProgress { get; } + + /// + /// Gets the triggers that define when the task will run + /// + /// The triggers. + /// value + TaskTriggerInfo[] Triggers { get; set; } + + /// + /// Gets the unique id. + /// + /// The unique id. + string Id { get; } + + /// + /// Reloads the trigger events. + /// + 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 0000000000..cbc18032c1 --- /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 + { + /// + /// Gets the list of Scheduled Tasks + /// + /// The scheduled tasks. + IScheduledTaskWorker[] ScheduledTasks { get; } + + /// + /// Cancels if running and queue. + /// + /// + /// Task options. + void CancelIfRunningAndQueue(TaskOptions options) + where T : IScheduledTask; + + /// + /// Cancels if running and queue. + /// + /// + void CancelIfRunningAndQueue() + where T : IScheduledTask; + + /// + /// Cancels if running. + /// + /// + void CancelIfRunning() + where T : IScheduledTask; + + /// + /// Queues the scheduled task. + /// + /// + /// Task options. + void QueueScheduledTask(TaskOptions options) + where T : IScheduledTask; + + /// + /// Queues the scheduled task. + /// + /// + void QueueScheduledTask() + where T : IScheduledTask; + + void QueueIfNotRunning() + where T : IScheduledTask; + + /// + /// Queues the scheduled task. + /// + void QueueScheduledTask(IScheduledTask task, TaskOptions options); + + /// + /// Adds the tasks. + /// + /// The tasks. + void AddTasks(IEnumerable tasks); + + void Cancel(IScheduledTaskWorker task); + Task Execute(IScheduledTaskWorker task, TaskOptions options); + + void Execute() + where T : IScheduledTask; + + event EventHandler> TaskExecuting; + event EventHandler 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 0000000000..7c804348a8 --- /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 +{ + /// + /// Interface ITaskTrigger + /// + public interface ITaskTrigger + { + /// + /// Fires when the trigger condition is satisfied and the task should run + /// + event EventHandler Triggered; + + /// + /// Gets or sets the options of this task. + /// + TaskOptions TaskOptions { get; set; } + + /// + /// Stars waiting for the trigger action + /// + void Start(TaskResult lastResult, ILogger logger, string taskName, bool isApplicationStartup); + + /// + /// Stops waiting for the trigger action + /// + 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 0000000000..2dec79e93b --- /dev/null +++ b/MediaBrowser.Model/Tasks/ScheduledTaskHelpers.cs @@ -0,0 +1,44 @@ + +namespace MediaBrowser.Model.Tasks +{ + /// + /// Class ScheduledTaskHelpers + /// + public static class ScheduledTaskHelpers + { + /// + /// Gets the task info. + /// + /// The task. + /// TaskInfo. + 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 0000000000..4d49a38ccb --- /dev/null +++ b/MediaBrowser.Model/Tasks/SystemEvent.cs @@ -0,0 +1,14 @@ + +namespace MediaBrowser.Model.Tasks +{ + /// + /// Enum SystemEvent + /// + public enum SystemEvent + { + /// + /// The wake from sleep + /// + WakeFromSleep = 0 + } +} diff --git a/MediaBrowser.Model/Tasks/TaskCompletionEventArgs.cs b/MediaBrowser.Model/Tasks/TaskCompletionEventArgs.cs new file mode 100644 index 0000000000..be9eaa613d --- /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 0000000000..6ba5ba5e4f --- /dev/null +++ b/MediaBrowser.Model/Tasks/TaskCompletionStatus.cs @@ -0,0 +1,29 @@ + +namespace MediaBrowser.Model.Tasks +{ + /// + /// Enum TaskCompletionStatus + /// + public enum TaskCompletionStatus + { + /// + /// The completed + /// + Completed, + + /// + /// The failed + /// + Failed, + + /// + /// Manually cancelled by the user + /// + Cancelled, + + /// + /// Aborted due to a system failure or shutdown + /// + Aborted + } +} diff --git a/MediaBrowser.Model/Tasks/TaskInfo.cs b/MediaBrowser.Model/Tasks/TaskInfo.cs new file mode 100644 index 0000000000..8792ce952a --- /dev/null +++ b/MediaBrowser.Model/Tasks/TaskInfo.cs @@ -0,0 +1,78 @@ +using System.Collections.Generic; + +namespace MediaBrowser.Model.Tasks +{ + /// + /// Class TaskInfo + /// + public class TaskInfo + { + /// + /// Gets or sets the name. + /// + /// The name. + public string Name { get; set; } + + /// + /// Gets or sets the state of the task. + /// + /// The state of the task. + public TaskState State { get; set; } + + /// + /// Gets or sets the progress. + /// + /// The progress. + public double? CurrentProgressPercentage { get; set; } + + /// + /// Gets or sets the id. + /// + /// The id. + public string Id { get; set; } + + /// + /// Gets or sets the last execution result. + /// + /// The last execution result. + public TaskResult LastExecutionResult { get; set; } + + /// + /// Gets or sets the triggers. + /// + /// The triggers. + public TaskTriggerInfo[] Triggers { get; set; } + + /// + /// Gets or sets the description. + /// + /// The description. + public string Description { get; set; } + + /// + /// Gets or sets the category. + /// + /// The category. + public string Category { get; set; } + + /// + /// Gets or sets a value indicating whether this instance is hidden. + /// + /// true if this instance is hidden; otherwise, false. + public bool IsHidden { get; set; } + + /// + /// Gets or sets the key. + /// + /// The key. + public string Key { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public TaskInfo() + { + Triggers = new TaskTriggerInfo[]{}; + } + } +} diff --git a/MediaBrowser.Model/Tasks/TaskOptions.cs b/MediaBrowser.Model/Tasks/TaskOptions.cs new file mode 100644 index 0000000000..caca154a9f --- /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 0000000000..39eacdf664 --- /dev/null +++ b/MediaBrowser.Model/Tasks/TaskResult.cs @@ -0,0 +1,58 @@ +using System; + +namespace MediaBrowser.Model.Tasks +{ + /// + /// Class TaskExecutionInfo + /// + public class TaskResult + { + /// + /// Gets or sets the start time UTC. + /// + /// The start time UTC. + public DateTime StartTimeUtc { get; set; } + + /// + /// Gets or sets the end time UTC. + /// + /// The end time UTC. + public DateTime EndTimeUtc { get; set; } + + /// + /// Gets or sets the status. + /// + /// The status. + public TaskCompletionStatus Status { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + public string Name { get; set; } + + /// + /// Gets or sets the key. + /// + /// The key. + public string Key { get; set; } + + /// + /// Gets or sets the id. + /// + /// The id. + public string Id { get; set; } + + /// + /// Gets or sets the error message. + /// + /// The error message. + public string ErrorMessage { get; set; } + + /// + /// Gets or sets the long error message. + /// + /// The long error message. + public string LongErrorMessage { get; set; } + } +} diff --git a/MediaBrowser.Model/Tasks/TaskState.cs b/MediaBrowser.Model/Tasks/TaskState.cs new file mode 100644 index 0000000000..889ce6875a --- /dev/null +++ b/MediaBrowser.Model/Tasks/TaskState.cs @@ -0,0 +1,22 @@ + +namespace MediaBrowser.Model.Tasks +{ + /// + /// Enum TaskState + /// + public enum TaskState + { + /// + /// The idle + /// + Idle, + /// + /// The cancelling + /// + Cancelling, + /// + /// The running + /// + Running + } +} diff --git a/MediaBrowser.Model/Tasks/TaskTriggerInfo.cs b/MediaBrowser.Model/Tasks/TaskTriggerInfo.cs new file mode 100644 index 0000000000..901a300d0f --- /dev/null +++ b/MediaBrowser.Model/Tasks/TaskTriggerInfo.cs @@ -0,0 +1,52 @@ +using System; + +namespace MediaBrowser.Model.Tasks +{ + /// + /// Class TaskTriggerInfo + /// + public class TaskTriggerInfo + { + /// + /// Gets or sets the type. + /// + /// The type. + public string Type { get; set; } + + /// + /// Gets or sets the time of day. + /// + /// The time of day. + public long? TimeOfDayTicks { get; set; } + + /// + /// Gets or sets the interval. + /// + /// The interval. + public long? IntervalTicks { get; set; } + + /// + /// Gets or sets the system event. + /// + /// The system event. + public SystemEvent? SystemEvent { get; set; } + + /// + /// Gets or sets the day of week. + /// + /// The day of week. + public DayOfWeek? DayOfWeek { get; set; } + + /// + /// Gets or sets the maximum runtime ticks. + /// + /// The maximum runtime ticks. + 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"; + } +} -- cgit v1.2.3