PeopleValidationTask.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using MediaBrowser.Common.ScheduledTasks;
  2. using MediaBrowser.Controller.Library;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using MediaBrowser.Controller;
  8. namespace MediaBrowser.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. /// <returns>IEnumerable{BaseTaskTrigger}.</returns>
  33. public IEnumerable<ITaskTrigger> GetDefaultTriggers()
  34. {
  35. // Randomize the default start hour because this operation can really hammer internet metadata providers
  36. var startHour = new Random(_appHost.SystemId.GetHashCode()).Next(0, 8);
  37. return new ITaskTrigger[]
  38. {
  39. new DailyTrigger { TimeOfDay = TimeSpan.FromHours(startHour) },
  40. };
  41. }
  42. /// <summary>
  43. /// Returns the task to be executed
  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. return _libraryManager.ValidatePeople(cancellationToken, progress);
  51. }
  52. /// <summary>
  53. /// Gets the name of the task
  54. /// </summary>
  55. /// <value>The name.</value>
  56. public string Name
  57. {
  58. get { return "Refresh people"; }
  59. }
  60. /// <summary>
  61. /// Gets the description.
  62. /// </summary>
  63. /// <value>The description.</value>
  64. public string Description
  65. {
  66. get { return "Updates metadata for actors and directors in your media library."; }
  67. }
  68. /// <summary>
  69. /// Gets the category.
  70. /// </summary>
  71. /// <value>The category.</value>
  72. public string Category
  73. {
  74. get
  75. {
  76. return "Library";
  77. }
  78. }
  79. }
  80. }