ApplicationHost.cs 47 KB

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