StartupTrigger.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Threading.Tasks;
  4. using MediaBrowser.Model.Tasks;
  5. using Microsoft.Extensions.Logging;
  6. namespace Emby.Server.Implementations.ScheduledTasks.Triggers
  7. {
  8. /// <summary>
  9. /// Class StartupTaskTrigger.
  10. /// </summary>
  11. public sealed class StartupTrigger : ITaskTrigger
  12. {
  13. public const int DelayMs = 3000;
  14. /// <summary>
  15. /// Initializes a new instance of the <see cref="StartupTrigger"/> class.
  16. /// </summary>
  17. /// <param name="taskOptions">The options of this task.</param>
  18. public StartupTrigger(TaskOptions taskOptions)
  19. {
  20. TaskOptions = taskOptions;
  21. }
  22. /// <summary>
  23. /// Occurs when [triggered].
  24. /// </summary>
  25. public event EventHandler<EventArgs>? Triggered;
  26. /// <summary>
  27. /// Gets the options of this task.
  28. /// </summary>
  29. public TaskOptions TaskOptions { get; }
  30. /// <summary>
  31. /// Stars waiting for the trigger action.
  32. /// </summary>
  33. /// <param name="lastResult">The last result.</param>
  34. /// <param name="logger">The logger.</param>
  35. /// <param name="taskName">The name of the task.</param>
  36. /// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param>
  37. public async void Start(TaskResult? lastResult, ILogger logger, string taskName, bool isApplicationStartup)
  38. {
  39. if (isApplicationStartup)
  40. {
  41. await Task.Delay(DelayMs).ConfigureAwait(false);
  42. OnTriggered();
  43. }
  44. }
  45. /// <summary>
  46. /// Stops waiting for the trigger action.
  47. /// </summary>
  48. public void Stop()
  49. {
  50. }
  51. /// <summary>
  52. /// Called when [triggered].
  53. /// </summary>
  54. private void OnTriggered()
  55. {
  56. Triggered?.Invoke(this, EventArgs.Empty);
  57. }
  58. }
  59. }