jellyfin/MediaBrowser.ServerApplication/App.xaml.cs

192 lines
5.7 KiB
C#
Raw Normal View History

using MediaBrowser.Controller;
2013-03-07 06:34:00 +01:00
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
2013-02-21 22:06:23 +01:00
using MediaBrowser.Model.Logging;
2013-05-19 00:07:59 +02:00
using MediaBrowser.ServerApplication.Splash;
2013-02-21 02:33:05 +01:00
using System;
using System.Diagnostics;
using System.Windows;
namespace MediaBrowser.ServerApplication
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application, IApplicationInterface
2013-02-21 02:33:05 +01:00
{
/// <summary>
/// Gets or sets the logger.
/// </summary>
/// <value>The logger.</value>
protected ILogger Logger { get; set; }
/// <summary>
2013-02-24 22:53:54 +01:00
/// Gets or sets the composition root.
/// </summary>
2013-02-24 22:53:54 +01:00
/// <value>The composition root.</value>
protected ApplicationHost CompositionRoot { get; set; }
2013-02-21 22:06:23 +01:00
/// <summary>
/// Initializes a new instance of the <see cref="App" /> class.
/// </summary>
/// <param name="logger">The logger.</param>
public App()
2013-02-21 22:06:23 +01:00
{
InitializeComponent();
2013-02-21 22:06:23 +01:00
}
public bool IsBackgroundService
{
get { return false; }
}
2013-02-21 02:33:05 +01:00
/// <summary>
/// Gets the name of the uninstaller file.
/// </summary>
/// <value>The name of the uninstaller file.</value>
protected string UninstallerFileName
2013-02-21 02:33:05 +01:00
{
get { return "MediaBrowser.Server.Uninstall.exe"; }
}
public void OnUnhandledException(Exception ex)
2013-02-21 02:33:05 +01:00
{
Logger.ErrorException("UnhandledException", ex);
MessageBox.Show("Unhandled exception: " + ex.Message);
}
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
LoadApplication();
}
/// <summary>
/// Loads the kernel.
/// </summary>
protected async void LoadApplication()
{
try
{
CompositionRoot = new ApplicationHost(this);
2013-03-04 06:43:06 +01:00
Logger = CompositionRoot.LogManager.GetLogger("App");
2013-05-19 00:07:59 +02:00
var splash = new SplashWindow(CompositionRoot.ApplicationVersion);
splash.Show();
2013-03-04 06:43:06 +01:00
await CompositionRoot.Init();
2013-05-19 00:07:59 +02:00
splash.Hide();
var task = CompositionRoot.RunStartupTasks();
2013-06-18 21:16:27 +02:00
new MainWindow(CompositionRoot.LogManager, CompositionRoot, CompositionRoot.ServerConfigurationManager, CompositionRoot.UserManager, CompositionRoot.LibraryManager, CompositionRoot.JsonSerializer, CompositionRoot.DisplayPreferencesRepository).Show();
2013-05-19 00:07:59 +02:00
await task.ConfigureAwait(false);
}
catch (Exception ex)
{
Logger.ErrorException("Error launching application", ex);
MessageBox.Show("There was an error launching Media Browser: " + ex.Message);
// Shutdown the app with an error code
Shutdown(1);
}
}
public void ShutdownApplication()
{
Dispatcher.Invoke(Shutdown);
}
/// <summary>
/// Raises the <see cref="E:System.Windows.Application.Exit" /> event.
/// </summary>
/// <param name="e">An <see cref="T:System.Windows.ExitEventArgs" /> that contains the event data.</param>
protected override void OnExit(ExitEventArgs e)
{
MainStartup.ReleaseMutex();
base.OnExit(e);
2013-04-23 16:53:43 +02:00
if (CompositionRoot != null)
{
CompositionRoot.Dispose();
}
}
2013-02-21 02:33:05 +01:00
/// <summary>
/// Opens the dashboard page.
/// </summary>
/// <param name="page">The page.</param>
2013-06-03 20:15:35 +02:00
/// <param name="loggedInUser">The logged in user.</param>
/// <param name="configurationManager">The configuration manager.</param>
/// <param name="appHost">The app host.</param>
public static void OpenDashboardPage(string page, User loggedInUser, IServerConfigurationManager configurationManager, IServerApplicationHost appHost)
2013-02-21 02:33:05 +01:00
{
2013-03-07 06:34:00 +01:00
var url = "http://localhost:" + configurationManager.Configuration.HttpServerPortNumber + "/" +
2013-06-03 20:15:35 +02:00
appHost.WebApplicationName + "/dashboard/" + page;
2013-02-21 02:33:05 +01:00
OpenUrl(url);
}
/// <summary>
/// Opens the URL.
/// </summary>
/// <param name="url">The URL.</param>
public static void OpenUrl(string url)
{
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = url
},
EnableRaisingEvents = true
};
process.Exited += ProcessExited;
2013-07-05 15:47:10 +02:00
try
{
process.Start();
}
catch (Exception ex)
{
MessageBox.Show("There was an error launching your web browser. Please check your defualt browser settings.");
}
2013-02-21 02:33:05 +01:00
}
/// <summary>
/// Processes the exited.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
static void ProcessExited(object sender, EventArgs e)
{
((Process)sender).Dispose();
}
/// <summary>
/// Restarts this instance.
/// </summary>
/// <exception cref="System.NotImplementedException"></exception>
public void RestartApplication()
{
Dispatcher.Invoke(MainStartup.ReleaseMutex);
CompositionRoot.Dispose();
System.Windows.Forms.Application.Restart();
Dispatcher.Invoke(Shutdown);
}
2013-02-21 02:33:05 +01:00
}
}