PeopleValidationTask.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using MediaBrowser.Controller.Library;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using MediaBrowser.Controller;
  7. using MediaBrowser.Model.Tasks;
  8. namespace Emby.Server.Implementations.ScheduledTasks
  9. {
  10. /// <summary>
  11. /// Class PeopleValidationTask
  12. /// </summary>
  13. public class PeopleValidationTask : IScheduledTask
  14. {
  15. /// <summary>
  16. /// The _library manager
  17. /// </summary>
  18. private readonly ILibraryManager _libraryManager;
  19. private readonly IServerApplicationHost _appHost;
  20. /// <summary>
  21. /// Initializes a new instance of the <see cref="PeopleValidationTask" /> class.
  22. /// </summary>
  23. /// <param name="libraryManager">The library manager.</param>
  24. public PeopleValidationTask(ILibraryManager libraryManager, IServerApplicationHost appHost)
  25. {
  26. _libraryManager = libraryManager;
  27. _appHost = appHost;
  28. }
  29. /// <summary>
  30. /// Creates the triggers that define when the task will run
  31. /// </summary>
  32. public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
  33. {
  34. // Randomize the default start hour because this operation can really hammer internet metadata providers
  35. var startHour = new Random(_appHost.SystemId.GetHashCode()).Next(0, 8);
  36. return new[] {
  37. // Every so often
  38. new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerDaily, TimeOfDayTicks = TimeSpan.FromHours(startHour).Ticks}
  39. };
  40. }
  41. public string Key
  42. {
  43. get { return "RefreshPeople"; }
  44. }
  45. /// <summary>
  46. /// Returns the task to be executed
  47. /// </summary>
  48. /// <param name="cancellationToken">The cancellation token.</param>
  49. /// <param name="progress">The progress.</param>
  50. /// <returns>Task.</returns>
  51. public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
  52. {
  53. return _libraryManager.ValidatePeople(cancellationToken, progress);
  54. }
  55. /// <summary>
  56. /// Gets the name of the task
  57. /// </summary>
  58. /// <value>The name.</value>
  59. public string Name
  60. {
  61. get { return "Refresh people"; }
  62. }
  63. /// <summary>
  64. /// Gets the description.
  65. /// </summary>
  66. /// <value>The description.</value>
  67. public string Description
  68. {
  69. get { return "Updates metadata for actors and directors in your media library."; }
  70. }
  71. /// <summary>
  72. /// Gets the category.
  73. /// </summary>
  74. /// <value>The category.</value>
  75. public string Category
  76. {
  77. get
  78. {
  79. return "Library";
  80. }
  81. }
  82. }
  83. }