2013-09-21 01:04:14 +00:00
|
|
|
|
using MediaBrowser.Common.Events;
|
|
|
|
|
using MediaBrowser.Controller;
|
2013-03-07 05:34:00 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2013-02-27 20:25:45 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-02-21 21:06:23 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-05-18 22:07:59 +00:00
|
|
|
|
using MediaBrowser.ServerApplication.Splash;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.ServerApplication
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for App.xaml
|
|
|
|
|
/// </summary>
|
2013-09-21 01:04:14 +00:00
|
|
|
|
public partial class App : Application
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-02-22 01:26:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the logger.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The logger.</value>
|
2013-09-21 01:04:14 +00:00
|
|
|
|
private readonly ILogger _logger;
|
2013-02-22 01:26:35 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2013-02-24 21:53:54 +00:00
|
|
|
|
/// Gets or sets the composition root.
|
2013-02-22 01:26:35 +00:00
|
|
|
|
/// </summary>
|
2013-02-24 21:53:54 +00:00
|
|
|
|
/// <value>The composition root.</value>
|
2013-09-21 01:04:14 +00:00
|
|
|
|
private readonly ApplicationHost _appHost;
|
|
|
|
|
|
|
|
|
|
public event EventHandler AppStarted;
|
|
|
|
|
|
|
|
|
|
public bool IsRunningAsService { get; private set; }
|
2013-09-20 17:32:10 +00:00
|
|
|
|
|
2013-02-21 21:06:23 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="App" /> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logger">The logger.</param>
|
2013-09-21 01:04:14 +00:00
|
|
|
|
public App(ApplicationHost appHost, ILogger logger, bool isRunningAsService)
|
2013-02-21 21:06:23 +00:00
|
|
|
|
{
|
2013-09-21 01:04:14 +00:00
|
|
|
|
_appHost = appHost;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
IsRunningAsService = isRunningAsService;
|
2013-02-21 21:06:23 +00:00
|
|
|
|
|
2013-09-21 01:04:14 +00:00
|
|
|
|
InitializeComponent();
|
2013-09-20 17:32:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the name of the uninstaller file.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The name of the uninstaller file.</value>
|
2013-02-22 01:26:35 +00:00
|
|
|
|
protected string UninstallerFileName
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
get { return "MediaBrowser.Server.Uninstall.exe"; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-20 17:32:10 +00:00
|
|
|
|
public void OnUnhandledException(Exception ex)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-09-20 17:32:10 +00:00
|
|
|
|
MessageBox.Show("Unhandled exception: " + ex.Message);
|
2013-02-22 01:26:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-20 17:32:10 +00:00
|
|
|
|
protected override void OnStartup(StartupEventArgs e)
|
2013-02-22 01:26:35 +00:00
|
|
|
|
{
|
2013-09-20 17:32:10 +00:00
|
|
|
|
base.OnStartup(e);
|
2013-02-22 01:26:35 +00:00
|
|
|
|
|
2013-09-20 17:32:10 +00:00
|
|
|
|
LoadApplication();
|
2013-02-22 01:26:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loads the kernel.
|
|
|
|
|
/// </summary>
|
2013-09-20 17:32:10 +00:00
|
|
|
|
protected async void LoadApplication()
|
2013-02-22 01:26:35 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-12-13 15:48:35 +00:00
|
|
|
|
var initProgress = new Progress<double>();
|
|
|
|
|
|
2013-09-21 01:04:14 +00:00
|
|
|
|
if (!IsRunningAsService)
|
|
|
|
|
{
|
2013-12-13 15:48:35 +00:00
|
|
|
|
ShowSplashWindow(initProgress);
|
2013-09-21 01:04:14 +00:00
|
|
|
|
}
|
2013-05-18 22:07:59 +00:00
|
|
|
|
|
2013-12-13 15:48:35 +00:00
|
|
|
|
await _appHost.Init(initProgress);
|
2013-09-20 17:32:10 +00:00
|
|
|
|
|
2013-09-30 22:18:44 +00:00
|
|
|
|
var task = _appHost.RunStartupTasks();
|
|
|
|
|
|
2013-09-21 01:04:14 +00:00
|
|
|
|
if (!IsRunningAsService)
|
|
|
|
|
{
|
|
|
|
|
HideSplashWindow();
|
|
|
|
|
}
|
2013-03-08 05:08:27 +00:00
|
|
|
|
|
2013-09-21 01:04:14 +00:00
|
|
|
|
if (!IsRunningAsService)
|
|
|
|
|
{
|
|
|
|
|
ShowMainWindow();
|
|
|
|
|
}
|
2013-05-18 22:07:59 +00:00
|
|
|
|
|
2013-09-21 01:04:14 +00:00
|
|
|
|
EventHelper.FireEventIfNotNull(AppStarted, this, EventArgs.Empty, _logger);
|
2013-03-08 05:08:27 +00:00
|
|
|
|
|
2013-09-25 18:05:21 +00:00
|
|
|
|
await task;
|
2013-02-22 01:26:35 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2013-09-21 01:04:14 +00:00
|
|
|
|
_logger.ErrorException("Error launching application", ex);
|
2013-02-22 01:26:35 +00:00
|
|
|
|
|
|
|
|
|
MessageBox.Show("There was an error launching Media Browser: " + ex.Message);
|
|
|
|
|
|
|
|
|
|
// Shutdown the app with an error code
|
|
|
|
|
Shutdown(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-21 01:04:14 +00:00
|
|
|
|
private MainWindow _mainWindow;
|
|
|
|
|
private void ShowMainWindow()
|
2013-09-20 17:32:10 +00:00
|
|
|
|
{
|
2013-09-21 01:04:14 +00:00
|
|
|
|
var host = _appHost;
|
|
|
|
|
|
|
|
|
|
var win = new MainWindow(host.LogManager, host,
|
|
|
|
|
host.ServerConfigurationManager, host.UserManager,
|
|
|
|
|
host.LibraryManager, host.JsonSerializer,
|
|
|
|
|
host.DisplayPreferencesRepository);
|
|
|
|
|
|
|
|
|
|
win.Show();
|
|
|
|
|
|
|
|
|
|
_mainWindow = win;
|
2013-09-20 17:32:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-21 01:04:14 +00:00
|
|
|
|
private void HideMainWindow()
|
2013-02-22 01:26:35 +00:00
|
|
|
|
{
|
2013-09-21 01:04:14 +00:00
|
|
|
|
if (_mainWindow != null)
|
|
|
|
|
{
|
|
|
|
|
_mainWindow.Hide();
|
|
|
|
|
_mainWindow = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-22 01:26:35 +00:00
|
|
|
|
|
2013-09-21 01:04:14 +00:00
|
|
|
|
private SplashWindow _splashWindow;
|
2013-12-13 15:48:35 +00:00
|
|
|
|
private void ShowSplashWindow(Progress<double> progress)
|
2013-09-21 01:04:14 +00:00
|
|
|
|
{
|
2013-12-13 15:48:35 +00:00
|
|
|
|
var win = new SplashWindow(_appHost.ApplicationVersion, progress);
|
2013-09-21 01:04:14 +00:00
|
|
|
|
win.Show();
|
2013-02-22 01:26:35 +00:00
|
|
|
|
|
2013-09-21 01:04:14 +00:00
|
|
|
|
_splashWindow = win;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HideSplashWindow()
|
|
|
|
|
{
|
|
|
|
|
if (_splashWindow != null)
|
2013-04-23 14:53:43 +00:00
|
|
|
|
{
|
2013-09-21 01:04:14 +00:00
|
|
|
|
_splashWindow.Hide();
|
|
|
|
|
_splashWindow = null;
|
2013-04-23 14:53:43 +00:00
|
|
|
|
}
|
2013-02-22 01:26:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-21 01:04:14 +00:00
|
|
|
|
public void ShutdownApplication()
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(Shutdown);
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|