using MediaBrowser.Common.Kernel;
using MediaBrowser.Common.Logging;
using MediaBrowser.Common.UI;
using MediaBrowser.Controller;
using MediaBrowser.IsoMounter;
using MediaBrowser.Model.Logging;
using MediaBrowser.Server.Uninstall;
using MediaBrowser.ServerApplication.Implementations;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
namespace MediaBrowser.ServerApplication
{
///
/// Interaction logic for App.xaml
///
public partial class App : BaseApplication, IApplication
{
///
/// Defines the entry point of the application.
///
[STAThread]
public static void Main()
{
var application = new App(LogManager.GetLogger("App"));
application.InitializeComponent();
application.Run();
}
///
/// Gets the instance.
///
/// The instance.
public static App Instance
{
get
{
return Current as App;
}
}
///
/// Initializes a new instance of the class.
///
/// The logger.
public App(ILogger logger)
: base(logger)
{
}
///
/// Gets the name of the product.
///
/// The name of the product.
protected override string ProductName
{
get { return Globals.ProductName; }
}
///
/// Gets the name of the publisher.
///
/// The name of the publisher.
protected override string PublisherName
{
get { return Globals.PublisherName; }
}
///
/// Gets the name of the suite.
///
/// The name of the suite.
protected override string SuiteName
{
get { return Globals.SuiteName; }
}
///
/// Gets the name of the uninstaller file.
///
/// The name of the uninstaller file.
protected override string UninstallerFileName
{
get { return "MediaBrowser.Server.Uninstall.exe"; }
}
///
/// Called when [second instance launched].
///
/// The args.
protected override void OnSecondInstanceLaunched(IList args)
{
base.OnSecondInstanceLaunched(args);
OpenDashboard();
InitializeComponent();
}
///
/// Opens the dashboard.
///
public static void OpenDashboard()
{
OpenDashboardPage("dashboard.html");
}
///
/// Opens the dashboard page.
///
/// The page.
public static void OpenDashboardPage(string page)
{
var url = "http://localhost:" + Controller.Kernel.Instance.Configuration.HttpServerPortNumber + "/" +
Controller.Kernel.Instance.WebApplicationName + "/dashboard/" + page;
url = AddAutoLoginToDashboardUrl(url);
OpenUrl(url);
}
///
/// Adds the auto login to dashboard URL.
///
/// The URL.
/// System.String.
public static string AddAutoLoginToDashboardUrl(string url)
{
var user = Controller.Kernel.Instance.Users.FirstOrDefault(u => u.Configuration.IsAdministrator);
if (user != null)
{
if (url.IndexOf('?') == -1)
{
url += "?u=" + user.Id;
}
else
{
url += "&u=" + user.Id;
}
}
return url;
}
///
/// Opens the URL.
///
/// The URL.
public static void OpenUrl(string url)
{
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = url
},
EnableRaisingEvents = true
};
process.Exited += ProcessExited;
process.Start();
}
///
/// Processes the exited.
///
/// The sender.
/// The instance containing the event data.
static void ProcessExited(object sender, EventArgs e)
{
((Process)sender).Dispose();
}
///
/// Instantiates the kernel.
///
/// IKernel.
protected override IKernel InstantiateKernel()
{
return new Kernel(new PismoIsoManager(Logger), new DotNetZipClient(), new BdInfoExaminer(), Logger);
}
///
/// Instantiates the main window.
///
/// Window.
protected override Window InstantiateMainWindow()
{
return new MainWindow(Logger);
}
}
}