ApplicationHost.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. using MediaBrowser.Api;
  2. using MediaBrowser.Common;
  3. using MediaBrowser.Common.Configuration;
  4. using MediaBrowser.Common.Constants;
  5. using MediaBrowser.Common.Extensions;
  6. using MediaBrowser.Common.Implementations;
  7. using MediaBrowser.Common.Implementations.ScheduledTasks;
  8. using MediaBrowser.Common.Implementations.Updates;
  9. using MediaBrowser.Common.IO;
  10. using MediaBrowser.Common.MediaInfo;
  11. using MediaBrowser.Common.Net;
  12. using MediaBrowser.Controller;
  13. using MediaBrowser.Controller.Configuration;
  14. using MediaBrowser.Controller.Drawing;
  15. using MediaBrowser.Controller.Entities;
  16. using MediaBrowser.Controller.IO;
  17. using MediaBrowser.Controller.Library;
  18. using MediaBrowser.Controller.Localization;
  19. using MediaBrowser.Controller.MediaInfo;
  20. using MediaBrowser.Controller.Notifications;
  21. using MediaBrowser.Controller.Persistence;
  22. using MediaBrowser.Controller.Plugins;
  23. using MediaBrowser.Controller.Providers;
  24. using MediaBrowser.Controller.Resolvers;
  25. using MediaBrowser.Controller.Session;
  26. using MediaBrowser.Controller.Sorting;
  27. using MediaBrowser.IsoMounter;
  28. using MediaBrowser.Model.IO;
  29. using MediaBrowser.Model.MediaInfo;
  30. using MediaBrowser.Model.System;
  31. using MediaBrowser.Model.Updates;
  32. using MediaBrowser.Providers;
  33. using MediaBrowser.Server.Implementations;
  34. using MediaBrowser.Server.Implementations.BdInfo;
  35. using MediaBrowser.Server.Implementations.Configuration;
  36. using MediaBrowser.Server.Implementations.HttpServer;
  37. using MediaBrowser.Server.Implementations.IO;
  38. using MediaBrowser.Server.Implementations.Library;
  39. using MediaBrowser.Server.Implementations.Localization;
  40. using MediaBrowser.Server.Implementations.MediaEncoder;
  41. using MediaBrowser.Server.Implementations.Persistence;
  42. using MediaBrowser.Server.Implementations.Providers;
  43. using MediaBrowser.Server.Implementations.ServerManager;
  44. using MediaBrowser.Server.Implementations.Session;
  45. using MediaBrowser.Server.Implementations.WebSocket;
  46. using MediaBrowser.ServerApplication.Implementations;
  47. using MediaBrowser.WebDashboard.Api;
  48. using System;
  49. using System.Collections.Generic;
  50. using System.Data.SQLite;
  51. using System.Diagnostics;
  52. using System.IO;
  53. using System.Linq;
  54. using System.Reflection;
  55. using System.Threading;
  56. using System.Threading.Tasks;
  57. namespace MediaBrowser.ServerApplication
  58. {
  59. /// <summary>
  60. /// Class CompositionRoot
  61. /// </summary>
  62. public class ApplicationHost : BaseApplicationHost<ServerApplicationPaths>, IServerApplicationHost
  63. {
  64. internal const int UdpServerPort = 7359;
  65. /// <summary>
  66. /// Gets the server kernel.
  67. /// </summary>
  68. /// <value>The server kernel.</value>
  69. protected Kernel ServerKernel { get; set; }
  70. /// <summary>
  71. /// Gets the server configuration manager.
  72. /// </summary>
  73. /// <value>The server configuration manager.</value>
  74. public IServerConfigurationManager ServerConfigurationManager
  75. {
  76. get { return (IServerConfigurationManager)ConfigurationManager; }
  77. }
  78. /// <summary>
  79. /// Gets the name of the log file prefix.
  80. /// </summary>
  81. /// <value>The name of the log file prefix.</value>
  82. protected override string LogFilePrefixName
  83. {
  84. get { return "server"; }
  85. }
  86. /// <summary>
  87. /// Gets the name of the web application that can be used for url building.
  88. /// All api urls will be of the form {protocol}://{host}:{port}/{appname}/...
  89. /// </summary>
  90. /// <value>The name of the web application.</value>
  91. public string WebApplicationName
  92. {
  93. get { return "mediabrowser"; }
  94. }
  95. /// <summary>
  96. /// Gets the HTTP server URL prefix.
  97. /// </summary>
  98. /// <value>The HTTP server URL prefix.</value>
  99. public string HttpServerUrlPrefix
  100. {
  101. get
  102. {
  103. return "http://+:" + ServerConfigurationManager.Configuration.HttpServerPortNumber + "/" + WebApplicationName + "/";
  104. }
  105. }
  106. /// <summary>
  107. /// Gets the configuration manager.
  108. /// </summary>
  109. /// <returns>IConfigurationManager.</returns>
  110. protected override IConfigurationManager GetConfigurationManager()
  111. {
  112. return new ServerConfigurationManager(ApplicationPaths, LogManager, XmlSerializer);
  113. }
  114. /// <summary>
  115. /// Gets or sets the server manager.
  116. /// </summary>
  117. /// <value>The server manager.</value>
  118. private IServerManager ServerManager { get; set; }
  119. /// <summary>
  120. /// Gets or sets the user manager.
  121. /// </summary>
  122. /// <value>The user manager.</value>
  123. public IUserManager UserManager { get; set; }
  124. /// <summary>
  125. /// Gets or sets the library manager.
  126. /// </summary>
  127. /// <value>The library manager.</value>
  128. internal ILibraryManager LibraryManager { get; set; }
  129. /// <summary>
  130. /// Gets or sets the directory watchers.
  131. /// </summary>
  132. /// <value>The directory watchers.</value>
  133. private IDirectoryWatchers DirectoryWatchers { get; set; }
  134. /// <summary>
  135. /// Gets or sets the provider manager.
  136. /// </summary>
  137. /// <value>The provider manager.</value>
  138. private IProviderManager ProviderManager { get; set; }
  139. /// <summary>
  140. /// Gets or sets the zip client.
  141. /// </summary>
  142. /// <value>The zip client.</value>
  143. private IZipClient ZipClient { get; set; }
  144. /// <summary>
  145. /// Gets or sets the HTTP server.
  146. /// </summary>
  147. /// <value>The HTTP server.</value>
  148. private IHttpServer HttpServer { get; set; }
  149. /// <summary>
  150. /// Gets or sets the media encoder.
  151. /// </summary>
  152. /// <value>The media encoder.</value>
  153. private IMediaEncoder MediaEncoder { get; set; }
  154. private ILocalizationManager LocalizationManager { get; set; }
  155. /// <summary>
  156. /// Gets or sets the user data repository.
  157. /// </summary>
  158. /// <value>The user data repository.</value>
  159. private IUserDataRepository UserDataRepository { get; set; }
  160. private IUserRepository UserRepository { get; set; }
  161. internal IDisplayPreferencesRepository DisplayPreferencesRepository { get; set; }
  162. private IItemRepository ItemRepository { get; set; }
  163. private INotificationsRepository NotificationsRepository { get; set; }
  164. /// <summary>
  165. /// The full path to our startmenu shortcut
  166. /// </summary>
  167. protected override string ProductShortcutPath
  168. {
  169. get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser 3", "Media Browser Server.lnk"); }
  170. }
  171. private Task<IHttpServer> _httpServerCreationTask;
  172. /// <summary>
  173. /// Runs the startup tasks.
  174. /// </summary>
  175. /// <returns>Task.</returns>
  176. public override async Task RunStartupTasks()
  177. {
  178. await base.RunStartupTasks().ConfigureAwait(false);
  179. DirectoryWatchers.Start();
  180. Logger.Info("Core startup complete");
  181. Parallel.ForEach(GetExports<IServerEntryPoint>(), entryPoint =>
  182. {
  183. try
  184. {
  185. entryPoint.Run();
  186. }
  187. catch (Exception ex)
  188. {
  189. Logger.ErrorException("Error in {0}", ex, entryPoint.GetType().Name);
  190. }
  191. });
  192. }
  193. /// <summary>
  194. /// Called when [logger loaded].
  195. /// </summary>
  196. protected override void OnLoggerLoaded()
  197. {
  198. base.OnLoggerLoaded();
  199. _httpServerCreationTask = Task.Run(() => ServerFactory.CreateServer(this, LogManager, "Media Browser", "dashboard/index.html"));
  200. }
  201. /// <summary>
  202. /// Registers resources that classes will depend on
  203. /// </summary>
  204. /// <returns>Task.</returns>
  205. protected override async Task RegisterResources()
  206. {
  207. ServerKernel = new Kernel();
  208. await base.RegisterResources().ConfigureAwait(false);
  209. RegisterSingleInstance<IHttpResultFactory>(new HttpResultFactory(LogManager));
  210. RegisterSingleInstance<IServerApplicationHost>(this);
  211. RegisterSingleInstance<IServerApplicationPaths>(ApplicationPaths);
  212. RegisterSingleInstance(ServerKernel);
  213. RegisterSingleInstance(ServerConfigurationManager);
  214. RegisterSingleInstance<IWebSocketServer>(() => new AlchemyServer(Logger));
  215. //RegisterSingleInstance<IIsoManager>(() => new PismoIsoManager(Logger));
  216. RegisterSingleInstance<IBlurayExaminer>(() => new BdInfoExaminer());
  217. ZipClient = new DotNetZipClient();
  218. RegisterSingleInstance(ZipClient);
  219. UserDataRepository = new SqliteUserDataRepository(ApplicationPaths, JsonSerializer, LogManager);
  220. RegisterSingleInstance(UserDataRepository);
  221. UserRepository = await GetUserRepository().ConfigureAwait(false);
  222. RegisterSingleInstance(UserRepository);
  223. DisplayPreferencesRepository = new SqliteDisplayPreferencesRepository(ApplicationPaths, JsonSerializer, LogManager);
  224. RegisterSingleInstance(DisplayPreferencesRepository);
  225. ItemRepository = new SqliteItemRepository(ApplicationPaths, JsonSerializer, LogManager);
  226. RegisterSingleInstance(ItemRepository);
  227. UserManager = new UserManager(Logger, ServerConfigurationManager, UserRepository);
  228. RegisterSingleInstance(UserManager);
  229. LibraryManager = new LibraryManager(Logger, TaskManager, UserManager, ServerConfigurationManager, UserDataRepository, () => DirectoryWatchers);
  230. RegisterSingleInstance(LibraryManager);
  231. DirectoryWatchers = new DirectoryWatchers(LogManager, TaskManager, LibraryManager, ServerConfigurationManager);
  232. RegisterSingleInstance(DirectoryWatchers);
  233. ProviderManager = new ProviderManager(HttpClient, ServerConfigurationManager, DirectoryWatchers, LogManager, LibraryManager);
  234. RegisterSingleInstance(ProviderManager);
  235. RegisterSingleInstance<ILibrarySearchEngine>(() => new LuceneSearchEngine(ApplicationPaths, LogManager, LibraryManager));
  236. MediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"), ZipClient, ApplicationPaths, JsonSerializer);
  237. RegisterSingleInstance(MediaEncoder);
  238. var clientConnectionManager = new SessionManager(UserDataRepository, ServerConfigurationManager, Logger, UserRepository);
  239. RegisterSingleInstance<ISessionManager>(clientConnectionManager);
  240. HttpServer = await _httpServerCreationTask.ConfigureAwait(false);
  241. RegisterSingleInstance(HttpServer, false);
  242. ServerManager = new ServerManager(this, JsonSerializer, Logger, ServerConfigurationManager);
  243. RegisterSingleInstance(ServerManager);
  244. LocalizationManager = new LocalizationManager(ServerConfigurationManager);
  245. RegisterSingleInstance(LocalizationManager);
  246. var displayPreferencesTask = Task.Run(async () => await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false));
  247. var itemsTask = Task.Run(async () => await ConfigureItemRepositories().ConfigureAwait(false));
  248. var userdataTask = Task.Run(async () => await ConfigureUserDataRepositories().ConfigureAwait(false));
  249. await ConfigureNotificationsRepository().ConfigureAwait(false);
  250. await Task.WhenAll(itemsTask, displayPreferencesTask, userdataTask).ConfigureAwait(false);
  251. SetKernelProperties();
  252. }
  253. /// <summary>
  254. /// Sets the kernel properties.
  255. /// </summary>
  256. private void SetKernelProperties()
  257. {
  258. ServerKernel.ImageManager = new ImageManager(LogManager.GetLogger("ImageManager"),
  259. ApplicationPaths, ItemRepository);
  260. Parallel.Invoke(
  261. () => ServerKernel.FFMpegManager = new FFMpegManager(ApplicationPaths, MediaEncoder, LibraryManager, Logger, ItemRepository),
  262. () => ServerKernel.ImageManager.ImageEnhancers = GetExports<IImageEnhancer>().OrderBy(e => e.Priority).ToArray(),
  263. () => LocalizedStrings.StringFiles = GetExports<LocalizedStringData>(),
  264. SetStaticProperties
  265. );
  266. }
  267. private async Task<IUserRepository> GetUserRepository()
  268. {
  269. var dbFile = Path.Combine(ApplicationPaths.DataPath, "users.db");
  270. var connection = await ConnectToDb(dbFile).ConfigureAwait(false);
  271. return new SqliteUserRepository(connection, ApplicationPaths, JsonSerializer, LogManager);
  272. }
  273. /// <summary>
  274. /// Configures the repositories.
  275. /// </summary>
  276. /// <returns>Task.</returns>
  277. private async Task ConfigureNotificationsRepository()
  278. {
  279. var dbFile = Path.Combine(ApplicationPaths.DataPath, "notifications.db");
  280. var connection = await ConnectToDb(dbFile).ConfigureAwait(false);
  281. var repo = new SqliteNotificationsRepository(connection, LogManager);
  282. repo.Initialize();
  283. NotificationsRepository = repo;
  284. RegisterSingleInstance(NotificationsRepository);
  285. }
  286. /// <summary>
  287. /// Configures the repositories.
  288. /// </summary>
  289. /// <returns>Task.</returns>
  290. private async Task ConfigureDisplayPreferencesRepositories()
  291. {
  292. await DisplayPreferencesRepository.Initialize().ConfigureAwait(false);
  293. }
  294. /// <summary>
  295. /// Configures the item repositories.
  296. /// </summary>
  297. /// <returns>Task.</returns>
  298. private async Task ConfigureItemRepositories()
  299. {
  300. await ItemRepository.Initialize().ConfigureAwait(false);
  301. ((LibraryManager)LibraryManager).ItemRepository = ItemRepository;
  302. }
  303. /// <summary>
  304. /// Configures the user data repositories.
  305. /// </summary>
  306. /// <returns>Task.</returns>
  307. private Task ConfigureUserDataRepositories()
  308. {
  309. return UserDataRepository.Initialize();
  310. }
  311. /// <summary>
  312. /// Connects to db.
  313. /// </summary>
  314. /// <param name="dbPath">The db path.</param>
  315. /// <returns>Task{IDbConnection}.</returns>
  316. /// <exception cref="System.ArgumentNullException">dbPath</exception>
  317. private static async Task<SQLiteConnection> ConnectToDb(string dbPath)
  318. {
  319. if (string.IsNullOrEmpty(dbPath))
  320. {
  321. throw new ArgumentNullException("dbPath");
  322. }
  323. var connectionstr = new SQLiteConnectionStringBuilder
  324. {
  325. PageSize = 4096,
  326. CacheSize = 4096,
  327. SyncMode = SynchronizationModes.Normal,
  328. DataSource = dbPath,
  329. JournalMode = SQLiteJournalModeEnum.Wal
  330. };
  331. var connection = new SQLiteConnection(connectionstr.ConnectionString);
  332. await connection.OpenAsync().ConfigureAwait(false);
  333. return connection;
  334. }
  335. /// <summary>
  336. /// Dirty hacks
  337. /// </summary>
  338. private void SetStaticProperties()
  339. {
  340. // For now there's no real way to inject these properly
  341. BaseItem.Logger = LogManager.GetLogger("BaseItem");
  342. BaseItem.ConfigurationManager = ServerConfigurationManager;
  343. BaseItem.LibraryManager = LibraryManager;
  344. BaseItem.ProviderManager = ProviderManager;
  345. BaseItem.LocalizationManager = LocalizationManager;
  346. BaseItem.ItemRepository = ItemRepository;
  347. User.XmlSerializer = XmlSerializer;
  348. User.UserManager = UserManager;
  349. LocalizedStrings.ApplicationPaths = ApplicationPaths;
  350. }
  351. /// <summary>
  352. /// Finds the parts.
  353. /// </summary>
  354. protected override void FindParts()
  355. {
  356. if (IsFirstRun)
  357. {
  358. RegisterServerWithAdministratorAccess();
  359. }
  360. base.FindParts();
  361. HttpServer.Init(GetExports<IRestfulService>(false));
  362. ServerManager.AddWebSocketListeners(GetExports<IWebSocketListener>(false));
  363. StartServer(true);
  364. LibraryManager.AddParts(GetExports<IResolverIgnoreRule>(),
  365. GetExports<IVirtualFolderCreator>(),
  366. GetExports<IItemResolver>(),
  367. GetExports<IIntroProvider>(),
  368. GetExports<IBaseItemComparer>(),
  369. GetExports<ILibraryPrescanTask>(),
  370. GetExports<ILibraryPostScanTask>(),
  371. GetExports<IMetadataSaver>());
  372. ProviderManager.AddParts(GetExports<BaseMetadataProvider>().ToArray());
  373. }
  374. /// <summary>
  375. /// Starts the server.
  376. /// </summary>
  377. /// <param name="retryOnFailure">if set to <c>true</c> [retry on failure].</param>
  378. private void StartServer(bool retryOnFailure)
  379. {
  380. try
  381. {
  382. ServerManager.Start();
  383. }
  384. catch
  385. {
  386. if (retryOnFailure)
  387. {
  388. RegisterServerWithAdministratorAccess();
  389. StartServer(false);
  390. }
  391. else
  392. {
  393. throw;
  394. }
  395. }
  396. }
  397. /// <summary>
  398. /// Called when [configuration updated].
  399. /// </summary>
  400. /// <param name="sender">The sender.</param>
  401. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  402. protected override void OnConfigurationUpdated(object sender, EventArgs e)
  403. {
  404. base.OnConfigurationUpdated(sender, e);
  405. if (!string.Equals(HttpServer.UrlPrefix, HttpServerUrlPrefix, StringComparison.OrdinalIgnoreCase))
  406. {
  407. NotifyPendingRestart();
  408. }
  409. else if (!ServerManager.SupportsNativeWebSocket && ServerManager.WebSocketPortNumber != ServerConfigurationManager.Configuration.LegacyWebSocketPortNumber)
  410. {
  411. NotifyPendingRestart();
  412. }
  413. }
  414. /// <summary>
  415. /// Restarts this instance.
  416. /// </summary>
  417. public override void Restart()
  418. {
  419. App.Instance.Restart();
  420. }
  421. /// <summary>
  422. /// Gets or sets a value indicating whether this instance can self update.
  423. /// </summary>
  424. /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
  425. public override bool CanSelfUpdate
  426. {
  427. get
  428. {
  429. #if DEBUG
  430. return false;
  431. #endif
  432. return ConfigurationManager.CommonConfiguration.EnableAutoUpdate;
  433. }
  434. }
  435. /// <summary>
  436. /// Gets the composable part assemblies.
  437. /// </summary>
  438. /// <returns>IEnumerable{Assembly}.</returns>
  439. protected override IEnumerable<Assembly> GetComposablePartAssemblies()
  440. {
  441. // Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that
  442. // This will prevent the .dll file from getting locked, and allow us to replace it when needed
  443. foreach (var pluginAssembly in Directory
  444. .EnumerateFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.TopDirectoryOnly)
  445. .Select(LoadAssembly).Where(a => a != null))
  446. {
  447. yield return pluginAssembly;
  448. }
  449. // Include composable parts in the Api assembly
  450. yield return typeof(ApiEntryPoint).Assembly;
  451. // Include composable parts in the Dashboard assembly
  452. yield return typeof(DashboardInfo).Assembly;
  453. // Include composable parts in the Model assembly
  454. yield return typeof(SystemInfo).Assembly;
  455. // Include composable parts in the Common assembly
  456. yield return typeof(IApplicationHost).Assembly;
  457. // Include composable parts in the Controller assembly
  458. yield return typeof(Kernel).Assembly;
  459. // Include composable parts in the Providers assembly
  460. yield return typeof(ImagesByNameProvider).Assembly;
  461. // Common implementations
  462. yield return typeof(TaskManager).Assembly;
  463. // Server implementations
  464. yield return typeof(ServerApplicationPaths).Assembly;
  465. // Include composable parts in the running assembly
  466. yield return GetType().Assembly;
  467. }
  468. private readonly string _systemId = Environment.MachineName.GetMD5().ToString();
  469. /// <summary>
  470. /// Gets the system status.
  471. /// </summary>
  472. /// <returns>SystemInfo.</returns>
  473. public virtual SystemInfo GetSystemInfo()
  474. {
  475. return new SystemInfo
  476. {
  477. HasPendingRestart = HasPendingRestart,
  478. Version = ApplicationVersion.ToString(),
  479. IsNetworkDeployed = CanSelfUpdate,
  480. WebSocketPortNumber = ServerManager.WebSocketPortNumber,
  481. SupportsNativeWebSocket = ServerManager.SupportsNativeWebSocket,
  482. FailedPluginAssemblies = FailedAssemblies.ToArray(),
  483. InProgressInstallations = InstallationManager.CurrentInstallations.Select(i => i.Item1).ToArray(),
  484. CompletedInstallations = InstallationManager.CompletedInstallations.ToArray(),
  485. Id = _systemId,
  486. ProgramDataPath = ApplicationPaths.ProgramDataPath
  487. };
  488. }
  489. /// <summary>
  490. /// Shuts down.
  491. /// </summary>
  492. public override void Shutdown()
  493. {
  494. App.Instance.Dispatcher.Invoke(App.Instance.Shutdown);
  495. }
  496. /// <summary>
  497. /// Registers the server with administrator access.
  498. /// </summary>
  499. private void RegisterServerWithAdministratorAccess()
  500. {
  501. Logger.Info("Requesting administrative access to authorize http server");
  502. // Create a temp file path to extract the bat file to
  503. var tmpFile = Path.Combine(ConfigurationManager.CommonApplicationPaths.TempDirectory, Guid.NewGuid() + ".bat");
  504. // Extract the bat file
  505. using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MediaBrowser.ServerApplication.RegisterServer.bat"))
  506. {
  507. using (var fileStream = File.Create(tmpFile))
  508. {
  509. stream.CopyTo(fileStream);
  510. }
  511. }
  512. var startInfo = new ProcessStartInfo
  513. {
  514. FileName = tmpFile,
  515. Arguments = string.Format("{0} {1} {2} {3}", ServerConfigurationManager.Configuration.HttpServerPortNumber,
  516. HttpServerUrlPrefix,
  517. UdpServerPort,
  518. ServerConfigurationManager.Configuration.LegacyWebSocketPortNumber),
  519. CreateNoWindow = true,
  520. WindowStyle = ProcessWindowStyle.Hidden,
  521. Verb = "runas",
  522. ErrorDialog = false
  523. };
  524. using (var process = Process.Start(startInfo))
  525. {
  526. process.WaitForExit();
  527. }
  528. }
  529. public override async Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress)
  530. {
  531. var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(CancellationToken.None).ConfigureAwait(false);
  532. var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, Constants.MbServerPkgName, ConfigurationManager.CommonConfiguration.SystemUpdateLevel);
  533. return version != null ? new CheckForUpdateResult { AvailableVersion = version.version, IsUpdateAvailable = version.version > ApplicationVersion, Package = version } :
  534. new CheckForUpdateResult { AvailableVersion = ApplicationVersion, IsUpdateAvailable = false };
  535. }
  536. }
  537. }