ApplicationHost.cs 47 KB

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