ApplicationHost.cs 47 KB

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