using MediaBrowser.Common.IO; using MediaBrowser.Common.Kernel; using MediaBrowser.Common.UI; using MediaBrowser.Controller; using MediaBrowser.IsoMounter; using MediaBrowser.Server.Uninstall; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; 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() { RunApplication("MediaBrowserServer"); } /// /// Gets the instance. /// /// The instance. public static App Instance { get { return Current as App; } } /// /// 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"; } } /// /// Instantiates the iso manager. /// /// The kernel. /// IIsoManager. protected override IIsoManager InstantiateIsoManager(IKernel kernel) { return new IsoManager(kernel); } /// /// 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(); } /// /// Instantiates the main window. /// /// Window. protected override Window InstantiateMainWindow() { return new MainWindow(); } } }