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