diff options
Diffstat (limited to 'MediaBrowser.Common/ScheduledTasks')
14 files changed, 0 insertions, 956 deletions
diff --git a/MediaBrowser.Common/ScheduledTasks/DailyTrigger.cs b/MediaBrowser.Common/ScheduledTasks/DailyTrigger.cs deleted file mode 100644 index 3d33e958d..000000000 --- a/MediaBrowser.Common/ScheduledTasks/DailyTrigger.cs +++ /dev/null @@ -1,91 +0,0 @@ -using MediaBrowser.Model.Events; -using MediaBrowser.Model.Tasks; -using System; -using System.Globalization; -using System.Threading; -using MediaBrowser.Model.Logging; - -namespace MediaBrowser.Common.ScheduledTasks -{ - /// <summary> - /// Represents a task trigger that fires everyday - /// </summary> - public class DailyTrigger : ITaskTrigger - { - /// <summary> - /// Get the time of day to trigger the task to run - /// </summary> - /// <value>The time of day.</value> - public TimeSpan TimeOfDay { get; set; } - - /// <summary> - /// Gets or sets the timer. - /// </summary> - /// <value>The timer.</value> - private Timer Timer { get; set; } - - /// <summary> - /// Gets the execution properties of this task. - /// </summary> - /// <value> - /// The execution properties of this task. - /// </value> - public TaskExecutionOptions TaskOptions { get; set; } - - /// <summary> - /// Stars waiting for the trigger action - /// </summary> - /// <param name="lastResult">The last result.</param> - /// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param> - public void Start(TaskResult lastResult, ILogger logger, string taskName, bool isApplicationStartup) - { - DisposeTimer(); - - var now = DateTime.Now; - - var triggerDate = now.TimeOfDay > TimeOfDay ? now.Date.AddDays(1) : now.Date; - triggerDate = triggerDate.Add(TimeOfDay); - - var dueTime = triggerDate - now; - - logger.Info("Daily trigger for {0} set to fire at {1}, which is {2} minutes from now.", taskName, triggerDate.ToString(), dueTime.TotalMinutes.ToString(CultureInfo.InvariantCulture)); - - Timer = new Timer(state => OnTriggered(), null, dueTime, TimeSpan.FromMilliseconds(-1)); - } - - /// <summary> - /// Stops waiting for the trigger action - /// </summary> - public void Stop() - { - DisposeTimer(); - } - - /// <summary> - /// Disposes the timer. - /// </summary> - private void DisposeTimer() - { - if (Timer != null) - { - Timer.Dispose(); - } - } - - /// <summary> - /// Occurs when [triggered]. - /// </summary> - public event EventHandler<GenericEventArgs<TaskExecutionOptions>> Triggered; - - /// <summary> - /// Called when [triggered]. - /// </summary> - private void OnTriggered() - { - if (Triggered != null) - { - Triggered(this, new GenericEventArgs<TaskExecutionOptions>(TaskOptions)); - } - } - } -} diff --git a/MediaBrowser.Common/ScheduledTasks/IConfigurableScheduledTask.cs b/MediaBrowser.Common/ScheduledTasks/IConfigurableScheduledTask.cs deleted file mode 100644 index 6989dea06..000000000 --- a/MediaBrowser.Common/ScheduledTasks/IConfigurableScheduledTask.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace MediaBrowser.Common.ScheduledTasks -{ - 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; } - } - - public interface IScheduledTaskActivityLog - { - bool IsActivityLogged { get; } - } -}
\ No newline at end of file diff --git a/MediaBrowser.Common/ScheduledTasks/IHasKey.cs b/MediaBrowser.Common/ScheduledTasks/IHasKey.cs deleted file mode 100644 index 5736cb616..000000000 --- a/MediaBrowser.Common/ScheduledTasks/IHasKey.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace MediaBrowser.Common.ScheduledTasks -{ - public interface IHasKey - { - string Key { get; } - } -}
\ No newline at end of file diff --git a/MediaBrowser.Common/ScheduledTasks/IScheduledTask.cs b/MediaBrowser.Common/ScheduledTasks/IScheduledTask.cs deleted file mode 100644 index 351e96c7d..000000000 --- a/MediaBrowser.Common/ScheduledTasks/IScheduledTask.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.ScheduledTasks -{ - /// <summary> - /// Interface IScheduledTaskWorker - /// </summary> - public interface IScheduledTask - { - /// <summary> - /// Gets the name of the task - /// </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> - /// 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<ITaskTrigger> GetDefaultTriggers(); - } -} diff --git a/MediaBrowser.Common/ScheduledTasks/IScheduledTaskWorker.cs b/MediaBrowser.Common/ScheduledTasks/IScheduledTaskWorker.cs deleted file mode 100644 index 0b9a5e276..000000000 --- a/MediaBrowser.Common/ScheduledTasks/IScheduledTaskWorker.cs +++ /dev/null @@ -1,78 +0,0 @@ -using MediaBrowser.Model.Events; -using MediaBrowser.Model.Tasks; -using System; -using System.Collections.Generic; - -namespace MediaBrowser.Common.ScheduledTasks -{ - /// <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="System.ArgumentNullException">value</exception> - IEnumerable<ITaskTrigger> 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.Common/ScheduledTasks/ITaskManager.cs b/MediaBrowser.Common/ScheduledTasks/ITaskManager.cs deleted file mode 100644 index f1809c451..000000000 --- a/MediaBrowser.Common/ScheduledTasks/ITaskManager.cs +++ /dev/null @@ -1,80 +0,0 @@ -using MediaBrowser.Model.Events; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.ScheduledTasks -{ - 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.Common/ScheduledTasks/ITaskTrigger.cs b/MediaBrowser.Common/ScheduledTasks/ITaskTrigger.cs deleted file mode 100644 index ef1ea9d38..000000000 --- a/MediaBrowser.Common/ScheduledTasks/ITaskTrigger.cs +++ /dev/null @@ -1,38 +0,0 @@ -using MediaBrowser.Model.Events; -using MediaBrowser.Model.Tasks; -using System; -using MediaBrowser.Model.Logging; - -namespace MediaBrowser.Common.ScheduledTasks -{ - /// <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> - /// <param name="lastResult">The last result.</param> - /// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param> - 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.Common/ScheduledTasks/IntervalTrigger.cs b/MediaBrowser.Common/ScheduledTasks/IntervalTrigger.cs deleted file mode 100644 index 8038d5551..000000000 --- a/MediaBrowser.Common/ScheduledTasks/IntervalTrigger.cs +++ /dev/null @@ -1,112 +0,0 @@ -using MediaBrowser.Model.Events; -using MediaBrowser.Model.Tasks; -using System; -using System.Linq; -using System.Threading; -using MediaBrowser.Model.Logging; - -namespace MediaBrowser.Common.ScheduledTasks -{ - /// <summary> - /// Represents a task trigger that runs repeatedly on an interval - /// </summary> - public class IntervalTrigger : ITaskTrigger - { - /// <summary> - /// Gets or sets the interval. - /// </summary> - /// <value>The interval.</value> - public TimeSpan Interval { get; set; } - - /// <summary> - /// Gets or sets the timer. - /// </summary> - /// <value>The timer.</value> - private Timer Timer { get; set; } - - /// <summary> - /// Gets the execution properties of this task. - /// </summary> - /// <value> - /// The execution properties of this task. - /// </value> - public TaskExecutionOptions TaskOptions { get; set; } - - private DateTime _lastStartDate; - - /// <summary> - /// Stars waiting for the trigger action - /// </summary> - /// <param name="lastResult">The last result.</param> - /// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param> - public void Start(TaskResult lastResult, ILogger logger, string taskName, bool isApplicationStartup) - { - DisposeTimer(); - - DateTime triggerDate; - - if (lastResult == null) - { - // Task has never been completed before - triggerDate = DateTime.UtcNow.AddHours(1); - } - else - { - triggerDate = new[] { lastResult.EndTimeUtc, _lastStartDate }.Max().Add(Interval); - } - - if (DateTime.UtcNow > triggerDate) - { - triggerDate = DateTime.UtcNow.AddMinutes(1); - } - - var dueTime = triggerDate - DateTime.UtcNow; - var maxDueTime = TimeSpan.FromDays(7); - - if (dueTime > maxDueTime) - { - dueTime = maxDueTime; - } - - Timer = new Timer(state => OnTriggered(), null, dueTime, TimeSpan.FromMilliseconds(-1)); - } - - /// <summary> - /// Stops waiting for the trigger action - /// </summary> - public void Stop() - { - DisposeTimer(); - } - - /// <summary> - /// Disposes the timer. - /// </summary> - private void DisposeTimer() - { - if (Timer != null) - { - Timer.Dispose(); - } - } - - /// <summary> - /// Occurs when [triggered]. - /// </summary> - public event EventHandler<GenericEventArgs<TaskExecutionOptions>> Triggered; - - /// <summary> - /// Called when [triggered]. - /// </summary> - private void OnTriggered() - { - DisposeTimer(); - - if (Triggered != null) - { - _lastStartDate = DateTime.UtcNow; - Triggered(this, new GenericEventArgs<TaskExecutionOptions>(TaskOptions)); - } - } - } -} diff --git a/MediaBrowser.Common/ScheduledTasks/ScheduledTaskHelpers.cs b/MediaBrowser.Common/ScheduledTasks/ScheduledTaskHelpers.cs deleted file mode 100644 index 4ad33341a..000000000 --- a/MediaBrowser.Common/ScheduledTasks/ScheduledTaskHelpers.cs +++ /dev/null @@ -1,194 +0,0 @@ -using MediaBrowser.Model.Tasks; -using System; -using System.Linq; - -namespace MediaBrowser.Common.ScheduledTasks -{ - /// <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 = null; - - var hasKey = task.ScheduledTask as IHasKey; - - if (hasKey != null) - { - key = hasKey.Key; - } - - var triggers = task.Triggers - .Select(GetTriggerInfo) - .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 - }; - } - - /// <summary> - /// Gets the trigger info. - /// </summary> - /// <param name="trigger">The trigger.</param> - /// <returns>TaskTriggerInfo.</returns> - public static TaskTriggerInfo GetTriggerInfo(ITaskTrigger trigger) - { - var info = new TaskTriggerInfo - { - Type = trigger.GetType().Name - }; - - var dailyTrigger = trigger as DailyTrigger; - - if (dailyTrigger != null) - { - info.TimeOfDayTicks = dailyTrigger.TimeOfDay.Ticks; - } - - var weeklyTaskTrigger = trigger as WeeklyTrigger; - - if (weeklyTaskTrigger != null) - { - info.TimeOfDayTicks = weeklyTaskTrigger.TimeOfDay.Ticks; - info.DayOfWeek = weeklyTaskTrigger.DayOfWeek; - } - - var intervalTaskTrigger = trigger as IntervalTrigger; - - if (intervalTaskTrigger != null) - { - info.IntervalTicks = intervalTaskTrigger.Interval.Ticks; - } - - var systemEventTrigger = trigger as SystemEventTrigger; - - if (systemEventTrigger != null) - { - info.SystemEvent = systemEventTrigger.SystemEvent; - } - - if (trigger.TaskOptions != null) - { - info.MaxRuntimeMs = trigger.TaskOptions.MaxRuntimeMs; - } - - return info; - } - - /// <summary> - /// Converts a TaskTriggerInfo into a concrete BaseTaskTrigger - /// </summary> - /// <param name="info">The info.</param> - /// <returns>BaseTaskTrigger.</returns> - /// <exception cref="System.ArgumentNullException"></exception> - /// <exception cref="System.ArgumentException">Invalid trigger type: + info.Type</exception> - public static ITaskTrigger GetTrigger(TaskTriggerInfo info) - { - var options = new TaskExecutionOptions - { - MaxRuntimeMs = info.MaxRuntimeMs - }; - - if (info.Type.Equals(typeof(DailyTrigger).Name, StringComparison.OrdinalIgnoreCase)) - { - if (!info.TimeOfDayTicks.HasValue) - { - throw new ArgumentNullException(); - } - - return new DailyTrigger - { - TimeOfDay = TimeSpan.FromTicks(info.TimeOfDayTicks.Value), - TaskOptions = options - }; - } - - if (info.Type.Equals(typeof(WeeklyTrigger).Name, StringComparison.OrdinalIgnoreCase)) - { - if (!info.TimeOfDayTicks.HasValue) - { - throw new ArgumentNullException(); - } - - if (!info.DayOfWeek.HasValue) - { - throw new ArgumentNullException(); - } - - return new WeeklyTrigger - { - TimeOfDay = TimeSpan.FromTicks(info.TimeOfDayTicks.Value), - DayOfWeek = info.DayOfWeek.Value, - TaskOptions = options - }; - } - - if (info.Type.Equals(typeof(IntervalTrigger).Name, StringComparison.OrdinalIgnoreCase)) - { - if (!info.IntervalTicks.HasValue) - { - throw new ArgumentNullException(); - } - - return new IntervalTrigger - { - Interval = TimeSpan.FromTicks(info.IntervalTicks.Value), - TaskOptions = options - }; - } - - if (info.Type.Equals(typeof(SystemEventTrigger).Name, StringComparison.OrdinalIgnoreCase)) - { - if (!info.SystemEvent.HasValue) - { - throw new ArgumentNullException(); - } - - return new SystemEventTrigger - { - SystemEvent = info.SystemEvent.Value, - TaskOptions = options - }; - } - - if (info.Type.Equals(typeof(StartupTrigger).Name, StringComparison.OrdinalIgnoreCase)) - { - return new StartupTrigger(); - } - - throw new ArgumentException("Unrecognized trigger type: " + info.Type); - } - } -} diff --git a/MediaBrowser.Common/ScheduledTasks/StartupTrigger.cs b/MediaBrowser.Common/ScheduledTasks/StartupTrigger.cs deleted file mode 100644 index 41f58a7ad..000000000 --- a/MediaBrowser.Common/ScheduledTasks/StartupTrigger.cs +++ /dev/null @@ -1,67 +0,0 @@ -using MediaBrowser.Model.Events; -using MediaBrowser.Model.Tasks; -using System; -using System.Threading.Tasks; -using MediaBrowser.Model.Logging; - -namespace MediaBrowser.Common.ScheduledTasks -{ - /// <summary> - /// Class StartupTaskTrigger - /// </summary> - public class StartupTrigger : ITaskTrigger - { - public int DelayMs { get; set; } - - /// <summary> - /// Gets the execution properties of this task. - /// </summary> - /// <value> - /// The execution properties of this task. - /// </value> - public TaskExecutionOptions TaskOptions { get; set; } - - public StartupTrigger() - { - DelayMs = 3000; - } - - /// <summary> - /// Stars waiting for the trigger action - /// </summary> - /// <param name="lastResult">The last result.</param> - /// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param> - public async void Start(TaskResult lastResult, ILogger logger, string taskName, bool isApplicationStartup) - { - if (isApplicationStartup) - { - await Task.Delay(DelayMs).ConfigureAwait(false); - - OnTriggered(); - } - } - - /// <summary> - /// Stops waiting for the trigger action - /// </summary> - public void Stop() - { - } - - /// <summary> - /// Occurs when [triggered]. - /// </summary> - public event EventHandler<GenericEventArgs<TaskExecutionOptions>> Triggered; - - /// <summary> - /// Called when [triggered]. - /// </summary> - private void OnTriggered() - { - if (Triggered != null) - { - Triggered(this, new GenericEventArgs<TaskExecutionOptions>(TaskOptions)); - } - } - } -} diff --git a/MediaBrowser.Common/ScheduledTasks/SystemEventTrigger.cs b/MediaBrowser.Common/ScheduledTasks/SystemEventTrigger.cs deleted file mode 100644 index 9972dc804..000000000 --- a/MediaBrowser.Common/ScheduledTasks/SystemEventTrigger.cs +++ /dev/null @@ -1,84 +0,0 @@ -using MediaBrowser.Model.Events; -using MediaBrowser.Model.Tasks; -using Microsoft.Win32; -using System; -using System.Threading.Tasks; -using MediaBrowser.Model.Logging; - -namespace MediaBrowser.Common.ScheduledTasks -{ - /// <summary> - /// Class SystemEventTrigger - /// </summary> - public class SystemEventTrigger : ITaskTrigger - { - /// <summary> - /// Gets or sets the system event. - /// </summary> - /// <value>The system event.</value> - public SystemEvent SystemEvent { get; set; } - - /// <summary> - /// Gets the execution properties of this task. - /// </summary> - /// <value> - /// The execution properties of this task. - /// </value> - public TaskExecutionOptions TaskOptions { get; set; } - - /// <summary> - /// Stars waiting for the trigger action - /// </summary> - /// <param name="lastResult">The last result.</param> - /// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param> - public void Start(TaskResult lastResult, ILogger logger, string taskName, bool isApplicationStartup) - { - switch (SystemEvent) - { - case SystemEvent.WakeFromSleep: - SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; - break; - } - } - - /// <summary> - /// Stops waiting for the trigger action - /// </summary> - public void Stop() - { - SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged; - } - - /// <summary> - /// Handles the PowerModeChanged event of the SystemEvents control. - /// </summary> - /// <param name="sender">The source of the event.</param> - /// <param name="e">The <see cref="PowerModeChangedEventArgs" /> instance containing the event data.</param> - async void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e) - { - if (e.Mode == PowerModes.Resume && SystemEvent == SystemEvent.WakeFromSleep) - { - // This value is a bit arbitrary, but add a delay to help ensure network connections have been restored before running the task - await Task.Delay(10000).ConfigureAwait(false); - - OnTriggered(); - } - } - - /// <summary> - /// Occurs when [triggered]. - /// </summary> - public event EventHandler<GenericEventArgs<TaskExecutionOptions>> Triggered; - - /// <summary> - /// Called when [triggered]. - /// </summary> - private void OnTriggered() - { - if (Triggered != null) - { - Triggered(this, new GenericEventArgs<TaskExecutionOptions>(TaskOptions)); - } - } - } -} diff --git a/MediaBrowser.Common/ScheduledTasks/TaskCompletionEventArgs.cs b/MediaBrowser.Common/ScheduledTasks/TaskCompletionEventArgs.cs deleted file mode 100644 index 2974806d0..000000000 --- a/MediaBrowser.Common/ScheduledTasks/TaskCompletionEventArgs.cs +++ /dev/null @@ -1,12 +0,0 @@ -using MediaBrowser.Model.Tasks; -using System; - -namespace MediaBrowser.Common.ScheduledTasks -{ - public class TaskCompletionEventArgs : EventArgs - { - public IScheduledTaskWorker Task { get; set; } - - public TaskResult Result { get; set; } - } -} diff --git a/MediaBrowser.Common/ScheduledTasks/TaskExecutionOptions.cs b/MediaBrowser.Common/ScheduledTasks/TaskExecutionOptions.cs deleted file mode 100644 index 41b33b1c2..000000000 --- a/MediaBrowser.Common/ScheduledTasks/TaskExecutionOptions.cs +++ /dev/null @@ -1,11 +0,0 @@ - -namespace MediaBrowser.Common.ScheduledTasks -{ - /// <summary> - /// A class that encomposases all common task run properties. - /// </summary> - public class TaskExecutionOptions - { - public int? MaxRuntimeMs { get; set; } - } -} diff --git a/MediaBrowser.Common/ScheduledTasks/WeeklyTrigger.cs b/MediaBrowser.Common/ScheduledTasks/WeeklyTrigger.cs deleted file mode 100644 index 318802e07..000000000 --- a/MediaBrowser.Common/ScheduledTasks/WeeklyTrigger.cs +++ /dev/null @@ -1,116 +0,0 @@ -using System; -using System.Threading; -using MediaBrowser.Model.Events; -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Tasks; - -namespace MediaBrowser.Common.ScheduledTasks -{ - /// <summary> - /// Represents a task trigger that fires on a weekly basis - /// </summary> - public class WeeklyTrigger : ITaskTrigger - { - /// <summary> - /// Get the time of day to trigger the task to run - /// </summary> - /// <value>The time of day.</value> - public TimeSpan TimeOfDay { get; set; } - - /// <summary> - /// Gets or sets the day of week. - /// </summary> - /// <value>The day of week.</value> - public DayOfWeek DayOfWeek { get; set; } - - /// <summary> - /// Gets the execution properties of this task. - /// </summary> - /// <value> - /// The execution properties of this task. - /// </value> - public TaskExecutionOptions TaskOptions { get; set; } - - /// <summary> - /// Gets or sets the timer. - /// </summary> - /// <value>The timer.</value> - private Timer Timer { get; set; } - - /// <summary> - /// Stars waiting for the trigger action - /// </summary> - /// <param name="lastResult">The last result.</param> - /// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param> - public void Start(TaskResult lastResult, ILogger logger, string taskName, bool isApplicationStartup) - { - DisposeTimer(); - - var triggerDate = GetNextTriggerDateTime(); - - Timer = new Timer(state => OnTriggered(), null, triggerDate - DateTime.Now, TimeSpan.FromMilliseconds(-1)); - } - - /// <summary> - /// Gets the next trigger date time. - /// </summary> - /// <returns>DateTime.</returns> - private DateTime GetNextTriggerDateTime() - { - var now = DateTime.Now; - - // If it's on the same day - if (now.DayOfWeek == DayOfWeek) - { - // It's either later today, or a week from now - return now.TimeOfDay < TimeOfDay ? now.Date.Add(TimeOfDay) : now.Date.AddDays(7).Add(TimeOfDay); - } - - var triggerDate = now.Date; - - // Walk the date forward until we get to the trigger day - while (triggerDate.DayOfWeek != DayOfWeek) - { - triggerDate = triggerDate.AddDays(1); - } - - // Return the trigger date plus the time offset - return triggerDate.Add(TimeOfDay); - } - - /// <summary> - /// Stops waiting for the trigger action - /// </summary> - public void Stop() - { - DisposeTimer(); - } - - /// <summary> - /// Disposes the timer. - /// </summary> - private void DisposeTimer() - { - if (Timer != null) - { - Timer.Dispose(); - } - } - - /// <summary> - /// Occurs when [triggered]. - /// </summary> - public event EventHandler<GenericEventArgs<TaskExecutionOptions>> Triggered; - - /// <summary> - /// Called when [triggered]. - /// </summary> - private void OnTriggered() - { - if (Triggered != null) - { - Triggered(this, new GenericEventArgs<TaskExecutionOptions>(TaskOptions)); - } - } - } -} |
