StartupTrigger.cs 1.8 KB

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