Created a BaseApplication class in common

This commit is contained in:
LukePulverenti Luke Pulverenti luke pulverenti
2012-08-19 18:47:02 -04:00
parent 3586c54e90
commit d54c6d8bf6
5 changed files with 86 additions and 51 deletions

View File

@@ -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();
}
}

View File

@@ -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>

View File

@@ -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();
}
}
}