diff options
| author | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-08-19 18:47:02 -0400 |
|---|---|---|
| committer | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-08-19 18:47:02 -0400 |
| commit | d54c6d8bf63c13c0b47f76fd9f40fec614fbd689 (patch) | |
| tree | 2932e9f064d06388831e6c6fb29089eedd543b64 | |
| parent | 3586c54e90811d106631ac429d126c0414889b64 (diff) | |
Created a BaseApplication class in common
| -rw-r--r-- | MediaBrowser.Common/Kernel/BaseKernel.cs | 8 | ||||
| -rw-r--r-- | MediaBrowser.Common/MediaBrowser.Common.csproj | 1 | ||||
| -rw-r--r-- | MediaBrowser.Common/UI/BaseApplication.cs | 62 | ||||
| -rw-r--r-- | MediaBrowser.ServerApplication/App.xaml | 7 | ||||
| -rw-r--r-- | MediaBrowser.ServerApplication/App.xaml.cs | 59 |
5 files changed, 86 insertions, 51 deletions
diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index 22ecc3315..15ab687f3 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -18,7 +18,7 @@ namespace MediaBrowser.Common.Kernel /// <summary>
/// Represents a shared base kernel for both the UI and server apps
/// </summary>
- public abstract class BaseKernel<TConfigurationType, TApplicationPathsType> : IDisposable
+ public abstract class BaseKernel<TConfigurationType, TApplicationPathsType> : IDisposable, IKernel
where TConfigurationType : BaseApplicationConfiguration, new()
where TApplicationPathsType : BaseApplicationPaths, new()
{
@@ -264,4 +264,10 @@ namespace MediaBrowser.Common.Kernel }
}
}
+
+ public interface IKernel
+ {
+ Task Init(IProgress<TaskProgress> progress);
+ void Dispose();
+ }
}
diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index bd5e8b733..57c817fc2 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -89,6 +89,7 @@ <Compile Include="Plugins\BasePlugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Serialization\XmlSerializer.cs" />
+ <Compile Include="UI\BaseApplication.cs" />
<Compile Include="UI\Splash.xaml.cs">
<DependentUpon>Splash.xaml</DependentUpon>
</Compile>
diff --git a/MediaBrowser.Common/UI/BaseApplication.cs b/MediaBrowser.Common/UI/BaseApplication.cs new file mode 100644 index 000000000..a6bc7f7e4 --- /dev/null +++ b/MediaBrowser.Common/UI/BaseApplication.cs @@ -0,0 +1,62 @@ +using System;
+using System.Threading.Tasks;
+using System.Windows;
+using MediaBrowser.Common.Kernel;
+using MediaBrowser.Common.Logging;
+using MediaBrowser.Model.Progress;
+
+namespace MediaBrowser.Common.UI
+{
+ public abstract class BaseApplication : Application
+ {
+ private IKernel Kernel { get; set; }
+
+ protected abstract IKernel InstantiateKernel();
+ protected abstract Window InstantiateMainWindow();
+
+ protected async override void OnStartup(StartupEventArgs e)
+ {
+ this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
+
+ await LoadKernel();
+ }
+
+ private async Task LoadKernel()
+ {
+ Kernel = InstantiateKernel();
+
+ Progress<TaskProgress> progress = new Progress<TaskProgress>();
+ Splash splash = new Splash(progress);
+
+ splash.Show();
+
+ try
+ {
+ DateTime now = DateTime.Now;
+
+ await Kernel.Init(progress);
+
+ double seconds = (DateTime.Now - now).TotalSeconds;
+
+ Logger.LogInfo("Kernel.Init completed in {0} seconds.", seconds);
+ splash.Close();
+
+ this.ShutdownMode = System.Windows.ShutdownMode.OnLastWindowClose;
+ InstantiateMainWindow().ShowDialog();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("There was an error launching Media Browser: " + ex.Message);
+ splash.Close();
+ Shutdown(1);
+ }
+ }
+
+ protected override void OnExit(ExitEventArgs e)
+ {
+ base.OnExit(e);
+
+ Kernel.Dispose();
+ }
+ }
+}
diff --git a/MediaBrowser.ServerApplication/App.xaml b/MediaBrowser.ServerApplication/App.xaml index 3792e5bac..6b7f6c38f 100644 --- a/MediaBrowser.ServerApplication/App.xaml +++ b/MediaBrowser.ServerApplication/App.xaml @@ -1,7 +1,8 @@ -<Application x:Class="MediaBrowser.ServerApplication.App"
+<z:BaseApplication x:Class="MediaBrowser.ServerApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:z="clr-namespace:MediaBrowser.Common.UI;assembly=MediaBrowser.Common">
<Application.Resources>
</Application.Resources>
-</Application>
+</z:BaseApplication>
diff --git a/MediaBrowser.ServerApplication/App.xaml.cs b/MediaBrowser.ServerApplication/App.xaml.cs index de8a1114e..db229905d 100644 --- a/MediaBrowser.ServerApplication/App.xaml.cs +++ b/MediaBrowser.ServerApplication/App.xaml.cs @@ -1,12 +1,10 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
-using System.Threading.Tasks;
using System.Windows;
-using MediaBrowser.Common.Logging;
+using MediaBrowser.Common.Kernel;
using MediaBrowser.Common.UI;
using MediaBrowser.Controller;
-using MediaBrowser.Model.Progress;
using Microsoft.Shell;
namespace MediaBrowser.ServerApplication
@@ -14,7 +12,7 @@ namespace MediaBrowser.ServerApplication /// <summary>
/// Interaction logic for App.xaml
/// </summary>
- public partial class App : Application, ISingleInstanceApp
+ public partial class App : BaseApplication, ISingleInstanceApp
{
private const string Unique = "MediaBrowser3";
@@ -32,42 +30,6 @@ namespace MediaBrowser.ServerApplication SingleInstance<App>.Cleanup();
}
}
-
- protected async override void OnStartup(StartupEventArgs e)
- {
- this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
-
- await LoadKernel();
- }
-
- private async Task LoadKernel()
- {
- Progress<TaskProgress> progress = new Progress<TaskProgress>();
- Splash splash = new Splash(progress);
-
- splash.Show();
-
- try
- {
- DateTime now = DateTime.Now;
-
- await new Kernel().Init(progress);
-
- double seconds = (DateTime.Now - now).TotalSeconds;
-
- Logger.LogInfo("Kernel.Init completed in {0} seconds.", seconds);
- splash.Close();
-
- this.ShutdownMode = System.Windows.ShutdownMode.OnLastWindowClose;
- new MainWindow().ShowDialog();
- }
- catch (Exception ex)
- {
- MessageBox.Show("There was an error launching Media Browser Server: " + ex.Message);
- splash.Close();
- Shutdown(1);
- }
- }
#region ISingleInstanceApp Members
public bool SignalExternalCommandLineArgs(IList<string> args)
@@ -78,18 +40,21 @@ namespace MediaBrowser.ServerApplication }
#endregion
- protected override void OnExit(ExitEventArgs e)
- {
- base.OnExit(e);
-
- Kernel.Instance.Dispose();
- }
-
public static void OpenDashboard()
{
using (Process process = Process.Start("http://localhost:" + Kernel.Instance.Configuration.HttpServerPortNumber + "/mediabrowser/dashboard/index.html"))
{
}
}
+
+ protected override IKernel InstantiateKernel()
+ {
+ return new Kernel();
+ }
+
+ protected override Window InstantiateMainWindow()
+ {
+ return new MainWindow();
+ }
}
}
|
