created entry point classes for the startup wizard and new item notifications

This commit is contained in:
LukePulverenti 2013-03-03 00:20:14 -05:00
parent 1ffc19a9a0
commit f26a3e3c61
7 changed files with 207 additions and 142 deletions

View File

@ -800,7 +800,7 @@ namespace MediaBrowser.Api.UserLibrary
return userdata.LastPlayedDate.Value;
}
return DateTime.MaxValue;
return DateTime.MinValue;
}
}
}

View File

@ -40,20 +40,6 @@ namespace MediaBrowser.Common.Kernel
}
#endregion
#region ReloadCompleted Event
/// <summary>
/// Fires whenever the kernel completes reloading
/// </summary>
public event EventHandler<EventArgs> ReloadCompleted;
/// <summary>
/// Called when [reload completed].
/// </summary>
private void OnReloadCompleted()
{
EventHelper.QueueEventIfNotNull(ReloadCompleted, this, EventArgs.Empty, Logger);
}
#endregion
#region ApplicationUpdated Event
/// <summary>
/// Occurs when [application updated].
@ -206,9 +192,7 @@ namespace MediaBrowser.Common.Kernel
{
ReloadInternal();
OnReloadCompleted();
Logger.Info("Kernel.Reload Complete");
Logger.Info("Kernel.Init Complete");
}
/// <summary>

View File

@ -89,11 +89,6 @@ namespace MediaBrowser.Common.Kernel
/// <value>The plug-in security manager.</value>
ISecurityManager SecurityManager { get; set; }
/// <summary>
/// Occurs when [reload completed].
/// </summary>
event EventHandler<EventArgs> ReloadCompleted;
/// <summary>
/// Occurs when [configuration updated].
/// </summary>

View File

@ -1,19 +1,13 @@
using MediaBrowser.Common.Kernel;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using MediaBrowser.ServerApplication.Controls;
using MediaBrowser.ServerApplication.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Threading;
namespace MediaBrowser.ServerApplication
@ -23,23 +17,6 @@ namespace MediaBrowser.ServerApplication
/// </summary>
public partial class MainWindow : Window, INotifyPropertyChanged
{
/// <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 _logger
/// </summary>
@ -54,8 +31,6 @@ namespace MediaBrowser.ServerApplication
/// The _log manager
/// </summary>
private readonly ILogManager _logManager;
private readonly ILibraryManager _libraryManager;
/// <summary>
/// Initializes a new instance of the <see cref="MainWindow" /> class.
@ -64,7 +39,7 @@ namespace MediaBrowser.ServerApplication
/// <param name="logger">The logger.</param>
/// <param name="appHost">The app host.</param>
/// <exception cref="System.ArgumentNullException">logger</exception>
public MainWindow(ILogManager logManager, IApplicationHost appHost, ILibraryManager libraryManager)
public MainWindow(ILogManager logManager, IApplicationHost appHost)
{
if (logManager == null)
{
@ -74,7 +49,6 @@ namespace MediaBrowser.ServerApplication
_logger = logManager.GetLogger("MainWindow");
_appHost = appHost;
_logManager = logManager;
_libraryManager = libraryManager;
InitializeComponent();
@ -92,7 +66,6 @@ namespace MediaBrowser.ServerApplication
Instance_ConfigurationUpdated(null, EventArgs.Empty);
Kernel.Instance.ReloadCompleted += KernelReloadCompleted;
_logManager.LoggerLoaded += LoadLogWindow;
Kernel.Instance.ConfigurationUpdated += Instance_ConfigurationUpdated;
}
@ -123,71 +96,6 @@ namespace MediaBrowser.ServerApplication
});
}
/// <summary>
/// Handles the LibraryChanged event of the Instance 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 Instance_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)
{
Dispatcher.InvokeAsync(() => MbTaskbarIcon.ShowCustomBalloon(new ItemUpdateNotification(_logger)
{
DataContext = newItems[0]
}, PopupAnimation.Slide, 6000));
}
else if (newItems.Count > 1)
{
Dispatcher.InvokeAsync(() => MbTaskbarIcon.ShowCustomBalloon(new MultiItemUpdateNotification(_logger)
{
DataContext = newItems
}, PopupAnimation.Slide, 6000));
}
}
/// <summary>
/// Loads the log window.
/// </summary>
@ -227,32 +135,6 @@ namespace MediaBrowser.ServerApplication
});
}
/// <summary>
/// Kernels the reload completed.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
void KernelReloadCompleted(object sender, EventArgs e)
{
_libraryManager.LibraryChanged -= Instance_LibraryChanged;
_libraryManager.LibraryChanged += Instance_LibraryChanged;
if (_appHost.IsFirstRun)
{
LaunchStartupWizard();
}
}
/// <summary>
/// Launches the startup wizard.
/// </summary>
private void LaunchStartupWizard()
{
var user = _appHost.Resolve<IUserManager>().Users.FirstOrDefault(u => u.Configuration.IsAdministrator);
App.OpenDashboardPage("wizardStart.html", user);
}
/// <summary>
/// Handles the Click event of the cmdApiDocs control.
/// </summary>

View File

@ -158,6 +158,8 @@
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Compile Include="NewItemNotifier.cs" />
<Compile Include="StartupWizard.cs" />
<Compile Include="WebSocketEvents.cs" />
<Page Include="App.xaml">
<Generator>MSBuild:Compile</Generator>

View File

@ -0,0 +1,141 @@
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)
{
var window = (MainWindow) App.Current.MainWindow;
window.Dispatcher.InvokeAsync(() => window.MbTaskbarIcon.ShowCustomBalloon(new ItemUpdateNotification(_logger)
{
DataContext = newItems[0]
}, PopupAnimation.Slide, 6000));
}
else if (newItems.Count > 1)
{
var window = (MainWindow)App.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;
}
}
}

View File

@ -0,0 +1,61 @@
using MediaBrowser.Common.Kernel;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Plugins;
using System.Linq;
namespace MediaBrowser.ServerApplication
{
/// <summary>
/// Class StartupWizard
/// </summary>
public class StartupWizard : IServerEntryPoint
{
/// <summary>
/// The _app host
/// </summary>
private readonly IApplicationHost _appHost;
/// <summary>
/// The _user manager
/// </summary>
private readonly IUserManager _userManager;
/// <summary>
/// Initializes a new instance of the <see cref="StartupWizard" /> class.
/// </summary>
/// <param name="appHost">The app host.</param>
/// <param name="userManager">The user manager.</param>
public StartupWizard(IApplicationHost appHost, IUserManager userManager)
{
_appHost = appHost;
_userManager = userManager;
}
/// <summary>
/// Runs this instance.
/// </summary>
public void Run()
{
if (_appHost.IsFirstRun)
{
LaunchStartupWizard();
}
}
/// <summary>
/// Launches the startup wizard.
/// </summary>
private void LaunchStartupWizard()
{
var user = _userManager.Users.FirstOrDefault(u => u.Configuration.IsAdministrator);
App.OpenDashboardPage("wizardStart.html", user);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
}
}
}