浏览代码

support realtime monitor per library

Luke Pulverenti 8 年之前
父节点
当前提交
c46e38725e

+ 1 - 0
MediaBrowser.Controller/Entities/CollectionFolder.cs

@@ -106,6 +106,7 @@ namespace MediaBrowser.Controller.Entities
             {
             {
                 LibraryOptions[path] = options;
                 LibraryOptions[path] = options;
 
 
+                options.SchemaVersion = 1;
                 XmlSerializer.SerializeToFile(options, GetLibraryOptionsPath(path));
                 XmlSerializer.SerializeToFile(options, GetLibraryOptionsPath(path));
             }
             }
         }
         }

+ 3 - 0
MediaBrowser.Model/Configuration/LibraryOptions.cs

@@ -4,10 +4,13 @@
     {
     {
         public bool EnableArchiveMediaFiles { get; set; }
         public bool EnableArchiveMediaFiles { get; set; }
         public bool EnablePhotos { get; set; }
         public bool EnablePhotos { get; set; }
+        public bool EnableRealtimeMonitor { get; set; }
+        public int SchemaVersion { get; set; }
 
 
         public LibraryOptions()
         public LibraryOptions()
         {
         {
             EnablePhotos = true;
             EnablePhotos = true;
+            EnableRealtimeMonitor = true;
         }
         }
     }
     }
 }
 }

+ 21 - 19
MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs

@@ -172,27 +172,29 @@ namespace MediaBrowser.Server.Implementations.IO
             }
             }
         }
         }
 
 
-        public void Start()
+        private bool IsLibraryMonitorEnabaled(BaseItem item)
         {
         {
-            if (EnableLibraryMonitor)
+            var options = LibraryManager.GetLibraryOptions(item);
+
+            if (options != null && options.SchemaVersion >= 1)
             {
             {
-                StartInternal();
+                return options.EnableRealtimeMonitor;
             }
             }
+
+            return EnableLibraryMonitor;
         }
         }
 
 
-        /// <summary>
-        /// Starts this instance.
-        /// </summary>
-        private void StartInternal()
+        public void Start()
         {
         {
             LibraryManager.ItemAdded += LibraryManager_ItemAdded;
             LibraryManager.ItemAdded += LibraryManager_ItemAdded;
             LibraryManager.ItemRemoved += LibraryManager_ItemRemoved;
             LibraryManager.ItemRemoved += LibraryManager_ItemRemoved;
 
 
-            var pathsToWatch = new List<string> { LibraryManager.RootFolder.Path };
+            var pathsToWatch = new List<string> { };
 
 
             var paths = LibraryManager
             var paths = LibraryManager
                 .RootFolder
                 .RootFolder
                 .Children
                 .Children
+                .Where(IsLibraryMonitorEnabaled)
                 .OfType<Folder>()
                 .OfType<Folder>()
                 .SelectMany(f => f.PhysicalLocations)
                 .SelectMany(f => f.PhysicalLocations)
                 .Distinct(StringComparer.OrdinalIgnoreCase)
                 .Distinct(StringComparer.OrdinalIgnoreCase)
@@ -213,6 +215,14 @@ namespace MediaBrowser.Server.Implementations.IO
             }
             }
         }
         }
 
 
+        private void StartWatching(BaseItem item)
+        {
+            if (IsLibraryMonitorEnabaled(item))
+            {
+                StartWatchingPath(item.Path);
+            }
+        }
+
         /// <summary>
         /// <summary>
         /// Handles the ItemRemoved event of the LibraryManager control.
         /// Handles the ItemRemoved event of the LibraryManager control.
         /// </summary>
         /// </summary>
@@ -235,7 +245,7 @@ namespace MediaBrowser.Server.Implementations.IO
         {
         {
             if (e.Item.GetParent() is AggregateFolder)
             if (e.Item.GetParent() is AggregateFolder)
             {
             {
-                StartWatchingPath(e.Item.Path);
+                StartWatching(e.Item);
             }
             }
         }
         }
 
 
@@ -382,14 +392,6 @@ namespace MediaBrowser.Server.Implementations.IO
             Logger.ErrorException("Error in Directory watcher for: " + dw.Path, ex);
             Logger.ErrorException("Error in Directory watcher for: " + dw.Path, ex);
 
 
             DisposeWatcher(dw);
             DisposeWatcher(dw);
-
-            if (ConfigurationManager.Configuration.EnableLibraryMonitor == AutoOnOff.Auto)
-            {
-                Logger.Info("Disabling realtime monitor to prevent future instability");
-
-                ConfigurationManager.Configuration.EnableLibraryMonitor = AutoOnOff.Disabled;
-                Stop();
-            }
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -420,8 +422,8 @@ namespace MediaBrowser.Server.Implementations.IO
 
 
             var filename = Path.GetFileName(path);
             var filename = Path.GetFileName(path);
 
 
-            var monitorPath = !string.IsNullOrEmpty(filename) && 
-                !_alwaysIgnoreFiles.Contains(filename, StringComparer.OrdinalIgnoreCase) && 
+            var monitorPath = !string.IsNullOrEmpty(filename) &&
+                !_alwaysIgnoreFiles.Contains(filename, StringComparer.OrdinalIgnoreCase) &&
                 !_alwaysIgnoreExtensions.Contains(Path.GetExtension(path) ?? string.Empty, StringComparer.OrdinalIgnoreCase);
                 !_alwaysIgnoreExtensions.Contains(Path.GetExtension(path) ?? string.Empty, StringComparer.OrdinalIgnoreCase);
 
 
             // Ignore certain files
             // Ignore certain files