ApplicationHost.cs 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224
  1. using MediaBrowser.Api;
  2. using MediaBrowser.Common;
  3. using MediaBrowser.Common.Configuration;
  4. using MediaBrowser.Common.Events;
  5. using MediaBrowser.Common.Extensions;
  6. using MediaBrowser.Common.Implementations;
  7. using MediaBrowser.Common.Implementations.ScheduledTasks;
  8. using MediaBrowser.Common.IO;
  9. using MediaBrowser.Common.Net;
  10. using MediaBrowser.Common.Progress;
  11. using MediaBrowser.Controller;
  12. using MediaBrowser.Controller.Channels;
  13. using MediaBrowser.Controller.Chapters;
  14. using MediaBrowser.Controller.Collections;
  15. using MediaBrowser.Controller.Configuration;
  16. using MediaBrowser.Controller.Dlna;
  17. using MediaBrowser.Controller.Drawing;
  18. using MediaBrowser.Controller.Dto;
  19. using MediaBrowser.Controller.Entities;
  20. using MediaBrowser.Controller.Entities.Audio;
  21. using MediaBrowser.Controller.Entities.Movies;
  22. using MediaBrowser.Controller.Entities.TV;
  23. using MediaBrowser.Controller.FileOrganization;
  24. using MediaBrowser.Controller.Library;
  25. using MediaBrowser.Controller.LiveTv;
  26. using MediaBrowser.Controller.Localization;
  27. using MediaBrowser.Controller.MediaEncoding;
  28. using MediaBrowser.Controller.Net;
  29. using MediaBrowser.Controller.News;
  30. using MediaBrowser.Controller.Notifications;
  31. using MediaBrowser.Controller.Persistence;
  32. using MediaBrowser.Controller.Plugins;
  33. using MediaBrowser.Controller.Providers;
  34. using MediaBrowser.Controller.Resolvers;
  35. using MediaBrowser.Controller.Security;
  36. using MediaBrowser.Controller.Session;
  37. using MediaBrowser.Controller.Sorting;
  38. using MediaBrowser.Controller.Subtitles;
  39. using MediaBrowser.Controller.Themes;
  40. using MediaBrowser.Dlna;
  41. using MediaBrowser.Dlna.ConnectionManager;
  42. using MediaBrowser.Dlna.ContentDirectory;
  43. using MediaBrowser.Dlna.Main;
  44. using MediaBrowser.LocalMetadata.Providers;
  45. using MediaBrowser.MediaEncoding.BdInfo;
  46. using MediaBrowser.MediaEncoding.Encoder;
  47. using MediaBrowser.MediaEncoding.Subtitles;
  48. using MediaBrowser.Model.Configuration;
  49. using MediaBrowser.Model.Logging;
  50. using MediaBrowser.Model.MediaInfo;
  51. using MediaBrowser.Model.System;
  52. using MediaBrowser.Model.Updates;
  53. using MediaBrowser.Providers.Chapters;
  54. using MediaBrowser.Providers.Manager;
  55. using MediaBrowser.Providers.Subtitles;
  56. using MediaBrowser.Server.Implementations;
  57. using MediaBrowser.Server.Implementations.Channels;
  58. using MediaBrowser.Server.Implementations.Collections;
  59. using MediaBrowser.Server.Implementations.Configuration;
  60. using MediaBrowser.Server.Implementations.Drawing;
  61. using MediaBrowser.Server.Implementations.Dto;
  62. using MediaBrowser.Server.Implementations.EntryPoints;
  63. using MediaBrowser.Server.Implementations.FileOrganization;
  64. using MediaBrowser.Server.Implementations.HttpServer;
  65. using MediaBrowser.Server.Implementations.IO;
  66. using MediaBrowser.Server.Implementations.Library;
  67. using MediaBrowser.Server.Implementations.LiveTv;
  68. using MediaBrowser.Server.Implementations.Localization;
  69. using MediaBrowser.Server.Implementations.MediaEncoder;
  70. using MediaBrowser.Server.Implementations.Notifications;
  71. using MediaBrowser.Server.Implementations.Persistence;
  72. using MediaBrowser.Server.Implementations.Security;
  73. using MediaBrowser.Server.Implementations.ServerManager;
  74. using MediaBrowser.Server.Implementations.Session;
  75. using MediaBrowser.Server.Implementations.Themes;
  76. using MediaBrowser.Server.Implementations.WebSocket;
  77. using MediaBrowser.ServerApplication.EntryPoints;
  78. using MediaBrowser.ServerApplication.FFMpeg;
  79. using MediaBrowser.ServerApplication.IO;
  80. using MediaBrowser.ServerApplication.Native;
  81. using MediaBrowser.ServerApplication.Networking;
  82. using MediaBrowser.WebDashboard.Api;
  83. using MediaBrowser.XbmcMetadata.Providers;
  84. using System;
  85. using System.Collections.Generic;
  86. using System.Globalization;
  87. using System.IO;
  88. using System.Linq;
  89. using System.Reflection;
  90. using System.Threading;
  91. using System.Threading.Tasks;
  92. namespace MediaBrowser.ServerApplication
  93. {
  94. /// <summary>
  95. /// Class CompositionRoot
  96. /// </summary>
  97. public class ApplicationHost : BaseApplicationHost<ServerApplicationPaths>, IServerApplicationHost
  98. {
  99. /// <summary>
  100. /// Gets the server configuration manager.
  101. /// </summary>
  102. /// <value>The server configuration manager.</value>
  103. public IServerConfigurationManager ServerConfigurationManager
  104. {
  105. get { return (IServerConfigurationManager)ConfigurationManager; }
  106. }
  107. /// <summary>
  108. /// Gets the name of the web application that can be used for url building.
  109. /// All api urls will be of the form {protocol}://{host}:{port}/{appname}/...
  110. /// </summary>
  111. /// <value>The name of the web application.</value>
  112. public string WebApplicationName
  113. {
  114. get { return "mediabrowser"; }
  115. }
  116. /// <summary>
  117. /// Gets the HTTP server URL prefix.
  118. /// </summary>
  119. /// <value>The HTTP server URL prefix.</value>
  120. private IEnumerable<string> HttpServerUrlPrefixes
  121. {
  122. get
  123. {
  124. var list = new List<string>
  125. {
  126. "http://+:" + ServerConfigurationManager.Configuration.HttpServerPortNumber + "/" + WebApplicationName + "/"
  127. };
  128. return list;
  129. }
  130. }
  131. /// <summary>
  132. /// Gets the configuration manager.
  133. /// </summary>
  134. /// <returns>IConfigurationManager.</returns>
  135. protected override IConfigurationManager GetConfigurationManager()
  136. {
  137. return new ServerConfigurationManager(ApplicationPaths, LogManager, XmlSerializer);
  138. }
  139. /// <summary>
  140. /// Gets or sets the server manager.
  141. /// </summary>
  142. /// <value>The server manager.</value>
  143. private IServerManager ServerManager { get; set; }
  144. /// <summary>
  145. /// Gets or sets the user manager.
  146. /// </summary>
  147. /// <value>The user manager.</value>
  148. public IUserManager UserManager { get; set; }
  149. /// <summary>
  150. /// Gets or sets the library manager.
  151. /// </summary>
  152. /// <value>The library manager.</value>
  153. internal ILibraryManager LibraryManager { get; set; }
  154. /// <summary>
  155. /// Gets or sets the directory watchers.
  156. /// </summary>
  157. /// <value>The directory watchers.</value>
  158. private ILibraryMonitor LibraryMonitor { get; set; }
  159. /// <summary>
  160. /// Gets or sets the provider manager.
  161. /// </summary>
  162. /// <value>The provider manager.</value>
  163. private IProviderManager ProviderManager { get; set; }
  164. /// <summary>
  165. /// Gets or sets the HTTP server.
  166. /// </summary>
  167. /// <value>The HTTP server.</value>
  168. private IHttpServer HttpServer { get; set; }
  169. private IDtoService DtoService { get; set; }
  170. private IImageProcessor ImageProcessor { get; set; }
  171. private ISeriesOrderManager SeriesOrderManager { get; set; }
  172. /// <summary>
  173. /// Gets or sets the media encoder.
  174. /// </summary>
  175. /// <value>The media encoder.</value>
  176. private IMediaEncoder MediaEncoder { get; set; }
  177. private ISessionManager SessionManager { get; set; }
  178. private ILiveTvManager LiveTvManager { get; set; }
  179. internal ILocalizationManager LocalizationManager { get; set; }
  180. private IEncodingManager EncodingManager { get; set; }
  181. private IChannelManager ChannelManager { get; set; }
  182. /// <summary>
  183. /// Gets or sets the user data repository.
  184. /// </summary>
  185. /// <value>The user data repository.</value>
  186. private IUserDataManager UserDataManager { get; set; }
  187. private IUserRepository UserRepository { get; set; }
  188. internal IDisplayPreferencesRepository DisplayPreferencesRepository { get; set; }
  189. internal IItemRepository ItemRepository { get; set; }
  190. private INotificationsRepository NotificationsRepository { get; set; }
  191. private IFileOrganizationRepository FileOrganizationRepository { get; set; }
  192. private IProviderRepository ProviderRepository { get; set; }
  193. private INotificationManager NotificationManager { get; set; }
  194. private ISubtitleManager SubtitleManager { get; set; }
  195. private IChapterManager ChapterManager { get; set; }
  196. private IUserViewManager UserViewManager { get; set; }
  197. /// <summary>
  198. /// Initializes a new instance of the <see cref="ApplicationHost"/> class.
  199. /// </summary>
  200. /// <param name="applicationPaths">The application paths.</param>
  201. /// <param name="logManager">The log manager.</param>
  202. public ApplicationHost(ServerApplicationPaths applicationPaths, ILogManager logManager, bool isRunningAsService)
  203. : base(applicationPaths, logManager)
  204. {
  205. _isRunningAsService = isRunningAsService;
  206. }
  207. private readonly bool _isRunningAsService;
  208. public override bool IsRunningAsService
  209. {
  210. get { return _isRunningAsService; }
  211. }
  212. /// <summary>
  213. /// Gets the name.
  214. /// </summary>
  215. /// <value>The name.</value>
  216. public override string Name
  217. {
  218. get
  219. {
  220. return "Media Browser Server";
  221. }
  222. }
  223. /// <summary>
  224. /// Gets a value indicating whether this instance can self restart.
  225. /// </summary>
  226. /// <value><c>true</c> if this instance can self restart; otherwise, <c>false</c>.</value>
  227. public override bool CanSelfRestart
  228. {
  229. get { return NativeApp.CanSelfRestart; }
  230. }
  231. public bool SupportsAutoRunAtStartup
  232. {
  233. get { return NativeApp.SupportsAutoRunAtStartup; }
  234. }
  235. /// <summary>
  236. /// Runs the startup tasks.
  237. /// </summary>
  238. /// <returns>Task.</returns>
  239. public override async Task RunStartupTasks()
  240. {
  241. await base.RunStartupTasks().ConfigureAwait(false);
  242. Logger.Info("Core startup complete");
  243. Parallel.ForEach(GetExports<IServerEntryPoint>(), entryPoint =>
  244. {
  245. try
  246. {
  247. entryPoint.Run();
  248. }
  249. catch (Exception ex)
  250. {
  251. Logger.ErrorException("Error in {0}", ex, entryPoint.GetType().Name);
  252. }
  253. });
  254. LogManager.RemoveConsoleOutput();
  255. }
  256. public override async Task Init(IProgress<double> progress)
  257. {
  258. PerformVersionMigration();
  259. await base.Init(progress).ConfigureAwait(false);
  260. MigrateModularConfigurations();
  261. ApplyDefaultMetadataSettings();
  262. }
  263. private void PerformVersionMigration()
  264. {
  265. DeleteDeprecatedModules();
  266. }
  267. private void MigrateModularConfigurations()
  268. {
  269. var saveConfig = false;
  270. if (ServerConfigurationManager.Configuration.DlnaOptions != null)
  271. {
  272. ServerConfigurationManager.SaveConfiguration("dlna", ServerConfigurationManager.Configuration.DlnaOptions);
  273. ServerConfigurationManager.Configuration.DlnaOptions = null;
  274. saveConfig = true;
  275. }
  276. if (ServerConfigurationManager.Configuration.ChapterOptions != null)
  277. {
  278. ServerConfigurationManager.SaveConfiguration("chapters", ServerConfigurationManager.Configuration.ChapterOptions);
  279. ServerConfigurationManager.Configuration.ChapterOptions = null;
  280. saveConfig = true;
  281. }
  282. if (ServerConfigurationManager.Configuration.ChannelOptions != null)
  283. {
  284. ServerConfigurationManager.SaveConfiguration("channels", ServerConfigurationManager.Configuration.ChannelOptions);
  285. ServerConfigurationManager.Configuration.ChannelOptions = null;
  286. saveConfig = true;
  287. }
  288. if (saveConfig)
  289. {
  290. ServerConfigurationManager.SaveConfiguration();
  291. }
  292. }
  293. private void ApplyDefaultMetadataSettings()
  294. {
  295. if (!ServerConfigurationManager.Configuration.DefaultMetadataSettingsApplied)
  296. {
  297. // Make sure xbmc metadata is disabled for existing users.
  298. // New users can just take the defaults.
  299. var service = ServerConfigurationManager.Configuration.IsStartupWizardCompleted
  300. ? "Xbmc Nfo"
  301. : "Media Browser Xml";
  302. DisableMetadataService(typeof(Movie), ServerConfigurationManager.Configuration, service);
  303. DisableMetadataService(typeof(MusicAlbum), ServerConfigurationManager.Configuration, service);
  304. DisableMetadataService(typeof(MusicArtist), ServerConfigurationManager.Configuration, service);
  305. DisableMetadataService(typeof(Episode), ServerConfigurationManager.Configuration, service);
  306. DisableMetadataService(typeof(Season), ServerConfigurationManager.Configuration, service);
  307. DisableMetadataService(typeof(Series), ServerConfigurationManager.Configuration, service);
  308. DisableMetadataService(typeof(MusicVideo), ServerConfigurationManager.Configuration, service);
  309. DisableMetadataService(typeof(Trailer), ServerConfigurationManager.Configuration, service);
  310. DisableMetadataService(typeof(AdultVideo), ServerConfigurationManager.Configuration, service);
  311. DisableMetadataService(typeof(Video), ServerConfigurationManager.Configuration, service);
  312. }
  313. ServerConfigurationManager.Configuration.DefaultMetadataSettingsApplied = true;
  314. ServerConfigurationManager.SaveConfiguration();
  315. }
  316. private void DisableMetadataService(Type type, ServerConfiguration config, string service)
  317. {
  318. var options = GetMetadataOptions(type, config);
  319. if (!options.DisabledMetadataSavers.Contains(service, StringComparer.OrdinalIgnoreCase))
  320. {
  321. var list = options.DisabledMetadataSavers.ToList();
  322. list.Add(service);
  323. options.DisabledMetadataSavers = list.ToArray();
  324. }
  325. }
  326. private MetadataOptions GetMetadataOptions(Type type, ServerConfiguration config)
  327. {
  328. var options = config.MetadataOptions
  329. .FirstOrDefault(i => string.Equals(i.ItemType, type.Name, StringComparison.OrdinalIgnoreCase));
  330. if (options == null)
  331. {
  332. var list = config.MetadataOptions.ToList();
  333. options = new MetadataOptions
  334. {
  335. ItemType = type.Name
  336. };
  337. list.Add(options);
  338. config.MetadataOptions = list.ToArray();
  339. }
  340. return options;
  341. }
  342. private void DeleteDeprecatedModules()
  343. {
  344. try
  345. {
  346. MigrateUserFolders();
  347. }
  348. catch (IOException)
  349. {
  350. }
  351. try
  352. {
  353. File.Delete(Path.Combine(ApplicationPaths.PluginsPath, "MBPhoto.dll"));
  354. }
  355. catch (IOException)
  356. {
  357. // Not there, no big deal
  358. }
  359. try
  360. {
  361. File.Delete(Path.Combine(ApplicationPaths.PluginsPath, "MediaBrowser.Plugins.XbmcMetadata.dll"));
  362. }
  363. catch (IOException)
  364. {
  365. // Not there, no big deal
  366. }
  367. Task.Run(() =>
  368. {
  369. try
  370. {
  371. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "remote-images"), true);
  372. }
  373. catch (IOException)
  374. {
  375. // Not there, no big deal
  376. }
  377. try
  378. {
  379. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "chapter-images"), true);
  380. }
  381. catch (IOException)
  382. {
  383. // Not there, no big deal
  384. }
  385. try
  386. {
  387. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "extracted-video-images"), true);
  388. }
  389. catch (IOException)
  390. {
  391. // Not there, no big deal
  392. }
  393. try
  394. {
  395. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "extracted-audio-images"), true);
  396. }
  397. catch (IOException)
  398. {
  399. // Not there, no big deal
  400. }
  401. try
  402. {
  403. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "tmdb-tv"), true);
  404. }
  405. catch (IOException)
  406. {
  407. // Not there, no big deal
  408. }
  409. try
  410. {
  411. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "tmdb-collections"), true);
  412. }
  413. catch (IOException)
  414. {
  415. // Not there, no big deal
  416. }
  417. try
  418. {
  419. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "tmdb-movies"), true);
  420. }
  421. catch (IOException)
  422. {
  423. // Not there, no big deal
  424. }
  425. try
  426. {
  427. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "fanart-movies"), true);
  428. }
  429. catch (IOException)
  430. {
  431. // Not there, no big deal
  432. }
  433. try
  434. {
  435. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "fanart-music"), true);
  436. }
  437. catch (IOException)
  438. {
  439. // Not there, no big deal
  440. }
  441. try
  442. {
  443. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "fanart-tv"), true);
  444. }
  445. catch (IOException)
  446. {
  447. // Not there, no big deal
  448. }
  449. try
  450. {
  451. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "tmdb-people"), true);
  452. }
  453. catch (IOException)
  454. {
  455. // Not there, no big deal
  456. }
  457. try
  458. {
  459. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "tvdb-v3"), true);
  460. }
  461. catch (IOException)
  462. {
  463. // Not there, no big deal
  464. }
  465. });
  466. }
  467. private void MigrateUserFolders()
  468. {
  469. var rootPath = ApplicationPaths.RootFolderPath;
  470. var folders = new DirectoryInfo(rootPath).EnumerateDirectories("*", SearchOption.TopDirectoryOnly).Where(i => !string.Equals(i.Name, "default", StringComparison.OrdinalIgnoreCase))
  471. .ToList();
  472. foreach (var folder in folders)
  473. {
  474. Directory.Delete(folder.FullName, true);
  475. }
  476. }
  477. /// <summary>
  478. /// Registers resources that classes will depend on
  479. /// </summary>
  480. /// <returns>Task.</returns>
  481. protected override async Task RegisterResources(IProgress<double> progress)
  482. {
  483. await base.RegisterResources(progress).ConfigureAwait(false);
  484. RegisterSingleInstance<IHttpResultFactory>(new HttpResultFactory(LogManager, FileSystemManager, JsonSerializer));
  485. RegisterSingleInstance<IServerApplicationHost>(this);
  486. RegisterSingleInstance<IServerApplicationPaths>(ApplicationPaths);
  487. RegisterSingleInstance(ServerConfigurationManager);
  488. LocalizationManager = new LocalizationManager(ServerConfigurationManager, FileSystemManager, JsonSerializer);
  489. RegisterSingleInstance(LocalizationManager);
  490. RegisterSingleInstance<IWebSocketServer>(() => new AlchemyServer(Logger));
  491. RegisterSingleInstance<IBlurayExaminer>(() => new BdInfoExaminer());
  492. UserDataManager = new UserDataManager(LogManager);
  493. RegisterSingleInstance(UserDataManager);
  494. UserRepository = await GetUserRepository().ConfigureAwait(false);
  495. RegisterSingleInstance(UserRepository);
  496. DisplayPreferencesRepository = new SqliteDisplayPreferencesRepository(ApplicationPaths, JsonSerializer, LogManager);
  497. RegisterSingleInstance(DisplayPreferencesRepository);
  498. ItemRepository = new SqliteItemRepository(ApplicationPaths, JsonSerializer, LogManager);
  499. RegisterSingleInstance(ItemRepository);
  500. ProviderRepository = new SqliteProviderInfoRepository(ApplicationPaths, LogManager);
  501. RegisterSingleInstance(ProviderRepository);
  502. FileOrganizationRepository = await GetFileOrganizationRepository().ConfigureAwait(false);
  503. RegisterSingleInstance(FileOrganizationRepository);
  504. UserManager = new UserManager(LogManager.GetLogger("UserManager"), ServerConfigurationManager, UserRepository, XmlSerializer);
  505. RegisterSingleInstance(UserManager);
  506. LibraryManager = new LibraryManager(Logger, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, () => LibraryMonitor, FileSystemManager, () => ProviderManager);
  507. RegisterSingleInstance(LibraryManager);
  508. var musicManager = new MusicManager(LibraryManager);
  509. RegisterSingleInstance<IMusicManager>(new MusicManager(LibraryManager));
  510. LibraryMonitor = new LibraryMonitor(LogManager, TaskManager, LibraryManager, ServerConfigurationManager, FileSystemManager);
  511. RegisterSingleInstance(LibraryMonitor);
  512. ProviderManager = new ProviderManager(HttpClient, ServerConfigurationManager, LibraryMonitor, LogManager, FileSystemManager);
  513. RegisterSingleInstance(ProviderManager);
  514. SeriesOrderManager = new SeriesOrderManager();
  515. RegisterSingleInstance(SeriesOrderManager);
  516. RegisterSingleInstance<ISearchEngine>(() => new SearchEngine(LogManager, LibraryManager, UserManager));
  517. HttpServer = ServerFactory.CreateServer(this, LogManager, "Media Browser", "mediabrowser", "dashboard/index.html");
  518. RegisterSingleInstance(HttpServer, false);
  519. progress.Report(10);
  520. ServerManager = new ServerManager(this, JsonSerializer, LogManager.GetLogger("ServerManager"), ServerConfigurationManager);
  521. RegisterSingleInstance(ServerManager);
  522. var innerProgress = new ActionableProgress<double>();
  523. innerProgress.RegisterAction(p => progress.Report((.75 * p) + 15));
  524. await RegisterMediaEncoder(innerProgress).ConfigureAwait(false);
  525. progress.Report(90);
  526. ImageProcessor = new ImageProcessor(LogManager.GetLogger("ImageProcessor"), ServerConfigurationManager.ApplicationPaths, FileSystemManager, JsonSerializer, MediaEncoder);
  527. RegisterSingleInstance(ImageProcessor);
  528. DtoService = new DtoService(Logger, LibraryManager, UserDataManager, ItemRepository, ImageProcessor, ServerConfigurationManager, FileSystemManager, ProviderManager, () => ChannelManager);
  529. RegisterSingleInstance(DtoService);
  530. SessionManager = new SessionManager(UserDataManager, ServerConfigurationManager, Logger, UserRepository, LibraryManager, UserManager, musicManager, DtoService, ImageProcessor, ItemRepository, JsonSerializer, this, HttpClient);
  531. RegisterSingleInstance(SessionManager);
  532. var newsService = new Server.Implementations.News.NewsService(ApplicationPaths, JsonSerializer);
  533. RegisterSingleInstance<INewsService>(newsService);
  534. var fileOrganizationService = new FileOrganizationService(TaskManager, FileOrganizationRepository, LogManager.GetLogger("FileOrganizationService"), LibraryMonitor, LibraryManager, ServerConfigurationManager, FileSystemManager, ProviderManager);
  535. RegisterSingleInstance<IFileOrganizationService>(fileOrganizationService);
  536. progress.Report(15);
  537. ChannelManager = new ChannelManager(UserManager, DtoService, LibraryManager, Logger, ServerConfigurationManager, FileSystemManager, UserDataManager, JsonSerializer, LocalizationManager);
  538. RegisterSingleInstance(ChannelManager);
  539. var appThemeManager = new AppThemeManager(ApplicationPaths, FileSystemManager, JsonSerializer, Logger);
  540. RegisterSingleInstance<IAppThemeManager>(appThemeManager);
  541. var dlnaManager = new DlnaManager(XmlSerializer, FileSystemManager, ApplicationPaths, LogManager.GetLogger("Dlna"), JsonSerializer);
  542. RegisterSingleInstance<IDlnaManager>(dlnaManager);
  543. var contentDirectory = new ContentDirectory(dlnaManager, UserDataManager, ImageProcessor, LibraryManager, ServerConfigurationManager, UserManager, LogManager.GetLogger("UpnpContentDirectory"), HttpClient);
  544. RegisterSingleInstance<IContentDirectory>(contentDirectory);
  545. var connectionManager = new ConnectionManager(dlnaManager, ServerConfigurationManager, LogManager.GetLogger("UpnpConnectionManager"), HttpClient);
  546. RegisterSingleInstance<IConnectionManager>(connectionManager);
  547. var collectionManager = new CollectionManager(LibraryManager, FileSystemManager, LibraryMonitor);
  548. RegisterSingleInstance<ICollectionManager>(collectionManager);
  549. LiveTvManager = new LiveTvManager(ServerConfigurationManager, FileSystemManager, Logger, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, TaskManager, JsonSerializer, LocalizationManager);
  550. RegisterSingleInstance(LiveTvManager);
  551. UserViewManager = new UserViewManager(LibraryManager, LocalizationManager, FileSystemManager, UserManager, ChannelManager, LiveTvManager);
  552. RegisterSingleInstance(UserViewManager);
  553. NotificationManager = new NotificationManager(LogManager, UserManager, ServerConfigurationManager);
  554. RegisterSingleInstance(NotificationManager);
  555. RegisterSingleInstance<IEncryptionManager>(new EncryptionManager());
  556. SubtitleManager = new SubtitleManager(LogManager.GetLogger("SubtitleManager"), FileSystemManager, LibraryMonitor, LibraryManager, ItemRepository);
  557. RegisterSingleInstance(SubtitleManager);
  558. ChapterManager = new ChapterManager(LibraryManager, LogManager.GetLogger("ChapterManager"), ServerConfigurationManager, ItemRepository);
  559. RegisterSingleInstance(ChapterManager);
  560. EncodingManager = new EncodingManager(ServerConfigurationManager, FileSystemManager, Logger,
  561. MediaEncoder, ChapterManager);
  562. RegisterSingleInstance(EncodingManager);
  563. RegisterSingleInstance<ISubtitleEncoder>(new SubtitleEncoder(LibraryManager, LogManager.GetLogger("SubtitleEncoder"), ApplicationPaths, FileSystemManager, MediaEncoder));
  564. var displayPreferencesTask = Task.Run(async () => await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false));
  565. var itemsTask = Task.Run(async () => await ConfigureItemRepositories().ConfigureAwait(false));
  566. var userdataTask = Task.Run(async () => await ConfigureUserDataRepositories().ConfigureAwait(false));
  567. await ConfigureNotificationsRepository().ConfigureAwait(false);
  568. progress.Report(92);
  569. await Task.WhenAll(itemsTask, displayPreferencesTask, userdataTask).ConfigureAwait(false);
  570. progress.Report(100);
  571. SetStaticProperties();
  572. await ((UserManager)UserManager).Initialize().ConfigureAwait(false);
  573. SetKernelProperties();
  574. }
  575. protected override INetworkManager CreateNetworkManager()
  576. {
  577. return new NetworkManager();
  578. }
  579. protected override IFileSystem CreateFileSystemManager()
  580. {
  581. return FileSystemFactory.CreateFileSystemManager(LogManager);
  582. }
  583. /// <summary>
  584. /// Registers the media encoder.
  585. /// </summary>
  586. /// <returns>Task.</returns>
  587. private async Task RegisterMediaEncoder(IProgress<double> progress)
  588. {
  589. var info = await new FFMpegDownloader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager).GetFFMpegInfo(progress).ConfigureAwait(false);
  590. MediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"), JsonSerializer, info.EncoderPath, info.ProbePath, info.Version);
  591. RegisterSingleInstance(MediaEncoder);
  592. }
  593. /// <summary>
  594. /// Sets the kernel properties.
  595. /// </summary>
  596. private void SetKernelProperties()
  597. {
  598. LocalizedStrings.StringFiles = GetExports<LocalizedStringData>();
  599. }
  600. /// <summary>
  601. /// Gets the user repository.
  602. /// </summary>
  603. /// <returns>Task{IUserRepository}.</returns>
  604. private async Task<IUserRepository> GetUserRepository()
  605. {
  606. var repo = new SqliteUserRepository(JsonSerializer, LogManager, ApplicationPaths);
  607. await repo.Initialize().ConfigureAwait(false);
  608. return repo;
  609. }
  610. /// <summary>
  611. /// Gets the file organization repository.
  612. /// </summary>
  613. /// <returns>Task{IUserRepository}.</returns>
  614. private async Task<IFileOrganizationRepository> GetFileOrganizationRepository()
  615. {
  616. var repo = new SqliteFileOrganizationRepository(LogManager, ServerConfigurationManager.ApplicationPaths);
  617. await repo.Initialize().ConfigureAwait(false);
  618. return repo;
  619. }
  620. /// <summary>
  621. /// Configures the repositories.
  622. /// </summary>
  623. /// <returns>Task.</returns>
  624. private async Task ConfigureNotificationsRepository()
  625. {
  626. var repo = new SqliteNotificationsRepository(LogManager, ApplicationPaths);
  627. await repo.Initialize().ConfigureAwait(false);
  628. NotificationsRepository = repo;
  629. RegisterSingleInstance(NotificationsRepository);
  630. }
  631. /// <summary>
  632. /// Configures the repositories.
  633. /// </summary>
  634. /// <returns>Task.</returns>
  635. private async Task ConfigureDisplayPreferencesRepositories()
  636. {
  637. await DisplayPreferencesRepository.Initialize().ConfigureAwait(false);
  638. }
  639. /// <summary>
  640. /// Configures the item repositories.
  641. /// </summary>
  642. /// <returns>Task.</returns>
  643. private async Task ConfigureItemRepositories()
  644. {
  645. await ItemRepository.Initialize().ConfigureAwait(false);
  646. await ProviderRepository.Initialize().ConfigureAwait(false);
  647. ((LibraryManager)LibraryManager).ItemRepository = ItemRepository;
  648. }
  649. /// <summary>
  650. /// Configures the user data repositories.
  651. /// </summary>
  652. /// <returns>Task.</returns>
  653. private async Task ConfigureUserDataRepositories()
  654. {
  655. var repo = new SqliteUserDataRepository(ApplicationPaths, LogManager);
  656. await repo.Initialize().ConfigureAwait(false);
  657. ((UserDataManager)UserDataManager).Repository = repo;
  658. }
  659. /// <summary>
  660. /// Dirty hacks
  661. /// </summary>
  662. private void SetStaticProperties()
  663. {
  664. // For now there's no real way to inject these properly
  665. BaseItem.Logger = LogManager.GetLogger("BaseItem");
  666. BaseItem.ConfigurationManager = ServerConfigurationManager;
  667. BaseItem.LibraryManager = LibraryManager;
  668. BaseItem.ProviderManager = ProviderManager;
  669. BaseItem.LocalizationManager = LocalizationManager;
  670. BaseItem.ItemRepository = ItemRepository;
  671. User.XmlSerializer = XmlSerializer;
  672. User.UserManager = UserManager;
  673. LocalizedStrings.ApplicationPaths = ApplicationPaths;
  674. Folder.UserManager = UserManager;
  675. BaseItem.FileSystem = FileSystemManager;
  676. BaseItem.UserDataManager = UserDataManager;
  677. ChannelVideoItem.ChannelManager = ChannelManager;
  678. }
  679. /// <summary>
  680. /// Finds the parts.
  681. /// </summary>
  682. protected override void FindParts()
  683. {
  684. if (IsFirstRun)
  685. {
  686. RegisterServerWithAdministratorAccess();
  687. }
  688. base.FindParts();
  689. HttpServer.Init(GetExports<IRestfulService>(false));
  690. ServerManager.AddWebSocketListeners(GetExports<IWebSocketListener>(false));
  691. StartServer(true);
  692. LibraryManager.AddParts(GetExports<IResolverIgnoreRule>(),
  693. GetExports<IVirtualFolderCreator>(),
  694. GetExports<IItemResolver>(),
  695. GetExports<IIntroProvider>(),
  696. GetExports<IBaseItemComparer>(),
  697. GetExports<ILibraryPostScanTask>());
  698. ProviderManager.AddParts(GetExports<IImageProvider>(),
  699. GetExports<IMetadataService>(),
  700. GetExports<IItemIdentityProvider>(),
  701. GetExports<IItemIdentityConverter>(),
  702. GetExports<IMetadataProvider>(),
  703. GetExports<IMetadataSaver>(),
  704. GetExports<IImageSaver>(),
  705. GetExports<IExternalId>());
  706. SeriesOrderManager.AddParts(GetExports<ISeriesOrderProvider>());
  707. ImageProcessor.AddParts(GetExports<IImageEnhancer>());
  708. LiveTvManager.AddParts(GetExports<ILiveTvService>());
  709. SubtitleManager.AddParts(GetExports<ISubtitleProvider>());
  710. ChapterManager.AddParts(GetExports<IChapterProvider>());
  711. SessionManager.AddParts(GetExports<ISessionControllerFactory>());
  712. ChannelManager.AddParts(GetExports<IChannel>(), GetExports<IChannelFactory>());
  713. NotificationManager.AddParts(GetExports<INotificationService>(), GetExports<INotificationTypeFactory>());
  714. }
  715. /// <summary>
  716. /// Starts the server.
  717. /// </summary>
  718. /// <param name="retryOnFailure">if set to <c>true</c> [retry on failure].</param>
  719. private void StartServer(bool retryOnFailure)
  720. {
  721. try
  722. {
  723. ServerManager.Start(HttpServerUrlPrefixes, ServerConfigurationManager.Configuration.EnableHttpLevelLogging);
  724. }
  725. catch (Exception ex)
  726. {
  727. Logger.ErrorException("Error starting http server", ex);
  728. if (retryOnFailure)
  729. {
  730. RegisterServerWithAdministratorAccess();
  731. StartServer(false);
  732. }
  733. else
  734. {
  735. throw;
  736. }
  737. }
  738. ServerManager.StartWebSocketServer();
  739. }
  740. /// <summary>
  741. /// Called when [configuration updated].
  742. /// </summary>
  743. /// <param name="sender">The sender.</param>
  744. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  745. protected override void OnConfigurationUpdated(object sender, EventArgs e)
  746. {
  747. base.OnConfigurationUpdated(sender, e);
  748. HttpServer.EnableHttpRequestLogging = ServerConfigurationManager.Configuration.EnableHttpLevelLogging;
  749. if (!HttpServer.UrlPrefixes.SequenceEqual(HttpServerUrlPrefixes, StringComparer.OrdinalIgnoreCase))
  750. {
  751. NotifyPendingRestart();
  752. }
  753. else if (!ServerManager.SupportsNativeWebSocket && ServerManager.WebSocketPortNumber != ServerConfigurationManager.Configuration.LegacyWebSocketPortNumber)
  754. {
  755. NotifyPendingRestart();
  756. }
  757. }
  758. /// <summary>
  759. /// Restarts this instance.
  760. /// </summary>
  761. public override async Task Restart()
  762. {
  763. if (!CanSelfRestart)
  764. {
  765. throw new InvalidOperationException("The server is unable to self-restart. Please restart manually.");
  766. }
  767. try
  768. {
  769. await SessionManager.SendServerRestartNotification(CancellationToken.None).ConfigureAwait(false);
  770. }
  771. catch (Exception ex)
  772. {
  773. Logger.ErrorException("Error sending server restart notification", ex);
  774. }
  775. Logger.Debug("Calling NativeApp.Restart");
  776. NativeApp.Restart();
  777. }
  778. /// <summary>
  779. /// Gets or sets a value indicating whether this instance can self update.
  780. /// </summary>
  781. /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
  782. public override bool CanSelfUpdate
  783. {
  784. get
  785. {
  786. #if DEBUG
  787. return false;
  788. #endif
  789. #pragma warning disable 162
  790. return NativeApp.CanSelfUpdate;
  791. #pragma warning restore 162
  792. }
  793. }
  794. /// <summary>
  795. /// Gets the composable part assemblies.
  796. /// </summary>
  797. /// <returns>IEnumerable{Assembly}.</returns>
  798. protected override IEnumerable<Assembly> GetComposablePartAssemblies()
  799. {
  800. var list = GetPluginAssemblies()
  801. .ToList();
  802. // Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that
  803. // This will prevent the .dll file from getting locked, and allow us to replace it when needed
  804. // Include composable parts in the Api assembly
  805. list.Add(typeof(ApiEntryPoint).Assembly);
  806. // Include composable parts in the Dashboard assembly
  807. list.Add(typeof(DashboardService).Assembly);
  808. // Include composable parts in the Model assembly
  809. list.Add(typeof(SystemInfo).Assembly);
  810. // Include composable parts in the Common assembly
  811. list.Add(typeof(IApplicationHost).Assembly);
  812. // Include composable parts in the Controller assembly
  813. list.Add(typeof(IServerApplicationHost).Assembly);
  814. // Include composable parts in the Providers assembly
  815. list.Add(typeof(ProviderUtils).Assembly);
  816. // Common implementations
  817. list.Add(typeof(TaskManager).Assembly);
  818. // Server implementations
  819. list.Add(typeof(ServerApplicationPaths).Assembly);
  820. // MediaEncoding
  821. list.Add(typeof(MediaEncoder).Assembly);
  822. // Dlna
  823. list.Add(typeof(DlnaEntryPoint).Assembly);
  824. // Local metadata
  825. list.Add(typeof(AlbumXmlProvider).Assembly);
  826. // Xbmc
  827. list.Add(typeof(ArtistNfoProvider).Assembly);
  828. list.AddRange(Assemblies.GetAssembliesWithParts());
  829. // Include composable parts in the running assembly
  830. list.Add(GetType().Assembly);
  831. return list;
  832. }
  833. /// <summary>
  834. /// Gets the plugin assemblies.
  835. /// </summary>
  836. /// <returns>IEnumerable{Assembly}.</returns>
  837. private IEnumerable<Assembly> GetPluginAssemblies()
  838. {
  839. try
  840. {
  841. return Directory.EnumerateFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.TopDirectoryOnly)
  842. .Select(LoadAssembly)
  843. .Where(a => a != null)
  844. .ToList();
  845. }
  846. catch (DirectoryNotFoundException)
  847. {
  848. return new List<Assembly>();
  849. }
  850. }
  851. private readonly string _systemId = Environment.MachineName.GetMD5().ToString();
  852. /// <summary>
  853. /// Gets the system status.
  854. /// </summary>
  855. /// <returns>SystemInfo.</returns>
  856. public virtual SystemInfo GetSystemInfo()
  857. {
  858. return new SystemInfo
  859. {
  860. HasPendingRestart = HasPendingRestart,
  861. Version = ApplicationVersion.ToString(),
  862. IsNetworkDeployed = CanSelfUpdate,
  863. WebSocketPortNumber = ServerManager.WebSocketPortNumber,
  864. SupportsNativeWebSocket = ServerManager.SupportsNativeWebSocket,
  865. FailedPluginAssemblies = FailedAssemblies.ToList(),
  866. InProgressInstallations = InstallationManager.CurrentInstallations.Select(i => i.Item1).ToList(),
  867. CompletedInstallations = InstallationManager.CompletedInstallations.ToList(),
  868. Id = _systemId,
  869. ProgramDataPath = ApplicationPaths.ProgramDataPath,
  870. LogPath = ApplicationPaths.LogDirectoryPath,
  871. ItemsByNamePath = ApplicationPaths.ItemsByNamePath,
  872. InternalMetadataPath = ApplicationPaths.InternalMetadataPath,
  873. CachePath = ApplicationPaths.CachePath,
  874. MacAddress = GetMacAddress(),
  875. HttpServerPortNumber = HttpServerPort,
  876. OperatingSystem = Environment.OSVersion.ToString(),
  877. CanSelfRestart = CanSelfRestart,
  878. CanSelfUpdate = CanSelfUpdate,
  879. WanAddress = GetWanAddress(),
  880. HasUpdateAvailable = HasUpdateAvailable,
  881. SupportsAutoRunAtStartup = SupportsAutoRunAtStartup,
  882. TranscodingTempPath = ApplicationPaths.TranscodingTempPath,
  883. IsRunningAsService = IsRunningAsService,
  884. ServerName = string.IsNullOrWhiteSpace(ServerConfigurationManager.Configuration.ServerName) ? Environment.MachineName : ServerConfigurationManager.Configuration.ServerName
  885. };
  886. }
  887. public int HttpServerPort
  888. {
  889. get { return ServerConfigurationManager.Configuration.HttpServerPortNumber; }
  890. }
  891. private readonly CultureInfo _usCulture = new CultureInfo("en-US");
  892. private string GetWanAddress()
  893. {
  894. var ip = ServerConfigurationManager.Configuration.WanDdns;
  895. if (string.IsNullOrWhiteSpace(ip))
  896. {
  897. ip = WanAddressEntryPoint.WanAddress;
  898. }
  899. if (!string.IsNullOrEmpty(ip))
  900. {
  901. if (!ip.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
  902. !ip.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
  903. {
  904. ip = "http://" + ip;
  905. }
  906. return ip + ":" + ServerConfigurationManager.Configuration.HttpServerPortNumber.ToString(_usCulture);
  907. }
  908. return null;
  909. }
  910. /// <summary>
  911. /// Gets the mac address.
  912. /// </summary>
  913. /// <returns>System.String.</returns>
  914. private string GetMacAddress()
  915. {
  916. try
  917. {
  918. return NetworkManager.GetMacAddress();
  919. }
  920. catch (Exception ex)
  921. {
  922. Logger.ErrorException("Error getting mac address", ex);
  923. return null;
  924. }
  925. }
  926. /// <summary>
  927. /// Shuts down.
  928. /// </summary>
  929. public override async Task Shutdown()
  930. {
  931. try
  932. {
  933. await SessionManager.SendServerShutdownNotification(CancellationToken.None).ConfigureAwait(false);
  934. }
  935. catch (Exception ex)
  936. {
  937. Logger.ErrorException("Error sending server shutdown notification", ex);
  938. }
  939. NativeApp.Shutdown();
  940. }
  941. /// <summary>
  942. /// Registers the server with administrator access.
  943. /// </summary>
  944. private void RegisterServerWithAdministratorAccess()
  945. {
  946. Logger.Info("Requesting administrative access to authorize http server");
  947. try
  948. {
  949. ServerAuthorization.AuthorizeServer(
  950. ServerConfigurationManager.Configuration.HttpServerPortNumber,
  951. HttpServerUrlPrefixes.First(),
  952. ServerConfigurationManager.Configuration.LegacyWebSocketPortNumber,
  953. UdpServerEntryPoint.PortNumber,
  954. ConfigurationManager.CommonApplicationPaths.TempDirectory);
  955. }
  956. catch (Exception ex)
  957. {
  958. Logger.ErrorException("Error authorizing server", ex);
  959. }
  960. }
  961. public event EventHandler HasUpdateAvailableChanged;
  962. private bool _hasUpdateAvailable;
  963. public bool HasUpdateAvailable
  964. {
  965. get { return _hasUpdateAvailable; }
  966. set
  967. {
  968. var fireEvent = value && !_hasUpdateAvailable;
  969. _hasUpdateAvailable = value;
  970. if (fireEvent)
  971. {
  972. EventHelper.FireEventIfNotNull(HasUpdateAvailableChanged, this, EventArgs.Empty, Logger);
  973. }
  974. }
  975. }
  976. /// <summary>
  977. /// Checks for update.
  978. /// </summary>
  979. /// <param name="cancellationToken">The cancellation token.</param>
  980. /// <param name="progress">The progress.</param>
  981. /// <returns>Task{CheckForUpdateResult}.</returns>
  982. public override async Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress)
  983. {
  984. var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
  985. var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, "MBServer", null, ApplicationVersion,
  986. ConfigurationManager.CommonConfiguration.SystemUpdateLevel);
  987. var versionObject = version == null || string.IsNullOrWhiteSpace(version.versionStr) ? null : new Version(version.versionStr);
  988. HasUpdateAvailable = versionObject != null && versionObject >= ApplicationVersion;
  989. return versionObject != null ? new CheckForUpdateResult { AvailableVersion = versionObject.ToString(), IsUpdateAvailable = versionObject > ApplicationVersion, Package = version } :
  990. new CheckForUpdateResult { AvailableVersion = ApplicationVersion.ToString(), IsUpdateAvailable = false };
  991. }
  992. /// <summary>
  993. /// Updates the application.
  994. /// </summary>
  995. /// <param name="package">The package that contains the update</param>
  996. /// <param name="cancellationToken">The cancellation token.</param>
  997. /// <param name="progress">The progress.</param>
  998. /// <returns>Task.</returns>
  999. public override async Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken, IProgress<double> progress)
  1000. {
  1001. await InstallationManager.InstallPackage(package, progress, cancellationToken).ConfigureAwait(false);
  1002. HasUpdateAvailable = false;
  1003. OnApplicationUpdated(package);
  1004. }
  1005. /// <summary>
  1006. /// Configures the automatic run at startup.
  1007. /// </summary>
  1008. /// <param name="autorun">if set to <c>true</c> [autorun].</param>
  1009. protected override void ConfigureAutoRunAtStartup(bool autorun)
  1010. {
  1011. if (SupportsAutoRunAtStartup)
  1012. {
  1013. Autorun.Configure(autorun);
  1014. }
  1015. }
  1016. }
  1017. }