StartupTrigger.cs 1.6 KB

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