RefreshMediaLibraryTask.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using MediaBrowser.Common.ScheduledTasks;
  2. using MediaBrowser.Model.Tasks;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel.Composition;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. namespace MediaBrowser.Controller.ScheduledTasks
  9. {
  10. /// <summary>
  11. /// Class RefreshMediaLibraryTask
  12. /// </summary>
  13. [Export(typeof(IScheduledTask))]
  14. public class RefreshMediaLibraryTask : BaseScheduledTask<Kernel>
  15. {
  16. /// <summary>
  17. /// Gets the default triggers.
  18. /// </summary>
  19. /// <returns>IEnumerable{BaseTaskTrigger}.</returns>
  20. protected override IEnumerable<BaseTaskTrigger> GetDefaultTriggers()
  21. {
  22. return new BaseTaskTrigger[] {
  23. new StartupTrigger(Kernel),
  24. new SystemEventTrigger{ SystemEvent = SystemEvent.WakeFromSleep},
  25. new IntervalTrigger{ Interval = TimeSpan.FromHours(2)}
  26. };
  27. }
  28. /// <summary>
  29. /// Executes the internal.
  30. /// </summary>
  31. /// <param name="cancellationToken">The cancellation token.</param>
  32. /// <param name="progress">The progress.</param>
  33. /// <returns>Task.</returns>
  34. protected override Task ExecuteInternal(CancellationToken cancellationToken, IProgress<TaskProgress> progress)
  35. {
  36. cancellationToken.ThrowIfCancellationRequested();
  37. progress.Report(new TaskProgress { PercentComplete = 0 });
  38. return Kernel.LibraryManager.ValidateMediaLibrary(progress, cancellationToken);
  39. }
  40. /// <summary>
  41. /// Gets the name.
  42. /// </summary>
  43. /// <value>The name.</value>
  44. public override string Name
  45. {
  46. get { return "Scan media library"; }
  47. }
  48. /// <summary>
  49. /// Gets the description.
  50. /// </summary>
  51. /// <value>The description.</value>
  52. public override string Description
  53. {
  54. get { return "Scans your media library and refreshes metatata based on configuration."; }
  55. }
  56. /// <summary>
  57. /// Gets the category.
  58. /// </summary>
  59. /// <value>The category.</value>
  60. public override string Category
  61. {
  62. get
  63. {
  64. return "Library";
  65. }
  66. }
  67. }
  68. }