2
0

StartupTrigger.cs 1.7 KB

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