2020-05-29 09:28:19 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 19:54:44 +00:00
|
|
|
using System;
|
2016-10-29 05:40:15 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using MediaBrowser.Model.Tasks;
|
2019-01-13 19:22:24 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2016-10-29 05:40:15 +00:00
|
|
|
|
2021-12-15 17:25:36 +00:00
|
|
|
namespace Emby.Server.Implementations.ScheduledTasks.Triggers
|
2016-10-29 05:40:15 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
2020-05-29 09:28:19 +00:00
|
|
|
/// Class StartupTaskTrigger.
|
2016-10-29 05:40:15 +00:00
|
|
|
/// </summary>
|
2021-05-28 12:33:54 +00:00
|
|
|
public sealed class StartupTrigger : ITaskTrigger
|
2016-10-29 05:40:15 +00:00
|
|
|
{
|
2021-05-28 12:33:54 +00:00
|
|
|
public const int DelayMs = 3000;
|
|
|
|
|
2020-08-31 20:20:19 +00:00
|
|
|
/// <summary>
|
2021-05-28 12:33:54 +00:00
|
|
|
/// Initializes a new instance of the <see cref="StartupTrigger"/> class.
|
2020-08-31 20:20:19 +00:00
|
|
|
/// </summary>
|
2021-05-28 12:33:54 +00:00
|
|
|
/// <param name="taskOptions">The options of this task.</param>
|
|
|
|
public StartupTrigger(TaskOptions taskOptions)
|
|
|
|
{
|
|
|
|
TaskOptions = taskOptions;
|
|
|
|
}
|
2016-10-29 05:40:15 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2021-05-28 12:33:54 +00:00
|
|
|
/// Occurs when [triggered].
|
2016-10-29 05:40:15 +00:00
|
|
|
/// </summary>
|
2021-05-28 12:33:54 +00:00
|
|
|
public event EventHandler<EventArgs>? Triggered;
|
2016-10-29 05:40:15 +00:00
|
|
|
|
2021-05-28 12:33:54 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the options of this task.
|
|
|
|
/// </summary>
|
|
|
|
public TaskOptions TaskOptions { get; }
|
2016-10-29 05:40:15 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2020-06-15 22:37:52 +00:00
|
|
|
/// Stars waiting for the trigger action.
|
2016-10-29 05:40:15 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="lastResult">The last result.</param>
|
2020-05-29 09:28:19 +00:00
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
/// <param name="taskName">The name of the task.</param>
|
2016-10-29 05:40:15 +00:00
|
|
|
/// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param>
|
2021-12-15 17:25:36 +00:00
|
|
|
public async void Start(TaskResult? lastResult, ILogger logger, string taskName, bool isApplicationStartup)
|
2016-10-29 05:40:15 +00:00
|
|
|
{
|
|
|
|
if (isApplicationStartup)
|
|
|
|
{
|
|
|
|
await Task.Delay(DelayMs).ConfigureAwait(false);
|
|
|
|
|
|
|
|
OnTriggered();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-06-15 22:37:52 +00:00
|
|
|
/// Stops waiting for the trigger action.
|
2016-10-29 05:40:15 +00:00
|
|
|
/// </summary>
|
|
|
|
public void Stop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Called when [triggered].
|
|
|
|
/// </summary>
|
|
|
|
private void OnTriggered()
|
|
|
|
{
|
2020-08-31 20:20:19 +00:00
|
|
|
Triggered?.Invoke(this, EventArgs.Empty);
|
2016-10-29 05:40:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|