jellyfin/MediaBrowser.Common/ScheduledTasks/StartupTrigger.cs

67 lines
1.8 KiB
C#
Raw Normal View History

2015-07-28 12:33:30 +00:00
using MediaBrowser.Model.Events;
using MediaBrowser.Model.Tasks;
using System;
2013-02-24 21:53:54 +00:00
using System.Threading.Tasks;
2013-02-21 01:33:05 +00:00
namespace MediaBrowser.Common.ScheduledTasks
{
/// <summary>
/// Class StartupTaskTrigger
/// </summary>
2013-02-24 21:53:54 +00:00
public class StartupTrigger : ITaskTrigger
2013-02-21 01:33:05 +00:00
{
2014-08-11 23:41:11 +00:00
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; }
2014-08-11 23:41:11 +00:00
public StartupTrigger()
{
DelayMs = 3000;
}
2013-02-21 01:33:05 +00:00
/// <summary>
/// Stars waiting for the trigger action
/// </summary>
2015-07-28 12:33:30 +00:00
/// <param name="lastResult">The last result.</param>
2013-02-23 07:57:11 +00:00
/// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param>
2015-07-28 12:33:30 +00:00
public async void Start(TaskResult lastResult, bool isApplicationStartup)
2013-02-21 01:33:05 +00:00
{
2013-02-23 07:57:11 +00:00
if (isApplicationStartup)
{
2014-08-11 23:41:11 +00:00
await Task.Delay(DelayMs).ConfigureAwait(false);
2013-02-21 01:33:05 +00:00
2013-02-23 07:57:11 +00:00
OnTriggered();
}
2013-02-21 01:33:05 +00:00
}
/// <summary>
/// Stops waiting for the trigger action
/// </summary>
2013-02-24 21:53:54 +00:00
public void Stop()
2013-02-21 01:33:05 +00:00
{
}
2013-02-24 21:53:54 +00:00
/// <summary>
/// Occurs when [triggered].
/// </summary>
public event EventHandler<GenericEventArgs<TaskExecutionOptions>> Triggered;
2013-02-24 21:53:54 +00:00
/// <summary>
/// Called when [triggered].
/// </summary>
private void OnTriggered()
{
if (Triggered != null)
{
Triggered(this, new GenericEventArgs<TaskExecutionOptions>(TaskOptions));
2013-02-24 21:53:54 +00:00
}
}
2013-02-21 01:33:05 +00:00
}
}