2012-08-19 22:47:02 +00:00
|
|
|
|
using System;
|
2012-08-25 21:08:27 +00:00
|
|
|
|
using System.IO;
|
2012-08-19 22:47:02 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
2012-08-25 21:08:27 +00:00
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
2012-08-19 22:47:02 +00:00
|
|
|
|
using MediaBrowser.Common.Kernel;
|
|
|
|
|
using MediaBrowser.Common.Logging;
|
|
|
|
|
using MediaBrowser.Model.Progress;
|
2012-08-25 21:08:27 +00:00
|
|
|
|
using System.Reflection;
|
2012-08-19 22:47:02 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Common.UI
|
|
|
|
|
{
|
2012-08-20 00:15:09 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Serves as a base Application class for both the UI and Server apps.
|
|
|
|
|
/// </summary>
|
2012-08-19 22:47:02 +00:00
|
|
|
|
public abstract class BaseApplication : Application
|
|
|
|
|
{
|
|
|
|
|
private IKernel Kernel { get; set; }
|
|
|
|
|
|
|
|
|
|
protected abstract IKernel InstantiateKernel();
|
|
|
|
|
protected abstract Window InstantiateMainWindow();
|
|
|
|
|
|
2012-08-22 02:50:59 +00:00
|
|
|
|
protected override void OnStartup(StartupEventArgs e)
|
2012-08-19 22:47:02 +00:00
|
|
|
|
{
|
2012-08-19 22:50:54 +00:00
|
|
|
|
// Without this the app will shutdown after the splash screen closes
|
2012-08-19 22:47:02 +00:00
|
|
|
|
this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
|
|
|
|
|
|
2012-08-22 02:50:59 +00:00
|
|
|
|
LoadKernel();
|
2012-08-19 22:47:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 02:50:59 +00:00
|
|
|
|
private async void LoadKernel()
|
2012-08-19 22:47:02 +00:00
|
|
|
|
{
|
|
|
|
|
Kernel = InstantiateKernel();
|
|
|
|
|
|
|
|
|
|
Progress<TaskProgress> progress = new Progress<TaskProgress>();
|
|
|
|
|
Splash splash = new Splash(progress);
|
|
|
|
|
|
|
|
|
|
splash.Show();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DateTime now = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
await Kernel.Init(progress);
|
|
|
|
|
|
2012-08-22 02:50:59 +00:00
|
|
|
|
Logger.LogInfo("Kernel.Init completed in {0} seconds.", (DateTime.Now - now).TotalSeconds);
|
2012-08-19 22:47:02 +00:00
|
|
|
|
splash.Close();
|
|
|
|
|
|
|
|
|
|
this.ShutdownMode = System.Windows.ShutdownMode.OnLastWindowClose;
|
|
|
|
|
InstantiateMainWindow().ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2012-08-23 05:45:26 +00:00
|
|
|
|
if (Logger.LoggerInstance != null)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogException(ex);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 22:47:02 +00:00
|
|
|
|
MessageBox.Show("There was an error launching Media Browser: " + ex.Message);
|
|
|
|
|
splash.Close();
|
2012-08-19 22:50:54 +00:00
|
|
|
|
|
|
|
|
|
// Shutdown the app with an error code
|
2012-08-19 22:47:02 +00:00
|
|
|
|
Shutdown(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnExit(ExitEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnExit(e);
|
|
|
|
|
|
|
|
|
|
Kernel.Dispose();
|
|
|
|
|
}
|
2012-08-25 21:08:27 +00:00
|
|
|
|
|
|
|
|
|
public BitmapImage GetLogoImage()
|
|
|
|
|
{
|
|
|
|
|
BitmapImage bitmap = new BitmapImage();
|
|
|
|
|
|
|
|
|
|
bitmap.CacheOption = BitmapCacheOption.Default;
|
|
|
|
|
|
|
|
|
|
bitmap.BeginInit();
|
|
|
|
|
bitmap.StreamSource = Assembly.GetExecutingAssembly().GetManifestResourceStream("MediaBrowser.Common.Resources.mblogo.png");
|
|
|
|
|
bitmap.EndInit();
|
|
|
|
|
|
|
|
|
|
return bitmap;
|
|
|
|
|
}
|
2012-08-19 22:47:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|