The Free Software Media System - Server Backend & API
Register and construct ILibraryMonitor correctly
Mark Monteiroc2b21ce5531a
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.csindex 57ec71c9da..51c6f13424 100644--- a/Emby.Server.Implementations/ApplicationHost.cs+++ b/Emby.Server.Implementations/ApplicationHost.cs@@ -257,12 +257,6 @@ namespace Emby.Server.Implementations/// <value>The library manager.</value>internal ILibraryManager LibraryManager { get; set; }- /// <summary>- /// Gets or sets the directory watchers.- /// </summary>- /// <value>The directory watchers.</value>- private ILibraryMonitor LibraryMonitor { get; set; }-/// <summary>/// Gets or sets the media encoder./// </summary>@@ -708,14 +702,13 @@ namespace Emby.Server.ImplementationsStartupOptions.FFmpegPath);serviceCollection.AddSingleton(MediaEncoder);- LibraryManager = new LibraryManager(this, LoggerFactory, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, () => LibraryMonitor, FileSystemManager, Resolve<IProviderManager>, Resolve<IUserViewManager>, MediaEncoder);+ LibraryManager = new LibraryManager(this, LoggerFactory, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, Resolve<ILibraryMonitor>, FileSystemManager, Resolve<IProviderManager>, Resolve<IUserViewManager>, MediaEncoder);serviceCollection.AddSingleton(LibraryManager);var musicManager = new MusicManager(LibraryManager);serviceCollection.AddSingleton<IMusicManager>(musicManager);- LibraryMonitor = new LibraryMonitor(LoggerFactory, LibraryManager, ServerConfigurationManager, FileSystemManager);- serviceCollection.AddSingleton(LibraryMonitor);+ serviceCollection.AddSingleton<ILibraryMonitor, LibraryMonitor>();serviceCollection.AddSingleton<ISearchEngine>(new SearchEngine(LoggerFactory, LibraryManager, UserManager));diff --git a/Emby.Server.Implementations/IO/LibraryMonitor.cs b/Emby.Server.Implementations/IO/LibraryMonitor.csindex b1fb8cc635..5a1eb43bcb 100644--- a/Emby.Server.Implementations/IO/LibraryMonitor.cs+++ b/Emby.Server.Implementations/IO/LibraryMonitor.cs@@ -17,6 +17,11 @@ namespace Emby.Server.Implementations.IO{public class LibraryMonitor : ILibraryMonitor{+ private readonly ILogger _logger;+ private readonly ILibraryManager _libraryManager;+ private readonly IServerConfigurationManager _configurationManager;+ private readonly IFileSystem _fileSystem;+/// <summary>/// The file system watchers./// </summary>@@ -113,34 +118,23 @@ namespace Emby.Server.Implementations.IO}catch (Exception ex){- Logger.LogError(ex, "Error in ReportFileSystemChanged for {path}", path);+ _logger.LogError(ex, "Error in ReportFileSystemChanged for {path}", path);}}}- /// <summary>- /// Gets or sets the logger.- /// </summary>- /// <value>The logger.</value>- private ILogger Logger { get; set; }-- private ILibraryManager LibraryManager { get; set; }- private IServerConfigurationManager ConfigurationManager { get; set; }-- private readonly IFileSystem _fileSystem;-/// <summary>/// Initializes a new instance of the <see cref="LibraryMonitor" /> class./// </summary>public LibraryMonitor(- ILoggerFactory loggerFactory,+ ILogger<LibraryMonitor> logger,ILibraryManager libraryManager,IServerConfigurationManager configurationManager,IFileSystem fileSystem){- LibraryManager = libraryManager;- Logger = loggerFactory.CreateLogger(GetType().Name);- ConfigurationManager = configurationManager;+ _libraryManager = libraryManager;+ _logger = logger;+ _configurationManager = configurationManager;_fileSystem = fileSystem;}@@ -151,7 +145,7 @@ namespace Emby.Server.Implementations.IOreturn false;}- var options = LibraryManager.GetLibraryOptions(item);+ var options = _libraryManager.GetLibraryOptions(item);if (options != null){@@ -163,12 +157,12 @@ namespace Emby.Server.Implementations.IOpublic void Start(){- LibraryManager.ItemAdded += OnLibraryManagerItemAdded;- LibraryManager.ItemRemoved += OnLibraryManagerItemRemoved;+ _libraryManager.ItemAdded += OnLibraryManagerItemAdded;+ _libraryManager.ItemRemoved += OnLibraryManagerItemRemoved;var pathsToWatch = new List<string>();- var paths = LibraryManager+ var paths = _libraryManager.RootFolder.Children.Where(IsLibraryMonitorEnabled)@@ -261,7 +255,7 @@ namespace Emby.Server.Implementations.IOif (!Directory.Exists(path)){// Seeing a crash in the mono runtime due to an exception being thrown on a different thread- Logger.LogInformation("Skipping realtime monitor for {Path} because the path does not exist", path);+ _logger.LogInformation("Skipping realtime monitor for {Path} because the path does not exist", path);return;}@@ -297,7 +291,7 @@ namespace Emby.Server.Implementations.IOif (_fileSystemWatchers.TryAdd(path, newWatcher)){newWatcher.EnableRaisingEvents = true;- Logger.LogInformation("Watching directory " + path);+ _logger.LogInformation("Watching directory " + path);}else{@@ -307,7 +301,7 @@ namespace Emby.Server.Implementations.IO}catch (Exception ex){- Logger.LogError(ex, "Error watching path: {path}", path);+ _logger.LogError(ex, "Error watching path: {path}", path);}});}@@ -333,7 +327,7 @@ namespace Emby.Server.Implementations.IO{using (watcher){- Logger.LogInformation("Stopping directory watching for path {Path}", watcher.Path);+ _logger.LogInformation("Stopping directory watching for path {Path}", watcher.Path);watcher.Created -= OnWatcherChanged;watcher.Deleted -= OnWatcherChanged;@@ -372,7 +366,7 @@ namespace Emby.Server.Implementations.IOvar ex = e.GetException();var dw = (FileSystemWatcher)sender;- Logger.LogError(ex, "Error in Directory watcher for: {Path}", dw.Path);+ _logger.LogError(ex, "Error in Directory watcher for: {Path}", dw.Path);DisposeWatcher(dw, true);}@@ -390,7 +384,7 @@ namespace Emby.Server.Implementations.IO}catch (Exception ex){- Logger.LogError(ex, "Exception in ReportFileSystemChanged. Path: {FullPath}", e.FullPath);+ _logger.LogError(ex, "Exception in ReportFileSystemChanged. Path: {FullPath}", e.FullPath);}}@@ -416,13 +410,13 @@ namespace Emby.Server.Implementations.IO{if (_fileSystem.AreEqual(i, path)){- Logger.LogDebug("Ignoring change to {Path}", path);+ _logger.LogDebug("Ignoring change to {Path}", path);return true;}if (_fileSystem.ContainsSubPath(i, path)){- Logger.LogDebug("Ignoring change to {Path}", path);+ _logger.LogDebug("Ignoring change to {Path}", path);return true;}@@ -430,7 +424,7 @@ namespace Emby.Server.Implementations.IOvar parent = Path.GetDirectoryName(i);if (!string.IsNullOrEmpty(parent) && _fileSystem.AreEqual(parent, path)){- Logger.LogDebug("Ignoring change to {Path}", path);+ _logger.LogDebug("Ignoring change to {Path}", path);return true;}@@ -485,7 +479,7 @@ namespace Emby.Server.Implementations.IO}}- var newRefresher = new FileRefresher(path, ConfigurationManager, LibraryManager, Logger);+ var newRefresher = new FileRefresher(path, _configurationManager, _libraryManager, _logger);newRefresher.Completed += NewRefresher_Completed;_activeRefreshers.Add(newRefresher);}@@ -502,8 +496,8 @@ namespace Emby.Server.Implementations.IO/// </summary>public void Stop(){- LibraryManager.ItemAdded -= OnLibraryManagerItemAdded;- LibraryManager.ItemRemoved -= OnLibraryManagerItemRemoved;+ _libraryManager.ItemAdded -= OnLibraryManagerItemAdded;+ _libraryManager.ItemRemoved -= OnLibraryManagerItemRemoved;foreach (var watcher in _fileSystemWatchers.Values.ToList()){