using System;
using System.Threading.Tasks;
using MediaBrowser.Model.Events;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Tasks;
namespace Emby.Server.Implementations.ScheduledTasks
{
///
/// Class StartupTaskTrigger
///
public class StartupTrigger : ITaskTrigger
{
public int DelayMs { get; set; }
///
/// Gets the execution properties of this task.
///
///
/// The execution properties of this task.
///
public TaskExecutionOptions TaskOptions { get; set; }
public StartupTrigger()
{
DelayMs = 3000;
}
///
/// Stars waiting for the trigger action
///
/// The last result.
/// if set to true [is application startup].
public async void Start(TaskResult lastResult, ILogger logger, string taskName, bool isApplicationStartup)
{
if (isApplicationStartup)
{
await Task.Delay(DelayMs).ConfigureAwait(false);
OnTriggered();
}
}
///
/// Stops waiting for the trigger action
///
public void Stop()
{
}
///
/// Occurs when [triggered].
///
public event EventHandler> Triggered;
///
/// Called when [triggered].
///
private void OnTriggered()
{
if (Triggered != null)
{
Triggered(this, new GenericEventArgs(TaskOptions));
}
}
}
}