mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-06-03 13:44:22 -04:00
Register and construct ILibraryMonitor correctly
This commit is contained in:
parent
d173358065
commit
c2b21ce553
@ -257,12 +257,6 @@ namespace Emby.Server.Implementations
|
|||||||
/// <value>The library manager.</value>
|
/// <value>The library manager.</value>
|
||||||
internal ILibraryManager LibraryManager { get; set; }
|
internal ILibraryManager LibraryManager { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the directory watchers.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The directory watchers.</value>
|
|
||||||
private ILibraryMonitor LibraryMonitor { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the media encoder.
|
/// Gets or sets the media encoder.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -708,14 +702,13 @@ namespace Emby.Server.Implementations
|
|||||||
StartupOptions.FFmpegPath);
|
StartupOptions.FFmpegPath);
|
||||||
serviceCollection.AddSingleton(MediaEncoder);
|
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);
|
serviceCollection.AddSingleton(LibraryManager);
|
||||||
|
|
||||||
var musicManager = new MusicManager(LibraryManager);
|
var musicManager = new MusicManager(LibraryManager);
|
||||||
serviceCollection.AddSingleton<IMusicManager>(musicManager);
|
serviceCollection.AddSingleton<IMusicManager>(musicManager);
|
||||||
|
|
||||||
LibraryMonitor = new LibraryMonitor(LoggerFactory, LibraryManager, ServerConfigurationManager, FileSystemManager);
|
serviceCollection.AddSingleton<ILibraryMonitor, LibraryMonitor>();
|
||||||
serviceCollection.AddSingleton(LibraryMonitor);
|
|
||||||
|
|
||||||
serviceCollection.AddSingleton<ISearchEngine>(new SearchEngine(LoggerFactory, LibraryManager, UserManager));
|
serviceCollection.AddSingleton<ISearchEngine>(new SearchEngine(LoggerFactory, LibraryManager, UserManager));
|
||||||
|
|
||||||
|
@ -17,6 +17,11 @@ namespace Emby.Server.Implementations.IO
|
|||||||
{
|
{
|
||||||
public class LibraryMonitor : ILibraryMonitor
|
public class LibraryMonitor : ILibraryMonitor
|
||||||
{
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
private readonly IServerConfigurationManager _configurationManager;
|
||||||
|
private readonly IFileSystem _fileSystem;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The file system watchers.
|
/// The file system watchers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -113,34 +118,23 @@ namespace Emby.Server.Implementations.IO
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
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>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="LibraryMonitor" /> class.
|
/// Initializes a new instance of the <see cref="LibraryMonitor" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public LibraryMonitor(
|
public LibraryMonitor(
|
||||||
ILoggerFactory loggerFactory,
|
ILogger<LibraryMonitor> logger,
|
||||||
ILibraryManager libraryManager,
|
ILibraryManager libraryManager,
|
||||||
IServerConfigurationManager configurationManager,
|
IServerConfigurationManager configurationManager,
|
||||||
IFileSystem fileSystem)
|
IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
LibraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
Logger = loggerFactory.CreateLogger(GetType().Name);
|
_logger = logger;
|
||||||
ConfigurationManager = configurationManager;
|
_configurationManager = configurationManager;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +145,7 @@ namespace Emby.Server.Implementations.IO
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var options = LibraryManager.GetLibraryOptions(item);
|
var options = _libraryManager.GetLibraryOptions(item);
|
||||||
|
|
||||||
if (options != null)
|
if (options != null)
|
||||||
{
|
{
|
||||||
@ -163,12 +157,12 @@ namespace Emby.Server.Implementations.IO
|
|||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
LibraryManager.ItemAdded += OnLibraryManagerItemAdded;
|
_libraryManager.ItemAdded += OnLibraryManagerItemAdded;
|
||||||
LibraryManager.ItemRemoved += OnLibraryManagerItemRemoved;
|
_libraryManager.ItemRemoved += OnLibraryManagerItemRemoved;
|
||||||
|
|
||||||
var pathsToWatch = new List<string>();
|
var pathsToWatch = new List<string>();
|
||||||
|
|
||||||
var paths = LibraryManager
|
var paths = _libraryManager
|
||||||
.RootFolder
|
.RootFolder
|
||||||
.Children
|
.Children
|
||||||
.Where(IsLibraryMonitorEnabled)
|
.Where(IsLibraryMonitorEnabled)
|
||||||
@ -261,7 +255,7 @@ namespace Emby.Server.Implementations.IO
|
|||||||
if (!Directory.Exists(path))
|
if (!Directory.Exists(path))
|
||||||
{
|
{
|
||||||
// Seeing a crash in the mono runtime due to an exception being thrown on a different thread
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,7 +291,7 @@ namespace Emby.Server.Implementations.IO
|
|||||||
if (_fileSystemWatchers.TryAdd(path, newWatcher))
|
if (_fileSystemWatchers.TryAdd(path, newWatcher))
|
||||||
{
|
{
|
||||||
newWatcher.EnableRaisingEvents = true;
|
newWatcher.EnableRaisingEvents = true;
|
||||||
Logger.LogInformation("Watching directory " + path);
|
_logger.LogInformation("Watching directory " + path);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -307,7 +301,7 @@ namespace Emby.Server.Implementations.IO
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
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)
|
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.Created -= OnWatcherChanged;
|
||||||
watcher.Deleted -= OnWatcherChanged;
|
watcher.Deleted -= OnWatcherChanged;
|
||||||
@ -372,7 +366,7 @@ namespace Emby.Server.Implementations.IO
|
|||||||
var ex = e.GetException();
|
var ex = e.GetException();
|
||||||
var dw = (FileSystemWatcher)sender;
|
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);
|
DisposeWatcher(dw, true);
|
||||||
}
|
}
|
||||||
@ -390,7 +384,7 @@ namespace Emby.Server.Implementations.IO
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
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))
|
if (_fileSystem.AreEqual(i, path))
|
||||||
{
|
{
|
||||||
Logger.LogDebug("Ignoring change to {Path}", path);
|
_logger.LogDebug("Ignoring change to {Path}", path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_fileSystem.ContainsSubPath(i, path))
|
if (_fileSystem.ContainsSubPath(i, path))
|
||||||
{
|
{
|
||||||
Logger.LogDebug("Ignoring change to {Path}", path);
|
_logger.LogDebug("Ignoring change to {Path}", path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,7 +424,7 @@ namespace Emby.Server.Implementations.IO
|
|||||||
var parent = Path.GetDirectoryName(i);
|
var parent = Path.GetDirectoryName(i);
|
||||||
if (!string.IsNullOrEmpty(parent) && _fileSystem.AreEqual(parent, path))
|
if (!string.IsNullOrEmpty(parent) && _fileSystem.AreEqual(parent, path))
|
||||||
{
|
{
|
||||||
Logger.LogDebug("Ignoring change to {Path}", path);
|
_logger.LogDebug("Ignoring change to {Path}", path);
|
||||||
return true;
|
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;
|
newRefresher.Completed += NewRefresher_Completed;
|
||||||
_activeRefreshers.Add(newRefresher);
|
_activeRefreshers.Add(newRefresher);
|
||||||
}
|
}
|
||||||
@ -502,8 +496,8 @@ namespace Emby.Server.Implementations.IO
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
LibraryManager.ItemAdded -= OnLibraryManagerItemAdded;
|
_libraryManager.ItemAdded -= OnLibraryManagerItemAdded;
|
||||||
LibraryManager.ItemRemoved -= OnLibraryManagerItemRemoved;
|
_libraryManager.ItemRemoved -= OnLibraryManagerItemRemoved;
|
||||||
|
|
||||||
foreach (var watcher in _fileSystemWatchers.Values.ToList())
|
foreach (var watcher in _fileSystemWatchers.Values.ToList())
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user