From 7c5b22246357ef6bcd6d74e61a8fe6a8a9d4df3e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 28 Jan 2014 16:25:10 -0500 Subject: Created ILibraryMonitor to replace IDirectoryWatchers --- .../Library/LibraryStructureService.cs | 37 ++++++++-------------- 1 file changed, 13 insertions(+), 24 deletions(-) (limited to 'MediaBrowser.Api/Library/LibraryStructureService.cs') diff --git a/MediaBrowser.Api/Library/LibraryStructureService.cs b/MediaBrowser.Api/Library/LibraryStructureService.cs index 775907379..56b0e01c3 100644 --- a/MediaBrowser.Api/Library/LibraryStructureService.cs +++ b/MediaBrowser.Api/Library/LibraryStructureService.cs @@ -187,7 +187,7 @@ namespace MediaBrowser.Api.Library /// private readonly ILibraryManager _libraryManager; - private readonly IDirectoryWatchers _directoryWatchers; + private readonly ILibraryMonitor _libraryMonitor; private readonly IFileSystem _fileSystem; private readonly ILogger _logger; @@ -199,7 +199,7 @@ namespace MediaBrowser.Api.Library /// The user manager. /// The library manager. /// appPaths - public LibraryStructureService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager, IDirectoryWatchers directoryWatchers, IFileSystem fileSystem, ILogger logger) + public LibraryStructureService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager, ILibraryMonitor libraryMonitor, IFileSystem fileSystem, ILogger logger) { if (appPaths == null) { @@ -209,7 +209,7 @@ namespace MediaBrowser.Api.Library _userManager = userManager; _appPaths = appPaths; _libraryManager = libraryManager; - _directoryWatchers = directoryWatchers; + _libraryMonitor = libraryMonitor; _fileSystem = fileSystem; _logger = logger; } @@ -270,8 +270,7 @@ namespace MediaBrowser.Api.Library throw new ArgumentException("There is already a media collection with the name " + name + "."); } - _directoryWatchers.Stop(); - _directoryWatchers.TemporarilyIgnore(virtualFolderPath); + _libraryMonitor.Stop(); try { @@ -294,10 +293,8 @@ namespace MediaBrowser.Api.Library // No need to start if scanning the library because it will handle it if (!request.RefreshLibrary) { - _directoryWatchers.Start(); + _libraryMonitor.Start(); } - - _directoryWatchers.RemoveTempIgnore(virtualFolderPath); } if (request.RefreshLibrary) @@ -348,9 +345,7 @@ namespace MediaBrowser.Api.Library throw new ArgumentException("There is already a media collection with the name " + newPath + "."); } - _directoryWatchers.Stop(); - _directoryWatchers.TemporarilyIgnore(currentPath); - _directoryWatchers.TemporarilyIgnore(newPath); + _libraryMonitor.Stop(); try { @@ -376,11 +371,8 @@ namespace MediaBrowser.Api.Library // No need to start if scanning the library because it will handle it if (!request.RefreshLibrary) { - _directoryWatchers.Start(); + _libraryMonitor.Start(); } - - _directoryWatchers.RemoveTempIgnore(currentPath); - _directoryWatchers.RemoveTempIgnore(newPath); } if (request.RefreshLibrary) @@ -420,8 +412,7 @@ namespace MediaBrowser.Api.Library throw new DirectoryNotFoundException("The media folder does not exist"); } - _directoryWatchers.Stop(); - _directoryWatchers.TemporarilyIgnore(path); + _libraryMonitor.Stop(); try { @@ -437,10 +428,8 @@ namespace MediaBrowser.Api.Library // No need to start if scanning the library because it will handle it if (!request.RefreshLibrary) { - _directoryWatchers.Start(); + _libraryMonitor.Start(); } - - _directoryWatchers.RemoveTempIgnore(path); } if (request.RefreshLibrary) @@ -460,7 +449,7 @@ namespace MediaBrowser.Api.Library throw new ArgumentNullException("request"); } - _directoryWatchers.Stop(); + _libraryMonitor.Stop(); try { @@ -485,7 +474,7 @@ namespace MediaBrowser.Api.Library // No need to start if scanning the library because it will handle it if (!request.RefreshLibrary) { - _directoryWatchers.Start(); + _libraryMonitor.Start(); } } @@ -506,7 +495,7 @@ namespace MediaBrowser.Api.Library throw new ArgumentNullException("request"); } - _directoryWatchers.Stop(); + _libraryMonitor.Stop(); try { @@ -531,7 +520,7 @@ namespace MediaBrowser.Api.Library // No need to start if scanning the library because it will handle it if (!request.RefreshLibrary) { - _directoryWatchers.Start(); + _libraryMonitor.Start(); } } -- cgit v1.2.3 From 40b8300e8e72245c802938cd335a7ee962f8193f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 28 Jan 2014 16:51:47 -0500 Subject: added api for external apps to report file system changes --- .../Library/LibraryStructureService.cs | 25 +++++++++++++ .../IO/LibraryMonitor.cs | 41 +++++++++++++++------- 2 files changed, 54 insertions(+), 12 deletions(-) (limited to 'MediaBrowser.Api/Library/LibraryStructureService.cs') diff --git a/MediaBrowser.Api/Library/LibraryStructureService.cs b/MediaBrowser.Api/Library/LibraryStructureService.cs index 56b0e01c3..d0d56c07b 100644 --- a/MediaBrowser.Api/Library/LibraryStructureService.cs +++ b/MediaBrowser.Api/Library/LibraryStructureService.cs @@ -167,6 +167,16 @@ namespace MediaBrowser.Api.Library public bool RefreshLibrary { get; set; } } + [Route("/Library/Changes/Path", "POST")] + public class ReportChangedPath : IReturnVoid + { + /// + /// Gets or sets the name. + /// + /// The name. + public string Path { get; set; } + } + /// /// Class LibraryStructureService /// @@ -214,6 +224,21 @@ namespace MediaBrowser.Api.Library _logger = logger; } + /// + /// Posts the specified request. + /// + /// The request. + /// Please supply a Path + public void Post(ReportChangedPath request) + { + if (string.IsNullOrEmpty(request.Path)) + { + throw new ArgumentException("Please supply a Path"); + } + + _libraryMonitor.ReportFileSystemChanged(request.Path); + } + /// /// Gets the specified request. /// diff --git a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs index e09e66765..bf90dc40e 100644 --- a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs +++ b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.ScheduledTasks; +using MediaBrowser.Common.IO; +using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; @@ -72,11 +73,21 @@ namespace MediaBrowser.Server.Implementations.IO public void ReportFileSystemChangeBeginning(string path) { + if (string.IsNullOrEmpty(path)) + { + throw new ArgumentNullException("path"); + } + TemporarilyIgnore(path); } public void ReportFileSystemChangeComplete(string path, bool refreshPath) { + if (string.IsNullOrEmpty(path)) + { + throw new ArgumentNullException("path"); + } + RemoveTempIgnore(path); if (refreshPath) @@ -100,6 +111,8 @@ namespace MediaBrowser.Server.Implementations.IO private ILibraryManager LibraryManager { get; set; } private IServerConfigurationManager ConfigurationManager { get; set; } + private IFileSystem _fileSystem; + /// /// Initializes a new instance of the class. /// @@ -350,6 +363,11 @@ namespace MediaBrowser.Server.Implementations.IO public void ReportFileSystemChanged(string path) { + if (string.IsNullOrEmpty(path)) + { + throw new ArgumentNullException("path"); + } + var filename = Path.GetFileName(path); // Ignore certain files @@ -369,30 +387,29 @@ namespace MediaBrowser.Server.Implementations.IO return true; } - // Go up a level - var parent = Path.GetDirectoryName(i); - if (string.Equals(parent, path, StringComparison.OrdinalIgnoreCase)) + if (_fileSystem.ContainsSubPath(i, path)) { Logger.Debug("Ignoring change to {0}", path); return true; } - // Go up another level + // Go up a level + var parent = Path.GetDirectoryName(i); if (!string.IsNullOrEmpty(parent)) { - parent = Path.GetDirectoryName(i); if (string.Equals(parent, path, StringComparison.OrdinalIgnoreCase)) { Logger.Debug("Ignoring change to {0}", path); return true; } - } - if (i.StartsWith(path, StringComparison.OrdinalIgnoreCase) || - path.StartsWith(i, StringComparison.OrdinalIgnoreCase)) - { - Logger.Debug("Ignoring change to {0}", path); - return true; + // Go up another level + parent = Path.GetDirectoryName(i); + if (string.Equals(parent, path, StringComparison.OrdinalIgnoreCase)) + { + Logger.Debug("Ignoring change to {0}", path); + return true; + } } return false; -- cgit v1.2.3 From e772b44ac73cf77b41072b7578a4014c6234ef1b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 28 Jan 2014 20:46:04 -0500 Subject: fix library monitor reference --- MediaBrowser.Api/Library/LibraryStructureService.cs | 1 + MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs | 5 +++-- MediaBrowser.ServerApplication/ApplicationHost.cs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'MediaBrowser.Api/Library/LibraryStructureService.cs') diff --git a/MediaBrowser.Api/Library/LibraryStructureService.cs b/MediaBrowser.Api/Library/LibraryStructureService.cs index d0d56c07b..8ea472da3 100644 --- a/MediaBrowser.Api/Library/LibraryStructureService.cs +++ b/MediaBrowser.Api/Library/LibraryStructureService.cs @@ -174,6 +174,7 @@ namespace MediaBrowser.Api.Library /// Gets or sets the name. /// /// The name. + [ApiMember(Name = "Path", Description = "The path that was changed.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] public string Path { get; set; } } diff --git a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs index bf90dc40e..22ea668f4 100644 --- a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs +++ b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs @@ -111,12 +111,12 @@ namespace MediaBrowser.Server.Implementations.IO private ILibraryManager LibraryManager { get; set; } private IServerConfigurationManager ConfigurationManager { get; set; } - private IFileSystem _fileSystem; + private readonly IFileSystem _fileSystem; /// /// Initializes a new instance of the class. /// - public LibraryMonitor(ILogManager logManager, ITaskManager taskManager, ILibraryManager libraryManager, IServerConfigurationManager configurationManager) + public LibraryMonitor(ILogManager logManager, ITaskManager taskManager, ILibraryManager libraryManager, IServerConfigurationManager configurationManager, IFileSystem fileSystem) { if (taskManager == null) { @@ -127,6 +127,7 @@ namespace MediaBrowser.Server.Implementations.IO TaskManager = taskManager; Logger = logManager.GetLogger(GetType().Name); ConfigurationManager = configurationManager; + _fileSystem = fileSystem; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; } diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 0c8a6b923..bf652d8cb 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -276,7 +276,7 @@ namespace MediaBrowser.ServerApplication LibraryManager = new LibraryManager(Logger, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, () => LibraryMonitor, FileSystemManager); RegisterSingleInstance(LibraryManager); - LibraryMonitor = new LibraryMonitor(LogManager, TaskManager, LibraryManager, ServerConfigurationManager); + LibraryMonitor = new LibraryMonitor(LogManager, TaskManager, LibraryManager, ServerConfigurationManager, FileSystemManager); RegisterSingleInstance(LibraryMonitor); ProviderManager = new ProviderManager(HttpClient, ServerConfigurationManager, LibraryMonitor, LogManager, FileSystemManager, ItemRepository); -- cgit v1.2.3