diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations/IO')
| -rw-r--r-- | MediaBrowser.Server.Implementations/IO/FileRefresher.cs | 22 | ||||
| -rw-r--r-- | MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs | 9 |
2 files changed, 17 insertions, 14 deletions
diff --git a/MediaBrowser.Server.Implementations/IO/FileRefresher.cs b/MediaBrowser.Server.Implementations/IO/FileRefresher.cs index eeefdd65a..2742e1a26 100644 --- a/MediaBrowser.Server.Implementations/IO/FileRefresher.cs +++ b/MediaBrowser.Server.Implementations/IO/FileRefresher.cs @@ -14,7 +14,7 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Tasks; -using MediaBrowser.Server.Implementations.ScheduledTasks; +using MediaBrowser.Model.Threading; namespace MediaBrowser.Server.Implementations.IO { @@ -26,13 +26,14 @@ namespace MediaBrowser.Server.Implementations.IO private IServerConfigurationManager ConfigurationManager { get; set; } private readonly IFileSystem _fileSystem; private readonly List<string> _affectedPaths = new List<string>(); - private Timer _timer; + private ITimer _timer; + private readonly ITimerFactory _timerFactory; private readonly object _timerLock = new object(); public string Path { get; private set; } public event EventHandler<EventArgs> Completed; - public FileRefresher(string path, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, ITaskManager taskManager, ILogger logger) + public FileRefresher(string path, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, ITaskManager taskManager, ILogger logger, ITimerFactory timerFactory) { logger.Debug("New file refresher created for {0}", path); Path = path; @@ -42,6 +43,7 @@ namespace MediaBrowser.Server.Implementations.IO LibraryManager = libraryManager; TaskManager = taskManager; Logger = logger; + _timerFactory = timerFactory; AddPath(path); } @@ -88,7 +90,7 @@ namespace MediaBrowser.Server.Implementations.IO if (_timer == null) { - _timer = new Timer(OnTimerCallback, null, TimeSpan.FromSeconds(ConfigurationManager.Configuration.LibraryMonitorDelay), TimeSpan.FromMilliseconds(-1)); + _timer = _timerFactory.Create(OnTimerCallback, null, TimeSpan.FromSeconds(ConfigurationManager.Configuration.LibraryMonitorDelay), TimeSpan.FromMilliseconds(-1)); } else { @@ -163,7 +165,7 @@ namespace MediaBrowser.Server.Implementations.IO // If the root folder changed, run the library task so the user can see it if (itemsToRefresh.Any(i => i is AggregateFolder)) { - TaskManager.CancelIfRunningAndQueue<RefreshMediaLibraryTask>(); + LibraryManager.ValidateMediaLibrary(new Progress<double>(), CancellationToken.None); return; } @@ -268,11 +270,11 @@ namespace MediaBrowser.Server.Implementations.IO return false; } } - catch (DirectoryNotFoundException) - { - // File may have been deleted - return false; - } + //catch (DirectoryNotFoundException) + //{ + // // File may have been deleted + // return false; + //} catch (FileNotFoundException) { // File may have been deleted diff --git a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs index 77981b528..1f2a6255e 100644 --- a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs +++ b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs @@ -16,6 +16,7 @@ using MediaBrowser.Model.IO; using MediaBrowser.Controller; using MediaBrowser.Controller.IO; using MediaBrowser.Model.Tasks; +using MediaBrowser.Model.Threading; namespace MediaBrowser.Server.Implementations.IO { @@ -136,12 +137,12 @@ namespace MediaBrowser.Server.Implementations.IO private IServerConfigurationManager ConfigurationManager { get; set; } private readonly IFileSystem _fileSystem; - private readonly IServerApplicationHost _appHost; + private readonly ITimerFactory _timerFactory; /// <summary> /// Initializes a new instance of the <see cref="LibraryMonitor" /> class. /// </summary> - public LibraryMonitor(ILogManager logManager, ITaskManager taskManager, ILibraryManager libraryManager, IServerConfigurationManager configurationManager, IFileSystem fileSystem, IServerApplicationHost appHost) + public LibraryMonitor(ILogManager logManager, ITaskManager taskManager, ILibraryManager libraryManager, IServerConfigurationManager configurationManager, IFileSystem fileSystem, ITimerFactory timerFactory) { if (taskManager == null) { @@ -153,7 +154,7 @@ namespace MediaBrowser.Server.Implementations.IO Logger = logManager.GetLogger(GetType().Name); ConfigurationManager = configurationManager; _fileSystem = fileSystem; - _appHost = appHost; + _timerFactory = timerFactory; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; } @@ -528,7 +529,7 @@ namespace MediaBrowser.Server.Implementations.IO } } - var newRefresher = new FileRefresher(path, _fileSystem, ConfigurationManager, LibraryManager, TaskManager, Logger); + var newRefresher = new FileRefresher(path, _fileSystem, ConfigurationManager, LibraryManager, TaskManager, Logger, _timerFactory); newRefresher.Completed += NewRefresher_Completed; _activeRefreshers.Add(newRefresher); } |
