2
0

App.xaml.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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.Server.Uninstall;
  7. using MediaBrowser.ServerApplication.Implementations;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Diagnostics;
  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. /// Called when [second instance launched].
  73. /// </summary>
  74. /// <param name="args">The args.</param>
  75. protected override void OnSecondInstanceLaunched(IList<string> args)
  76. {
  77. base.OnSecondInstanceLaunched(args);
  78. OpenDashboard();
  79. InitializeComponent();
  80. }
  81. /// <summary>
  82. /// Opens the dashboard.
  83. /// </summary>
  84. public static void OpenDashboard()
  85. {
  86. OpenDashboardPage("dashboard.html");
  87. }
  88. /// <summary>
  89. /// Opens the dashboard page.
  90. /// </summary>
  91. /// <param name="page">The page.</param>
  92. public static void OpenDashboardPage(string page)
  93. {
  94. var url = "http://localhost:" + Controller.Kernel.Instance.Configuration.HttpServerPortNumber + "/" +
  95. Controller.Kernel.Instance.WebApplicationName + "/dashboard/" + page;
  96. url = AddAutoLoginToDashboardUrl(url);
  97. OpenUrl(url);
  98. }
  99. /// <summary>
  100. /// Adds the auto login to dashboard URL.
  101. /// </summary>
  102. /// <param name="url">The URL.</param>
  103. /// <returns>System.String.</returns>
  104. public static string AddAutoLoginToDashboardUrl(string url)
  105. {
  106. var user = Controller.Kernel.Instance.Users.FirstOrDefault(u => u.Configuration.IsAdministrator);
  107. if (user != null)
  108. {
  109. if (url.IndexOf('?') == -1)
  110. {
  111. url += "?u=" + user.Id;
  112. }
  113. else
  114. {
  115. url += "&u=" + user.Id;
  116. }
  117. }
  118. return url;
  119. }
  120. /// <summary>
  121. /// Opens the URL.
  122. /// </summary>
  123. /// <param name="url">The URL.</param>
  124. public static void OpenUrl(string url)
  125. {
  126. var process = new Process
  127. {
  128. StartInfo = new ProcessStartInfo
  129. {
  130. FileName = url
  131. },
  132. EnableRaisingEvents = true
  133. };
  134. process.Exited += ProcessExited;
  135. process.Start();
  136. }
  137. /// <summary>
  138. /// Processes the exited.
  139. /// </summary>
  140. /// <param name="sender">The sender.</param>
  141. /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
  142. static void ProcessExited(object sender, EventArgs e)
  143. {
  144. ((Process)sender).Dispose();
  145. }
  146. /// <summary>
  147. /// Instantiates the kernel.
  148. /// </summary>
  149. /// <returns>IKernel.</returns>
  150. protected override IKernel InstantiateKernel()
  151. {
  152. return new Kernel(new PismoIsoManager(LogManager.GetLogger("PismoIsoManager")), new DotNetZipClient(), new BdInfoExaminer());
  153. }
  154. /// <summary>
  155. /// Instantiates the main window.
  156. /// </summary>
  157. /// <returns>Window.</returns>
  158. protected override Window InstantiateMainWindow()
  159. {
  160. return new MainWindow();
  161. }
  162. }
  163. }