support realtime monitor per library

This commit is contained in:
Luke Pulverenti 2016-08-24 16:46:26 -04:00
parent e5d5c67041
commit c46e38725e
3 changed files with 25 additions and 19 deletions

View File

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

View File

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

View File

@ -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;
}
/// <summary>
/// Starts this instance.
/// </summary>
private void StartInternal()
return EnableLibraryMonitor;
}
public void Start()
{
LibraryManager.ItemAdded += LibraryManager_ItemAdded;
LibraryManager.ItemRemoved += LibraryManager_ItemRemoved;
var pathsToWatch = new List<string> { LibraryManager.RootFolder.Path };
var pathsToWatch = new List<string> { };
var paths = LibraryManager
.RootFolder
.Children
.Where(IsLibraryMonitorEnabaled)
.OfType<Folder>()
.SelectMany(f => f.PhysicalLocations)
.Distinct(StringComparer.OrdinalIgnoreCase)
@ -213,6 +215,14 @@ namespace MediaBrowser.Server.Implementations.IO
}
}
private void StartWatching(BaseItem item)
{
if (IsLibraryMonitorEnabaled(item))
{
StartWatchingPath(item.Path);
}
}
/// <summary>
/// Handles the ItemRemoved event of the LibraryManager control.
/// </summary>
@ -235,7 +245,7 @@ namespace MediaBrowser.Server.Implementations.IO
{
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);
DisposeWatcher(dw);
if (ConfigurationManager.Configuration.EnableLibraryMonitor == AutoOnOff.Auto)
{
Logger.Info("Disabling realtime monitor to prevent future instability");
ConfigurationManager.Configuration.EnableLibraryMonitor = AutoOnOff.Disabled;
Stop();
}
}
/// <summary>