SortingScheduledTask.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using MediaBrowser.Common.IO;
  2. using MediaBrowser.Common.ScheduledTasks;
  3. using MediaBrowser.Controller.Configuration;
  4. using MediaBrowser.Controller.Library;
  5. using MediaBrowser.Model.Logging;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. namespace MediaBrowser.Server.Implementations.FileSorting
  11. {
  12. public class SortingScheduledTask : IScheduledTask, IConfigurableScheduledTask
  13. {
  14. private readonly IServerConfigurationManager _config;
  15. private readonly ILogger _logger;
  16. private readonly ILibraryManager _libraryManager;
  17. private readonly IFileSystem _fileSystem;
  18. public SortingScheduledTask(IServerConfigurationManager config, ILogger logger, ILibraryManager libraryManager, IFileSystem fileSystem)
  19. {
  20. _config = config;
  21. _logger = logger;
  22. _libraryManager = libraryManager;
  23. _fileSystem = fileSystem;
  24. }
  25. public string Name
  26. {
  27. get { return "Sort new files"; }
  28. }
  29. public string Description
  30. {
  31. get { return "Processes new files available in the configured sorting location."; }
  32. }
  33. public string Category
  34. {
  35. get { return "Library"; }
  36. }
  37. public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
  38. {
  39. return Task.Run(() => SortFiles(cancellationToken, progress), cancellationToken);
  40. }
  41. private void SortFiles(CancellationToken cancellationToken, IProgress<double> progress)
  42. {
  43. new TvFileSorter(_libraryManager, _logger, _fileSystem).Sort(_config.Configuration.FileSortingOptions, cancellationToken, progress);
  44. }
  45. public IEnumerable<ITaskTrigger> GetDefaultTriggers()
  46. {
  47. return new ITaskTrigger[]
  48. {
  49. new IntervalTrigger{ Interval = TimeSpan.FromMinutes(5)}
  50. };
  51. }
  52. public bool IsHidden
  53. {
  54. get { return !_config.Configuration.FileSortingOptions.IsEnabled; }
  55. }
  56. public bool IsEnabled
  57. {
  58. get { return _config.Configuration.FileSortingOptions.IsEnabled; }
  59. }
  60. }
  61. }