RefreshMediaLibraryTask.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System.Linq;
  2. using MediaBrowser.Common.ScheduledTasks;
  3. using MediaBrowser.Controller.Configuration;
  4. using MediaBrowser.Controller.Library;
  5. using MediaBrowser.Server.Implementations.Library;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. namespace MediaBrowser.Server.Implementations.ScheduledTasks
  11. {
  12. /// <summary>
  13. /// Class RefreshMediaLibraryTask
  14. /// </summary>
  15. public class RefreshMediaLibraryTask : IScheduledTask, IHasKey
  16. {
  17. /// <summary>
  18. /// The _library manager
  19. /// </summary>
  20. private readonly ILibraryManager _libraryManager;
  21. private readonly IServerConfigurationManager _config;
  22. /// <summary>
  23. /// Initializes a new instance of the <see cref="RefreshMediaLibraryTask" /> class.
  24. /// </summary>
  25. /// <param name="libraryManager">The library manager.</param>
  26. public RefreshMediaLibraryTask(ILibraryManager libraryManager, IServerConfigurationManager config)
  27. {
  28. _libraryManager = libraryManager;
  29. _config = config;
  30. }
  31. /// <summary>
  32. /// Gets the default triggers.
  33. /// </summary>
  34. /// <returns>IEnumerable{BaseTaskTrigger}.</returns>
  35. public IEnumerable<ITaskTrigger> GetDefaultTriggers()
  36. {
  37. var list = new ITaskTrigger[] {
  38. new IntervalTrigger{ Interval = TimeSpan.FromHours(12)}
  39. }.ToList();
  40. return list;
  41. }
  42. /// <summary>
  43. /// Executes the internal.
  44. /// </summary>
  45. /// <param name="cancellationToken">The cancellation token.</param>
  46. /// <param name="progress">The progress.</param>
  47. /// <returns>Task.</returns>
  48. public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
  49. {
  50. cancellationToken.ThrowIfCancellationRequested();
  51. progress.Report(0);
  52. return ((LibraryManager)_libraryManager).ValidateMediaLibraryInternal(progress, cancellationToken);
  53. }
  54. /// <summary>
  55. /// Gets the name.
  56. /// </summary>
  57. /// <value>The name.</value>
  58. public string Name
  59. {
  60. get { return "Scan media library"; }
  61. }
  62. /// <summary>
  63. /// Gets the description.
  64. /// </summary>
  65. /// <value>The description.</value>
  66. public string Description
  67. {
  68. get { return "Scans your media library and refreshes metatata based on configuration."; }
  69. }
  70. /// <summary>
  71. /// Gets the category.
  72. /// </summary>
  73. /// <value>The category.</value>
  74. public string Category
  75. {
  76. get
  77. {
  78. return "Library";
  79. }
  80. }
  81. public string Key
  82. {
  83. get { return "RefreshLibrary"; }
  84. }
  85. }
  86. }