App.xaml.cs 5.3 KB

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