From 6481688d2acc23b789dab6e8ad04a96e48c46064 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 3 May 2013 00:10:11 -0400 Subject: fixes #223 - New Content Localhost Popups Repeat 'Old' 'New Content' on Media Changes --- .../IO/DirectoryWatchers.cs | 58 +++++++++++----------- 1 file changed, 30 insertions(+), 28 deletions(-) (limited to 'MediaBrowser.Server.Implementations/IO') diff --git a/MediaBrowser.Server.Implementations/IO/DirectoryWatchers.cs b/MediaBrowser.Server.Implementations/IO/DirectoryWatchers.cs index d45952d6fd..51fbfd2198 100644 --- a/MediaBrowser.Server.Implementations/IO/DirectoryWatchers.cs +++ b/MediaBrowser.Server.Implementations/IO/DirectoryWatchers.cs @@ -103,7 +103,8 @@ namespace MediaBrowser.Server.Implementations.IO /// public void Start() { - LibraryManager.LibraryChanged += Instance_LibraryChanged; + LibraryManager.ItemAdded += LibraryManager_ItemAdded; + LibraryManager.ItemRemoved += LibraryManager_ItemRemoved; var pathsToWatch = new List { LibraryManager.RootFolder.Path }; @@ -137,6 +138,32 @@ namespace MediaBrowser.Server.Implementations.IO } } + /// + /// Handles the ItemRemoved event of the LibraryManager control. + /// + /// The source of the event. + /// The instance containing the event data. + void LibraryManager_ItemRemoved(object sender, ItemChangeEventArgs e) + { + if (e.Item.Parent is AggregateFolder) + { + StopWatchingPath(e.Item.Path); + } + } + + /// + /// Handles the ItemAdded event of the LibraryManager control. + /// + /// The source of the event. + /// The instance containing the event data. + void LibraryManager_ItemAdded(object sender, ItemChangeEventArgs e) + { + if (e.Item.Parent is AggregateFolder) + { + StartWatchingPath(e.Item.Path); + } + } + /// /// Examine a list of strings assumed to be file paths to see if it contains a parent of /// the provided path. @@ -231,32 +258,6 @@ namespace MediaBrowser.Server.Implementations.IO _fileSystemWatchers = new ConcurrentBag(watchers); } - /// - /// Handles the LibraryChanged event of the Kernel - /// - /// The source of the event. - /// The instance containing the event data. - void Instance_LibraryChanged(object sender, ChildrenChangedEventArgs e) - { - if (e.Folder is AggregateFolder && e.HasAddOrRemoveChange) - { - if (e.ItemsRemoved != null) - { - foreach (var item in e.ItemsRemoved.OfType()) - { - StopWatchingPath(item.Path); - } - } - if (e.ItemsAdded != null) - { - foreach (var item in e.ItemsAdded.OfType()) - { - StartWatchingPath(item.Path); - } - } - } - } - /// /// Handles the Error event of the watcher control. /// @@ -497,7 +498,8 @@ namespace MediaBrowser.Server.Implementations.IO /// public void Stop() { - LibraryManager.LibraryChanged -= Instance_LibraryChanged; + LibraryManager.ItemAdded -= LibraryManager_ItemAdded; + LibraryManager.ItemRemoved -= LibraryManager_ItemRemoved; FileSystemWatcher watcher; -- cgit v1.2.3