RefreshMediaLibraryTask.cs 3.4 KB

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