aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.ServerApplication/NewItemNotifier.cs
diff options
context:
space:
mode:
authorLukePulverenti <luke.pulverenti@gmail.com>2013-03-08 00:08:27 -0500
committerLukePulverenti <luke.pulverenti@gmail.com>2013-03-08 00:08:27 -0500
commit9911df11e8a96d5d7fffcd8618b63a6adb27701f (patch)
treeb7e446296c6b0f61804430cd59beda68aa549065 /MediaBrowser.ServerApplication/NewItemNotifier.cs
parent211d24e66e717f6294840b4f91806a24c1fb2e78 (diff)
extracted provider manager. took more off the kernel
Diffstat (limited to 'MediaBrowser.ServerApplication/NewItemNotifier.cs')
-rw-r--r--MediaBrowser.ServerApplication/NewItemNotifier.cs148
1 files changed, 0 insertions, 148 deletions
diff --git a/MediaBrowser.ServerApplication/NewItemNotifier.cs b/MediaBrowser.ServerApplication/NewItemNotifier.cs
deleted file mode 100644
index 4864cef62..000000000
--- a/MediaBrowser.ServerApplication/NewItemNotifier.cs
+++ /dev/null
@@ -1,148 +0,0 @@
-using System.Windows;
-using MediaBrowser.Controller.Entities;
-using MediaBrowser.Controller.Library;
-using MediaBrowser.Controller.Plugins;
-using MediaBrowser.Model.Logging;
-using MediaBrowser.ServerApplication.Controls;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using System.Windows.Controls.Primitives;
-
-namespace MediaBrowser.ServerApplication
-{
- /// <summary>
- /// Class NewItemNotifier
- /// </summary>
- public class NewItemNotifier : IServerEntryPoint
- {
- /// <summary>
- /// Holds the list of new items to display when the NewItemTimer expires
- /// </summary>
- private readonly List<BaseItem> _newlyAddedItems = new List<BaseItem>();
-
- /// <summary>
- /// The amount of time to wait before showing a new item notification
- /// This allows us to group items together into one notification
- /// </summary>
- private const int NewItemDelay = 60000;
-
- /// <summary>
- /// The current new item timer
- /// </summary>
- /// <value>The new item timer.</value>
- private Timer NewItemTimer { get; set; }
-
- /// <summary>
- /// The _library manager
- /// </summary>
- private readonly ILibraryManager _libraryManager;
-
- /// <summary>
- /// The _logger
- /// </summary>
- private readonly ILogger _logger;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="NewItemNotifier" /> class.
- /// </summary>
- /// <param name="libraryManager">The library manager.</param>
- /// <param name="logManager">The log manager.</param>
- public NewItemNotifier(ILibraryManager libraryManager, ILogManager logManager)
- {
- _logger = logManager.GetLogger("NewItemNotifier");
- _libraryManager = libraryManager;
- }
-
- /// <summary>
- /// Runs this instance.
- /// </summary>
- public void Run()
- {
- _libraryManager.LibraryChanged += libraryManager_LibraryChanged;
- }
-
- /// <summary>
- /// Handles the LibraryChanged event of the libraryManager control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="ChildrenChangedEventArgs" /> instance containing the event data.</param>
- void libraryManager_LibraryChanged(object sender, ChildrenChangedEventArgs e)
- {
- var newItems = e.ItemsAdded.Where(i => !i.IsFolder).ToList();
-
- // Use a timer to prevent lots of these notifications from showing in a short period of time
- if (newItems.Count > 0)
- {
- lock (_newlyAddedItems)
- {
- _newlyAddedItems.AddRange(newItems);
-
- if (NewItemTimer == null)
- {
- NewItemTimer = new Timer(NewItemTimerCallback, null, NewItemDelay, Timeout.Infinite);
- }
- else
- {
- NewItemTimer.Change(NewItemDelay, Timeout.Infinite);
- }
- }
- }
- }
-
- /// <summary>
- /// Called when the new item timer expires
- /// </summary>
- /// <param name="state">The state.</param>
- private void NewItemTimerCallback(object state)
- {
- List<BaseItem> newItems;
-
- // Lock the list and release all resources
- lock (_newlyAddedItems)
- {
- newItems = _newlyAddedItems.ToList();
- _newlyAddedItems.Clear();
-
- NewItemTimer.Dispose();
- NewItemTimer = null;
- }
-
- // Show the notification
- if (newItems.Count == 1)
- {
- Application.Current.Dispatcher.InvokeAsync(() =>
- {
- var window = (MainWindow)Application.Current.MainWindow;
-
- window.Dispatcher.InvokeAsync(() => window.MbTaskbarIcon.ShowCustomBalloon(new ItemUpdateNotification(_logger)
- {
- DataContext = newItems[0]
-
- }, PopupAnimation.Slide, 6000));
- });
- }
- else if (newItems.Count > 1)
- {
- Application.Current.Dispatcher.InvokeAsync(() =>
- {
- var window = (MainWindow)Application.Current.MainWindow;
-
- window.Dispatcher.InvokeAsync(() => window.MbTaskbarIcon.ShowCustomBalloon(new MultiItemUpdateNotification(_logger)
- {
- DataContext = newItems
-
- }, PopupAnimation.Slide, 6000));
- });
- }
- }
-
- /// <summary>
- /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- /// </summary>
- public void Dispose()
- {
- _libraryManager.LibraryChanged -= libraryManager_LibraryChanged;
- }
- }
-}