jellyfin/MediaBrowser.Common/ScheduledTasks/StartupTrigger.cs

68 lines
1.8 KiB
C#
Raw Normal View History

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