2
0

RefreshMediaLibraryTask.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using Emby.Server.Implementations.Library;
  7. using MediaBrowser.Controller.Library;
  8. using MediaBrowser.Model.Globalization;
  9. using MediaBrowser.Model.Tasks;
  10. namespace Emby.Server.Implementations.ScheduledTasks
  11. {
  12. /// <summary>
  13. /// Class RefreshMediaLibraryTask.
  14. /// </summary>
  15. public class RefreshMediaLibraryTask : IScheduledTask
  16. {
  17. /// <summary>
  18. /// The _library manager.
  19. /// </summary>
  20. private readonly ILibraryManager _libraryManager;
  21. private readonly ILocalizationManager _localization;
  22. /// <summary>
  23. /// Initializes a new instance of the <see cref="RefreshMediaLibraryTask" /> class.
  24. /// </summary>
  25. /// <param name="libraryManager">The library manager.</param>
  26. /// <param name="localization">The localization manager.</param>
  27. public RefreshMediaLibraryTask(ILibraryManager libraryManager, ILocalizationManager localization)
  28. {
  29. _libraryManager = libraryManager;
  30. _localization = localization;
  31. }
  32. /// <summary>
  33. /// Creates the triggers that define when the task will run.
  34. /// </summary>
  35. /// <returns>IEnumerable{BaseTaskTrigger}.</returns>
  36. public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
  37. {
  38. yield return new TaskTriggerInfo
  39. {
  40. Type = TaskTriggerInfo.TriggerInterval,
  41. IntervalTicks = TimeSpan.FromHours(12).Ticks
  42. };
  43. }
  44. /// <summary>
  45. /// Executes the internal.
  46. /// </summary>
  47. /// <param name="cancellationToken">The cancellation token.</param>
  48. /// <param name="progress">The progress.</param>
  49. /// <returns>Task.</returns>
  50. public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
  51. {
  52. cancellationToken.ThrowIfCancellationRequested();
  53. progress.Report(0);
  54. return ((LibraryManager)_libraryManager).ValidateMediaLibraryInternal(progress, cancellationToken);
  55. }
  56. /// <inheritdoc />
  57. public string Name => _localization.GetLocalizedString("TaskRefreshLibrary");
  58. /// <inheritdoc />
  59. public string Description => _localization.GetLocalizedString("TaskRefreshLibraryDescription");
  60. /// <inheritdoc />
  61. public string Category => _localization.GetLocalizedString("TasksLibraryCategory");
  62. /// <inheritdoc />
  63. public string Key => "RefreshLibrary";
  64. /// <inheritdoc />
  65. public bool IsHidden => false;
  66. /// <inheritdoc />
  67. public bool IsEnabled => true;
  68. /// <inheritdoc />
  69. public bool IsLogged => true;
  70. }
  71. }