ApplicationHost.cs 48 KB

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