ApplicationHost.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  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 = new SqliteUserRepository(ApplicationPaths, JsonSerializer, LogManager);
  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);
  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. var userTask = Task.Run(async () => await ConfigureUserRepositories().ConfigureAwait(false));
  250. await ConfigureNotificationsRepository().ConfigureAwait(false);
  251. await Task.WhenAll(itemsTask, userTask, displayPreferencesTask, userdataTask).ConfigureAwait(false);
  252. SetKernelProperties();
  253. }
  254. /// <summary>
  255. /// Sets the kernel properties.
  256. /// </summary>
  257. private void SetKernelProperties()
  258. {
  259. ServerKernel.ImageManager = new ImageManager(LogManager.GetLogger("ImageManager"),
  260. ApplicationPaths, ItemRepository);
  261. Parallel.Invoke(
  262. () => ServerKernel.FFMpegManager = new FFMpegManager(ApplicationPaths, MediaEncoder, LibraryManager, Logger, ItemRepository),
  263. () => ServerKernel.ImageManager.ImageEnhancers = GetExports<IImageEnhancer>().OrderBy(e => e.Priority).ToArray(),
  264. () => LocalizedStrings.StringFiles = GetExports<LocalizedStringData>(),
  265. SetStaticProperties
  266. );
  267. }
  268. /// <summary>
  269. /// Configures the repositories.
  270. /// </summary>
  271. /// <returns>Task.</returns>
  272. private async Task ConfigureNotificationsRepository()
  273. {
  274. var dbFile = Path.Combine(ApplicationPaths.DataPath, "notifications.db");
  275. var connection = await ConnectToDb(dbFile).ConfigureAwait(false);
  276. var repo = new SqliteNotificationsRepository(connection, LogManager);
  277. repo.Initialize();
  278. NotificationsRepository = repo;
  279. RegisterSingleInstance(NotificationsRepository);
  280. }
  281. /// <summary>
  282. /// Configures the repositories.
  283. /// </summary>
  284. /// <returns>Task.</returns>
  285. private async Task ConfigureDisplayPreferencesRepositories()
  286. {
  287. await DisplayPreferencesRepository.Initialize().ConfigureAwait(false);
  288. }
  289. /// <summary>
  290. /// Configures the item repositories.
  291. /// </summary>
  292. /// <returns>Task.</returns>
  293. private async Task ConfigureItemRepositories()
  294. {
  295. await ItemRepository.Initialize().ConfigureAwait(false);
  296. ((LibraryManager)LibraryManager).ItemRepository = ItemRepository;
  297. }
  298. /// <summary>
  299. /// Configures the user data repositories.
  300. /// </summary>
  301. /// <returns>Task.</returns>
  302. private Task ConfigureUserDataRepositories()
  303. {
  304. return UserDataRepository.Initialize();
  305. }
  306. /// <summary>
  307. /// Configures the user repositories.
  308. /// </summary>
  309. /// <returns>Task.</returns>
  310. private async Task ConfigureUserRepositories()
  311. {
  312. await UserRepository.Initialize().ConfigureAwait(false);
  313. ((UserManager)UserManager).UserRepository = UserRepository;
  314. }
  315. /// <summary>
  316. /// Connects to db.
  317. /// </summary>
  318. /// <param name="dbPath">The db path.</param>
  319. /// <returns>Task{IDbConnection}.</returns>
  320. /// <exception cref="System.ArgumentNullException">dbPath</exception>
  321. private static async Task<SQLiteConnection> ConnectToDb(string dbPath)
  322. {
  323. if (string.IsNullOrEmpty(dbPath))
  324. {
  325. throw new ArgumentNullException("dbPath");
  326. }
  327. var connectionstr = new SQLiteConnectionStringBuilder
  328. {
  329. PageSize = 4096,
  330. CacheSize = 4096,
  331. SyncMode = SynchronizationModes.Normal,
  332. DataSource = dbPath,
  333. JournalMode = SQLiteJournalModeEnum.Wal
  334. };
  335. var connection = new SQLiteConnection(connectionstr.ConnectionString);
  336. await connection.OpenAsync().ConfigureAwait(false);
  337. return connection;
  338. }
  339. /// <summary>
  340. /// Dirty hacks
  341. /// </summary>
  342. private void SetStaticProperties()
  343. {
  344. // For now there's no real way to inject these properly
  345. BaseItem.Logger = LogManager.GetLogger("BaseItem");
  346. BaseItem.ConfigurationManager = ServerConfigurationManager;
  347. BaseItem.LibraryManager = LibraryManager;
  348. BaseItem.ProviderManager = ProviderManager;
  349. BaseItem.LocalizationManager = LocalizationManager;
  350. BaseItem.ItemRepository = ItemRepository;
  351. User.XmlSerializer = XmlSerializer;
  352. User.UserManager = UserManager;
  353. LocalizedStrings.ApplicationPaths = ApplicationPaths;
  354. }
  355. /// <summary>
  356. /// Finds the parts.
  357. /// </summary>
  358. protected override void FindParts()
  359. {
  360. if (IsFirstRun)
  361. {
  362. RegisterServerWithAdministratorAccess();
  363. }
  364. base.FindParts();
  365. HttpServer.Init(GetExports<IRestfulService>(false));
  366. ServerManager.AddWebSocketListeners(GetExports<IWebSocketListener>(false));
  367. StartServer(true);
  368. LibraryManager.AddParts(GetExports<IResolverIgnoreRule>(),
  369. GetExports<IVirtualFolderCreator>(),
  370. GetExports<IItemResolver>(),
  371. GetExports<IIntroProvider>(),
  372. GetExports<IBaseItemComparer>(),
  373. GetExports<ILibraryPrescanTask>(),
  374. GetExports<ILibraryPostScanTask>(),
  375. GetExports<IMetadataSaver>());
  376. ProviderManager.AddParts(GetExports<BaseMetadataProvider>().ToArray());
  377. }
  378. /// <summary>
  379. /// Starts the server.
  380. /// </summary>
  381. /// <param name="retryOnFailure">if set to <c>true</c> [retry on failure].</param>
  382. private void StartServer(bool retryOnFailure)
  383. {
  384. try
  385. {
  386. ServerManager.Start();
  387. }
  388. catch
  389. {
  390. if (retryOnFailure)
  391. {
  392. RegisterServerWithAdministratorAccess();
  393. StartServer(false);
  394. }
  395. else
  396. {
  397. throw;
  398. }
  399. }
  400. }
  401. /// <summary>
  402. /// Called when [configuration updated].
  403. /// </summary>
  404. /// <param name="sender">The sender.</param>
  405. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  406. protected override void OnConfigurationUpdated(object sender, EventArgs e)
  407. {
  408. base.OnConfigurationUpdated(sender, e);
  409. if (!string.Equals(HttpServer.UrlPrefix, HttpServerUrlPrefix, StringComparison.OrdinalIgnoreCase))
  410. {
  411. NotifyPendingRestart();
  412. }
  413. else if (!ServerManager.SupportsNativeWebSocket && ServerManager.WebSocketPortNumber != ServerConfigurationManager.Configuration.LegacyWebSocketPortNumber)
  414. {
  415. NotifyPendingRestart();
  416. }
  417. }
  418. /// <summary>
  419. /// Restarts this instance.
  420. /// </summary>
  421. public override void Restart()
  422. {
  423. App.Instance.Restart();
  424. }
  425. /// <summary>
  426. /// Gets or sets a value indicating whether this instance can self update.
  427. /// </summary>
  428. /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
  429. public override bool CanSelfUpdate
  430. {
  431. get
  432. {
  433. #if DEBUG
  434. return false;
  435. #endif
  436. return ConfigurationManager.CommonConfiguration.EnableAutoUpdate;
  437. }
  438. }
  439. /// <summary>
  440. /// Gets the composable part assemblies.
  441. /// </summary>
  442. /// <returns>IEnumerable{Assembly}.</returns>
  443. protected override IEnumerable<Assembly> GetComposablePartAssemblies()
  444. {
  445. // Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that
  446. // This will prevent the .dll file from getting locked, and allow us to replace it when needed
  447. foreach (var pluginAssembly in Directory
  448. .EnumerateFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.TopDirectoryOnly)
  449. .Select(LoadAssembly).Where(a => a != null))
  450. {
  451. yield return pluginAssembly;
  452. }
  453. // Include composable parts in the Api assembly
  454. yield return typeof(ApiEntryPoint).Assembly;
  455. // Include composable parts in the Dashboard assembly
  456. yield return typeof(DashboardInfo).Assembly;
  457. // Include composable parts in the Model assembly
  458. yield return typeof(SystemInfo).Assembly;
  459. // Include composable parts in the Common assembly
  460. yield return typeof(IApplicationHost).Assembly;
  461. // Include composable parts in the Controller assembly
  462. yield return typeof(Kernel).Assembly;
  463. // Include composable parts in the Providers assembly
  464. yield return typeof(ImagesByNameProvider).Assembly;
  465. // Common implementations
  466. yield return typeof(TaskManager).Assembly;
  467. // Server implementations
  468. yield return typeof(ServerApplicationPaths).Assembly;
  469. // Include composable parts in the running assembly
  470. yield return GetType().Assembly;
  471. }
  472. private readonly string _systemId = Environment.MachineName.GetMD5().ToString();
  473. /// <summary>
  474. /// Gets the system status.
  475. /// </summary>
  476. /// <returns>SystemInfo.</returns>
  477. public virtual SystemInfo GetSystemInfo()
  478. {
  479. return new SystemInfo
  480. {
  481. HasPendingRestart = HasPendingRestart,
  482. Version = ApplicationVersion.ToString(),
  483. IsNetworkDeployed = CanSelfUpdate,
  484. WebSocketPortNumber = ServerManager.WebSocketPortNumber,
  485. SupportsNativeWebSocket = ServerManager.SupportsNativeWebSocket,
  486. FailedPluginAssemblies = FailedAssemblies.ToArray(),
  487. InProgressInstallations = InstallationManager.CurrentInstallations.Select(i => i.Item1).ToArray(),
  488. CompletedInstallations = InstallationManager.CompletedInstallations.ToArray(),
  489. Id = _systemId,
  490. ProgramDataPath = ApplicationPaths.ProgramDataPath
  491. };
  492. }
  493. /// <summary>
  494. /// Shuts down.
  495. /// </summary>
  496. public override void Shutdown()
  497. {
  498. App.Instance.Dispatcher.Invoke(App.Instance.Shutdown);
  499. }
  500. /// <summary>
  501. /// Registers the server with administrator access.
  502. /// </summary>
  503. private void RegisterServerWithAdministratorAccess()
  504. {
  505. Logger.Info("Requesting administrative access to authorize http server");
  506. // Create a temp file path to extract the bat file to
  507. var tmpFile = Path.Combine(ConfigurationManager.CommonApplicationPaths.TempDirectory, Guid.NewGuid() + ".bat");
  508. // Extract the bat file
  509. using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MediaBrowser.ServerApplication.RegisterServer.bat"))
  510. {
  511. using (var fileStream = File.Create(tmpFile))
  512. {
  513. stream.CopyTo(fileStream);
  514. }
  515. }
  516. var startInfo = new ProcessStartInfo
  517. {
  518. FileName = tmpFile,
  519. Arguments = string.Format("{0} {1} {2} {3}", ServerConfigurationManager.Configuration.HttpServerPortNumber,
  520. HttpServerUrlPrefix,
  521. UdpServerPort,
  522. ServerConfigurationManager.Configuration.LegacyWebSocketPortNumber),
  523. CreateNoWindow = true,
  524. WindowStyle = ProcessWindowStyle.Hidden,
  525. Verb = "runas",
  526. ErrorDialog = false
  527. };
  528. using (var process = Process.Start(startInfo))
  529. {
  530. process.WaitForExit();
  531. }
  532. }
  533. public override async Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress)
  534. {
  535. var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(CancellationToken.None).ConfigureAwait(false);
  536. var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, Constants.MbServerPkgName, ConfigurationManager.CommonConfiguration.SystemUpdateLevel);
  537. return version != null ? new CheckForUpdateResult { AvailableVersion = version.version, IsUpdateAvailable = version.version > ApplicationVersion, Package = version } :
  538. new CheckForUpdateResult { AvailableVersion = ApplicationVersion, IsUpdateAvailable = false };
  539. }
  540. }
  541. }