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 --- .../Library/LibraryManager.cs | 89 ++++++++++++++-------- 1 file changed, 57 insertions(+), 32 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/LibraryManager.cs') diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index b78aa88f3..045b49aef 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -69,24 +69,20 @@ namespace MediaBrowser.Server.Implementations.Library /// The item repository. public IItemRepository ItemRepository { get; set; } - #region LibraryChanged Event /// - /// Fires whenever any validation routine adds or removes items. The added and removed items are properties of the args. - /// *** Will fire asynchronously. *** + /// Occurs when [item added]. /// - public event EventHandler LibraryChanged; + public event EventHandler ItemAdded; /// - /// Reports the library changed. + /// Occurs when [item updated]. /// - /// The instance containing the event data. - public void ReportLibraryChanged(ChildrenChangedEventArgs args) - { - UpdateLibraryCache(args); + public event EventHandler ItemUpdated; - EventHelper.FireEventIfNotNull(LibraryChanged, this, args, _logger); - } - #endregion + /// + /// Occurs when [item removed]. + /// + public event EventHandler ItemRemoved; /// /// The _logger @@ -302,25 +298,6 @@ namespace MediaBrowser.Server.Implementations.Library return new ConcurrentDictionary(items.ToDictionary(i => i.Id)); } - /// - /// Updates the library cache. - /// - /// The instance containing the event data. - private void UpdateLibraryCache(ChildrenChangedEventArgs args) - { - UpdateItemInLibraryCache(args.Folder); - - foreach (var item in args.ItemsAdded) - { - UpdateItemInLibraryCache(item); - } - - foreach (var item in args.ItemsUpdated) - { - UpdateItemInLibraryCache(item); - } - } - /// /// Updates the item in library cache. /// @@ -1069,13 +1046,61 @@ namespace MediaBrowser.Server.Implementations.Library return comparer; } + /// + /// Creates the item. + /// + /// The item. + /// The cancellation token. + /// Task. + public async Task CreateItem(BaseItem item, CancellationToken cancellationToken) + { + await SaveItem(item, cancellationToken).ConfigureAwait(false); + + UpdateItemInLibraryCache(item); + + if (ItemAdded != null) + { + ItemAdded(this, new ItemChangeEventArgs { Item = item }); + } + } + + /// + /// Updates the item. + /// + /// The item. + /// The cancellation token. + /// Task. + public async Task UpdateItem(BaseItem item, CancellationToken cancellationToken) + { + await SaveItem(item, cancellationToken).ConfigureAwait(false); + + UpdateItemInLibraryCache(item); + + if (ItemUpdated != null) + { + ItemUpdated(this, new ItemChangeEventArgs { Item = item }); + } + } + + /// + /// Reports the item removed. + /// + /// The item. + public void ReportItemRemoved(BaseItem item) + { + if (ItemRemoved != null) + { + ItemRemoved(this, new ItemChangeEventArgs { Item = item }); + } + } + /// /// Saves the item. /// /// The item. /// The cancellation token. /// Task. - public Task SaveItem(BaseItem item, CancellationToken cancellationToken) + private Task SaveItem(BaseItem item, CancellationToken cancellationToken) { return ItemRepository.SaveItem(item, cancellationToken); } -- cgit v1.2.3