StartupTrigger.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using MediaBrowser.Model.Events;
  2. using MediaBrowser.Model.Tasks;
  3. using System;
  4. using System.Threading.Tasks;
  5. namespace MediaBrowser.Common.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 the execution properties of this task.
  15. /// </summary>
  16. /// <value>
  17. /// The execution properties of this task.
  18. /// </value>
  19. public TaskExecutionOptions TaskOptions { get; set; }
  20. public StartupTrigger()
  21. {
  22. DelayMs = 3000;
  23. }
  24. /// <summary>
  25. /// Stars waiting for the trigger action
  26. /// </summary>
  27. /// <param name="lastResult">The last result.</param>
  28. /// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param>
  29. public async void Start(TaskResult lastResult, bool isApplicationStartup)
  30. {
  31. if (isApplicationStartup)
  32. {
  33. await Task.Delay(DelayMs).ConfigureAwait(false);
  34. OnTriggered();
  35. }
  36. }
  37. /// <summary>
  38. /// Stops waiting for the trigger action
  39. /// </summary>
  40. public void Stop()
  41. {
  42. }
  43. /// <summary>
  44. /// Occurs when [triggered].
  45. /// </summary>
  46. public event EventHandler<GenericEventArgs<TaskExecutionOptions>> Triggered;
  47. /// <summary>
  48. /// Called when [triggered].
  49. /// </summary>
  50. private void OnTriggered()
  51. {
  52. if (Triggered != null)
  53. {
  54. Triggered(this, new GenericEventArgs<TaskExecutionOptions>(TaskOptions));
  55. }
  56. }
  57. }
  58. }