App.xaml.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using MediaBrowser.Common.Kernel;
  2. using MediaBrowser.Common.Logging;
  3. using MediaBrowser.Common.UI;
  4. using MediaBrowser.Controller;
  5. using MediaBrowser.IsoMounter;
  6. using MediaBrowser.Model.Logging;
  7. using MediaBrowser.Server.Uninstall;
  8. using MediaBrowser.ServerApplication.Implementations;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Diagnostics;
  12. using System.Linq;
  13. using System.Windows;
  14. namespace MediaBrowser.ServerApplication
  15. {
  16. /// <summary>
  17. /// Interaction logic for App.xaml
  18. /// </summary>
  19. public partial class App : BaseApplication, IApplication
  20. {
  21. /// <summary>
  22. /// Defines the entry point of the application.
  23. /// </summary>
  24. [STAThread]
  25. public static void Main()
  26. {
  27. var application = new App(LogManager.GetLogger("App"));
  28. application.InitializeComponent();
  29. application.Run();
  30. }
  31. /// <summary>
  32. /// Gets the instance.
  33. /// </summary>
  34. /// <value>The instance.</value>
  35. public static App Instance
  36. {
  37. get
  38. {
  39. return Current as App;
  40. }
  41. }
  42. /// <summary>
  43. /// Initializes a new instance of the <see cref="App" /> class.
  44. /// </summary>
  45. /// <param name="logger">The logger.</param>
  46. public App(ILogger logger)
  47. : base(logger)
  48. {
  49. }
  50. /// <summary>
  51. /// Gets the name of the product.
  52. /// </summary>
  53. /// <value>The name of the product.</value>
  54. protected override string ProductName
  55. {
  56. get { return Globals.ProductName; }
  57. }
  58. /// <summary>
  59. /// Gets the name of the publisher.
  60. /// </summary>
  61. /// <value>The name of the publisher.</value>
  62. protected override string PublisherName
  63. {
  64. get { return Globals.PublisherName; }
  65. }
  66. /// <summary>
  67. /// Gets the name of the suite.
  68. /// </summary>
  69. /// <value>The name of the suite.</value>
  70. protected override string SuiteName
  71. {
  72. get { return Globals.SuiteName; }
  73. }
  74. /// <summary>
  75. /// Gets the name of the uninstaller file.
  76. /// </summary>
  77. /// <value>The name of the uninstaller file.</value>
  78. protected override string UninstallerFileName
  79. {
  80. get { return "MediaBrowser.Server.Uninstall.exe"; }
  81. }
  82. /// <summary>
  83. /// Called when [second instance launched].
  84. /// </summary>
  85. /// <param name="args">The args.</param>
  86. protected override void OnSecondInstanceLaunched(IList<string> args)
  87. {
  88. base.OnSecondInstanceLaunched(args);
  89. OpenDashboard();
  90. InitializeComponent();
  91. }
  92. /// <summary>
  93. /// Opens the dashboard.
  94. /// </summary>
  95. public static void OpenDashboard()
  96. {
  97. OpenDashboardPage("dashboard.html");
  98. }
  99. /// <summary>
  100. /// Opens the dashboard page.
  101. /// </summary>
  102. /// <param name="page">The page.</param>
  103. public static void OpenDashboardPage(string page)
  104. {
  105. var url = "http://localhost:" + Controller.Kernel.Instance.Configuration.HttpServerPortNumber + "/" +
  106. Controller.Kernel.Instance.WebApplicationName + "/dashboard/" + page;
  107. url = AddAutoLoginToDashboardUrl(url);
  108. OpenUrl(url);
  109. }
  110. /// <summary>
  111. /// Adds the auto login to dashboard URL.
  112. /// </summary>
  113. /// <param name="url">The URL.</param>
  114. /// <returns>System.String.</returns>
  115. public static string AddAutoLoginToDashboardUrl(string url)
  116. {
  117. var user = Controller.Kernel.Instance.Users.FirstOrDefault(u => u.Configuration.IsAdministrator);
  118. if (user != null)
  119. {
  120. if (url.IndexOf('?') == -1)
  121. {
  122. url += "?u=" + user.Id;
  123. }
  124. else
  125. {
  126. url += "&u=" + user.Id;
  127. }
  128. }
  129. return url;
  130. }
  131. /// <summary>
  132. /// Opens the URL.
  133. /// </summary>
  134. /// <param name="url">The URL.</param>
  135. public static void OpenUrl(string url)
  136. {
  137. var process = new Process
  138. {
  139. StartInfo = new ProcessStartInfo
  140. {
  141. FileName = url
  142. },
  143. EnableRaisingEvents = true
  144. };
  145. process.Exited += ProcessExited;
  146. process.Start();
  147. }
  148. /// <summary>
  149. /// Processes the exited.
  150. /// </summary>
  151. /// <param name="sender">The sender.</param>
  152. /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
  153. static void ProcessExited(object sender, EventArgs e)
  154. {
  155. ((Process)sender).Dispose();
  156. }
  157. /// <summary>
  158. /// Instantiates the kernel.
  159. /// </summary>
  160. /// <returns>IKernel.</returns>
  161. protected override IKernel InstantiateKernel()
  162. {
  163. return new Kernel(new PismoIsoManager(Logger), new DotNetZipClient(), new BdInfoExaminer(), Logger);
  164. }
  165. /// <summary>
  166. /// Instantiates the main window.
  167. /// </summary>
  168. /// <returns>Window.</returns>
  169. protected override Window InstantiateMainWindow()
  170. {
  171. return new MainWindow(Logger);
  172. }
  173. }
  174. }