BaseApplicationHost.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. using System.Text;
  2. using MediaBrowser.Common.Configuration;
  3. using MediaBrowser.Common.Events;
  4. using MediaBrowser.Common.Implementations.Archiving;
  5. using MediaBrowser.Common.Implementations.IO;
  6. using MediaBrowser.Common.Implementations.ScheduledTasks;
  7. using MediaBrowser.Common.Implementations.Security;
  8. using MediaBrowser.Common.Implementations.Serialization;
  9. using MediaBrowser.Common.Implementations.Updates;
  10. using MediaBrowser.Common.IO;
  11. using MediaBrowser.Common.Net;
  12. using MediaBrowser.Common.Plugins;
  13. using MediaBrowser.Common.Progress;
  14. using MediaBrowser.Common.ScheduledTasks;
  15. using MediaBrowser.Common.Security;
  16. using MediaBrowser.Common.Updates;
  17. using MediaBrowser.Model.IO;
  18. using MediaBrowser.Model.Logging;
  19. using MediaBrowser.Model.Serialization;
  20. using MediaBrowser.Model.Updates;
  21. using ServiceStack;
  22. using SimpleInjector;
  23. using System;
  24. using System.Collections.Generic;
  25. using System.IO;
  26. using System.Linq;
  27. using System.Net;
  28. using System.Reflection;
  29. using System.Threading;
  30. using System.Threading.Tasks;
  31. namespace MediaBrowser.Common.Implementations
  32. {
  33. /// <summary>
  34. /// Class BaseApplicationHost
  35. /// </summary>
  36. /// <typeparam name="TApplicationPathsType">The type of the T application paths type.</typeparam>
  37. public abstract class BaseApplicationHost<TApplicationPathsType> : IApplicationHost
  38. where TApplicationPathsType : class, IApplicationPaths
  39. {
  40. /// <summary>
  41. /// Occurs when [has pending restart changed].
  42. /// </summary>
  43. public event EventHandler HasPendingRestartChanged;
  44. /// <summary>
  45. /// Occurs when [application updated].
  46. /// </summary>
  47. public event EventHandler<GenericEventArgs<Version>> ApplicationUpdated;
  48. /// <summary>
  49. /// Gets or sets a value indicating whether this instance has changes that require the entire application to restart.
  50. /// </summary>
  51. /// <value><c>true</c> if this instance has pending application restart; otherwise, <c>false</c>.</value>
  52. public bool HasPendingRestart { get; private set; }
  53. /// <summary>
  54. /// Gets or sets the logger.
  55. /// </summary>
  56. /// <value>The logger.</value>
  57. protected ILogger Logger { get; private set; }
  58. /// <summary>
  59. /// Gets or sets the plugins.
  60. /// </summary>
  61. /// <value>The plugins.</value>
  62. public IEnumerable<IPlugin> Plugins { get; protected set; }
  63. /// <summary>
  64. /// Gets or sets the log manager.
  65. /// </summary>
  66. /// <value>The log manager.</value>
  67. public ILogManager LogManager { get; protected set; }
  68. /// <summary>
  69. /// Gets the application paths.
  70. /// </summary>
  71. /// <value>The application paths.</value>
  72. protected TApplicationPathsType ApplicationPaths { get; private set; }
  73. /// <summary>
  74. /// The container
  75. /// </summary>
  76. protected readonly Container Container = new Container();
  77. /// <summary>
  78. /// The json serializer
  79. /// </summary>
  80. public IJsonSerializer JsonSerializer { get; private set; }
  81. /// <summary>
  82. /// The _XML serializer
  83. /// </summary>
  84. protected readonly IXmlSerializer XmlSerializer = new XmlSerializer();
  85. /// <summary>
  86. /// Gets assemblies that failed to load
  87. /// </summary>
  88. /// <value>The failed assemblies.</value>
  89. public List<string> FailedAssemblies { get; protected set; }
  90. /// <summary>
  91. /// Gets all types within all running assemblies
  92. /// </summary>
  93. /// <value>All types.</value>
  94. public Type[] AllTypes { get; protected set; }
  95. /// <summary>
  96. /// Gets all concrete types.
  97. /// </summary>
  98. /// <value>All concrete types.</value>
  99. public Type[] AllConcreteTypes { get; protected set; }
  100. /// <summary>
  101. /// The disposable parts
  102. /// </summary>
  103. protected readonly List<IDisposable> DisposableParts = new List<IDisposable>();
  104. /// <summary>
  105. /// Gets a value indicating whether this instance is first run.
  106. /// </summary>
  107. /// <value><c>true</c> if this instance is first run; otherwise, <c>false</c>.</value>
  108. public bool IsFirstRun { get; private set; }
  109. /// <summary>
  110. /// Gets the kernel.
  111. /// </summary>
  112. /// <value>The kernel.</value>
  113. protected ITaskManager TaskManager { get; private set; }
  114. /// <summary>
  115. /// Gets the security manager.
  116. /// </summary>
  117. /// <value>The security manager.</value>
  118. protected ISecurityManager SecurityManager { get; private set; }
  119. /// <summary>
  120. /// Gets the HTTP client.
  121. /// </summary>
  122. /// <value>The HTTP client.</value>
  123. protected IHttpClient HttpClient { get; private set; }
  124. /// <summary>
  125. /// Gets the network manager.
  126. /// </summary>
  127. /// <value>The network manager.</value>
  128. protected INetworkManager NetworkManager { get; private set; }
  129. /// <summary>
  130. /// Gets the configuration manager.
  131. /// </summary>
  132. /// <value>The configuration manager.</value>
  133. protected IConfigurationManager ConfigurationManager { get; private set; }
  134. /// <summary>
  135. /// Gets or sets the installation manager.
  136. /// </summary>
  137. /// <value>The installation manager.</value>
  138. protected IInstallationManager InstallationManager { get; private set; }
  139. protected IFileSystem FileSystemManager { get; private set; }
  140. /// <summary>
  141. /// Gets or sets the zip client.
  142. /// </summary>
  143. /// <value>The zip client.</value>
  144. protected IZipClient ZipClient { get; private set; }
  145. protected IIsoManager IsoManager { get; private set; }
  146. /// <summary>
  147. /// Initializes a new instance of the <see cref="BaseApplicationHost{TApplicationPathsType}"/> class.
  148. /// </summary>
  149. protected BaseApplicationHost(TApplicationPathsType applicationPaths, ILogManager logManager)
  150. {
  151. FailedAssemblies = new List<string>();
  152. ApplicationPaths = applicationPaths;
  153. LogManager = logManager;
  154. ConfigurationManager = GetConfigurationManager();
  155. }
  156. /// <summary>
  157. /// Inits this instance.
  158. /// </summary>
  159. /// <returns>Task.</returns>
  160. public virtual async Task Init(IProgress<double> progress)
  161. {
  162. try
  163. {
  164. // https://github.com/ServiceStack/ServiceStack/blob/master/tests/ServiceStack.WebHost.IntegrationTests/Web.config#L4
  165. Licensing.RegisterLicense("1001-e1JlZjoxMDAxLE5hbWU6VGVzdCBCdXNpbmVzcyxUeXBlOkJ1c2luZXNzLEhhc2g6UHVNTVRPclhvT2ZIbjQ5MG5LZE1mUTd5RUMzQnBucTFEbTE3TDczVEF4QUNMT1FhNXJMOWkzVjFGL2ZkVTE3Q2pDNENqTkQyUktRWmhvUVBhYTBiekJGUUZ3ZE5aZHFDYm9hL3lydGlwUHI5K1JsaTBYbzNsUC85cjVJNHE5QVhldDN6QkE4aTlvdldrdTgyTk1relY2eis2dFFqTThYN2lmc0JveHgycFdjPSxFeHBpcnk6MjAxMy0wMS0wMX0=");
  166. }
  167. catch
  168. {
  169. // Failing under mono
  170. }
  171. progress.Report(1);
  172. JsonSerializer = CreateJsonSerializer();
  173. Logger = LogManager.GetLogger("App");
  174. IsFirstRun = !ConfigurationManager.CommonConfiguration.IsStartupWizardCompleted;
  175. progress.Report(2);
  176. LogManager.LogSeverity = ConfigurationManager.CommonConfiguration.EnableDebugLevelLogging
  177. ? LogSeverity.Debug
  178. : LogSeverity.Info;
  179. // Put the app config in the log for troubleshooting purposes
  180. Logger.LogMultiline("Application Configuration:", LogSeverity.Info, new StringBuilder(JsonSerializer.SerializeToString(ConfigurationManager.CommonConfiguration)));
  181. progress.Report(3);
  182. DiscoverTypes();
  183. progress.Report(14);
  184. Logger.Info("Version {0} initializing", ApplicationVersion);
  185. SetHttpLimit();
  186. progress.Report(15);
  187. var innerProgress = new ActionableProgress<double>();
  188. innerProgress.RegisterAction(p => progress.Report((.8 * p) + 15));
  189. await RegisterResources(innerProgress).ConfigureAwait(false);
  190. FindParts();
  191. progress.Report(95);
  192. await InstallIsoMounters(CancellationToken.None).ConfigureAwait(false);
  193. progress.Report(100);
  194. }
  195. protected virtual IJsonSerializer CreateJsonSerializer()
  196. {
  197. return new JsonSerializer();
  198. }
  199. private void SetHttpLimit()
  200. {
  201. try
  202. {
  203. // Increase the max http request limit
  204. ServicePointManager.DefaultConnectionLimit = Math.Max(96, ServicePointManager.DefaultConnectionLimit);
  205. }
  206. catch (Exception ex)
  207. {
  208. Logger.ErrorException("Error setting http limit", ex);
  209. }
  210. }
  211. /// <summary>
  212. /// Installs the iso mounters.
  213. /// </summary>
  214. /// <param name="cancellationToken">The cancellation token.</param>
  215. /// <returns>Task.</returns>
  216. private async Task InstallIsoMounters(CancellationToken cancellationToken)
  217. {
  218. var list = new List<IIsoMounter>();
  219. foreach (var isoMounter in GetExports<IIsoMounter>())
  220. {
  221. try
  222. {
  223. if (isoMounter.RequiresInstallation && !isoMounter.IsInstalled)
  224. {
  225. Logger.Info("Installing {0}", isoMounter.Name);
  226. await isoMounter.Install(cancellationToken).ConfigureAwait(false);
  227. }
  228. list.Add(isoMounter);
  229. }
  230. catch (Exception ex)
  231. {
  232. Logger.ErrorException("{0} failed to load.", ex, isoMounter.Name);
  233. }
  234. }
  235. IsoManager.AddParts(list);
  236. }
  237. /// <summary>
  238. /// Runs the startup tasks.
  239. /// </summary>
  240. /// <returns>Task.</returns>
  241. public virtual Task RunStartupTasks()
  242. {
  243. return Task.Run(() =>
  244. {
  245. Resolve<ITaskManager>().AddTasks(GetExports<IScheduledTask>(false));
  246. Task.Run(() => ConfigureAutorun());
  247. ConfigurationManager.ConfigurationUpdated += OnConfigurationUpdated;
  248. });
  249. }
  250. /// <summary>
  251. /// Configures the autorun.
  252. /// </summary>
  253. private void ConfigureAutorun()
  254. {
  255. try
  256. {
  257. ConfigureAutoRunAtStartup(ConfigurationManager.CommonConfiguration.RunAtStartup);
  258. }
  259. catch (Exception ex)
  260. {
  261. Logger.ErrorException("Error configuring autorun", ex);
  262. }
  263. }
  264. /// <summary>
  265. /// Gets the composable part assemblies.
  266. /// </summary>
  267. /// <returns>IEnumerable{Assembly}.</returns>
  268. protected abstract IEnumerable<Assembly> GetComposablePartAssemblies();
  269. /// <summary>
  270. /// Gets the configuration manager.
  271. /// </summary>
  272. /// <returns>IConfigurationManager.</returns>
  273. protected abstract IConfigurationManager GetConfigurationManager();
  274. /// <summary>
  275. /// Finds the parts.
  276. /// </summary>
  277. protected virtual void FindParts()
  278. {
  279. Plugins = GetExports<IPlugin>();
  280. }
  281. /// <summary>
  282. /// Discovers the types.
  283. /// </summary>
  284. protected void DiscoverTypes()
  285. {
  286. FailedAssemblies.Clear();
  287. var assemblies = GetComposablePartAssemblies().ToList();
  288. foreach (var assembly in assemblies)
  289. {
  290. Logger.Info("Loading {0}", assembly.FullName);
  291. }
  292. AllTypes = assemblies.SelectMany(GetTypes).ToArray();
  293. AllConcreteTypes = AllTypes.Where(t => t.IsClass && !t.IsAbstract && !t.IsInterface && !t.IsGenericType).ToArray();
  294. }
  295. /// <summary>
  296. /// Registers resources that classes will depend on
  297. /// </summary>
  298. /// <returns>Task.</returns>
  299. protected virtual Task RegisterResources(IProgress<double> progress)
  300. {
  301. return Task.Run(() =>
  302. {
  303. RegisterSingleInstance(ConfigurationManager);
  304. RegisterSingleInstance<IApplicationHost>(this);
  305. RegisterSingleInstance<IApplicationPaths>(ApplicationPaths);
  306. TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, Logger);
  307. RegisterSingleInstance(JsonSerializer);
  308. RegisterSingleInstance(XmlSerializer);
  309. RegisterSingleInstance(LogManager);
  310. RegisterSingleInstance(Logger);
  311. RegisterSingleInstance(TaskManager);
  312. FileSystemManager = CreateFileSystemManager();
  313. RegisterSingleInstance(FileSystemManager);
  314. HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, Logger, FileSystemManager);
  315. RegisterSingleInstance(HttpClient);
  316. NetworkManager = CreateNetworkManager();
  317. RegisterSingleInstance(NetworkManager);
  318. SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, NetworkManager, LogManager);
  319. RegisterSingleInstance(SecurityManager);
  320. InstallationManager = new InstallationManager(Logger, this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, NetworkManager, ConfigurationManager);
  321. RegisterSingleInstance(InstallationManager);
  322. ZipClient = new ZipClient();
  323. RegisterSingleInstance(ZipClient);
  324. IsoManager = new IsoManager();
  325. RegisterSingleInstance(IsoManager);
  326. });
  327. }
  328. protected virtual IFileSystem CreateFileSystemManager()
  329. {
  330. return new CommonFileSystem(Logger, true);
  331. }
  332. /// <summary>
  333. /// Gets a list of types within an assembly
  334. /// This will handle situations that would normally throw an exception - such as a type within the assembly that depends on some other non-existant reference
  335. /// </summary>
  336. /// <param name="assembly">The assembly.</param>
  337. /// <returns>IEnumerable{Type}.</returns>
  338. /// <exception cref="System.ArgumentNullException">assembly</exception>
  339. protected IEnumerable<Type> GetTypes(Assembly assembly)
  340. {
  341. if (assembly == null)
  342. {
  343. throw new ArgumentNullException("assembly");
  344. }
  345. try
  346. {
  347. return assembly.GetTypes();
  348. }
  349. catch (ReflectionTypeLoadException ex)
  350. {
  351. // If it fails we can still get a list of the Types it was able to resolve
  352. return ex.Types.Where(t => t != null);
  353. }
  354. }
  355. protected abstract INetworkManager CreateNetworkManager();
  356. /// <summary>
  357. /// Creates an instance of type and resolves all constructor dependancies
  358. /// </summary>
  359. /// <param name="type">The type.</param>
  360. /// <returns>System.Object.</returns>
  361. public object CreateInstance(Type type)
  362. {
  363. try
  364. {
  365. return Container.GetInstance(type);
  366. }
  367. catch (Exception ex)
  368. {
  369. Logger.Error("Error creating {0}", ex, type.Name);
  370. throw;
  371. }
  372. }
  373. /// <summary>
  374. /// Creates the instance safe.
  375. /// </summary>
  376. /// <param name="type">The type.</param>
  377. /// <returns>System.Object.</returns>
  378. protected object CreateInstanceSafe(Type type)
  379. {
  380. try
  381. {
  382. return Container.GetInstance(type);
  383. }
  384. catch (Exception ex)
  385. {
  386. Logger.Error("Error creating {0}", ex, type.Name);
  387. // Don't blow up in release mode
  388. return null;
  389. }
  390. }
  391. /// <summary>
  392. /// Registers the specified obj.
  393. /// </summary>
  394. /// <typeparam name="T"></typeparam>
  395. /// <param name="obj">The obj.</param>
  396. /// <param name="manageLifetime">if set to <c>true</c> [manage lifetime].</param>
  397. protected void RegisterSingleInstance<T>(T obj, bool manageLifetime = true)
  398. where T : class
  399. {
  400. Container.RegisterSingle(obj);
  401. if (manageLifetime)
  402. {
  403. var disposable = obj as IDisposable;
  404. if (disposable != null)
  405. {
  406. DisposableParts.Add(disposable);
  407. }
  408. }
  409. }
  410. /// <summary>
  411. /// Registers the single instance.
  412. /// </summary>
  413. /// <typeparam name="T"></typeparam>
  414. /// <param name="func">The func.</param>
  415. protected void RegisterSingleInstance<T>(Func<T> func)
  416. where T : class
  417. {
  418. Container.RegisterSingle(func);
  419. }
  420. /// <summary>
  421. /// Resolves this instance.
  422. /// </summary>
  423. /// <typeparam name="T"></typeparam>
  424. /// <returns>``0.</returns>
  425. public T Resolve<T>()
  426. {
  427. return (T)Container.GetRegistration(typeof(T), true).GetInstance();
  428. }
  429. /// <summary>
  430. /// Resolves this instance.
  431. /// </summary>
  432. /// <typeparam name="T"></typeparam>
  433. /// <returns>``0.</returns>
  434. public T TryResolve<T>()
  435. {
  436. var result = Container.GetRegistration(typeof(T), false);
  437. if (result == null)
  438. {
  439. return default(T);
  440. }
  441. return (T)result.GetInstance();
  442. }
  443. /// <summary>
  444. /// Loads the assembly.
  445. /// </summary>
  446. /// <param name="file">The file.</param>
  447. /// <returns>Assembly.</returns>
  448. protected Assembly LoadAssembly(string file)
  449. {
  450. try
  451. {
  452. return Assembly.Load(File.ReadAllBytes((file)));
  453. }
  454. catch (Exception ex)
  455. {
  456. FailedAssemblies.Add(file);
  457. Logger.ErrorException("Error loading assembly {0}", ex, file);
  458. return null;
  459. }
  460. }
  461. /// <summary>
  462. /// Gets the export types.
  463. /// </summary>
  464. /// <typeparam name="T"></typeparam>
  465. /// <returns>IEnumerable{Type}.</returns>
  466. public IEnumerable<Type> GetExportTypes<T>()
  467. {
  468. var currentType = typeof(T);
  469. return AllConcreteTypes.AsParallel().Where(currentType.IsAssignableFrom);
  470. }
  471. /// <summary>
  472. /// Gets the exports.
  473. /// </summary>
  474. /// <typeparam name="T"></typeparam>
  475. /// <param name="manageLiftime">if set to <c>true</c> [manage liftime].</param>
  476. /// <returns>IEnumerable{``0}.</returns>
  477. public IEnumerable<T> GetExports<T>(bool manageLiftime = true)
  478. {
  479. var parts = GetExportTypes<T>()
  480. .Select(CreateInstanceSafe)
  481. .Where(i => i != null)
  482. .Cast<T>()
  483. .ToList();
  484. if (manageLiftime)
  485. {
  486. lock (DisposableParts)
  487. {
  488. DisposableParts.AddRange(parts.OfType<IDisposable>());
  489. }
  490. }
  491. return parts;
  492. }
  493. /// <summary>
  494. /// Gets the current application version
  495. /// </summary>
  496. /// <value>The application version.</value>
  497. public Version ApplicationVersion
  498. {
  499. get
  500. {
  501. return GetType().Assembly.GetName().Version;
  502. }
  503. }
  504. /// <summary>
  505. /// Handles the ConfigurationUpdated event of the ConfigurationManager control.
  506. /// </summary>
  507. /// <param name="sender">The source of the event.</param>
  508. /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
  509. /// <exception cref="System.NotImplementedException"></exception>
  510. protected virtual void OnConfigurationUpdated(object sender, EventArgs e)
  511. {
  512. ConfigureAutorun();
  513. }
  514. protected abstract void ConfigureAutoRunAtStartup(bool autorun);
  515. /// <summary>
  516. /// Removes the plugin.
  517. /// </summary>
  518. /// <param name="plugin">The plugin.</param>
  519. public void RemovePlugin(IPlugin plugin)
  520. {
  521. var list = Plugins.ToList();
  522. list.Remove(plugin);
  523. Plugins = list;
  524. }
  525. /// <summary>
  526. /// Gets a value indicating whether this instance can self restart.
  527. /// </summary>
  528. /// <value><c>true</c> if this instance can self restart; otherwise, <c>false</c>.</value>
  529. public abstract bool CanSelfRestart { get; }
  530. /// <summary>
  531. /// Notifies that the kernel that a change has been made that requires a restart
  532. /// </summary>
  533. public void NotifyPendingRestart()
  534. {
  535. HasPendingRestart = true;
  536. EventHelper.QueueEventIfNotNull(HasPendingRestartChanged, this, EventArgs.Empty, Logger);
  537. }
  538. /// <summary>
  539. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  540. /// </summary>
  541. public void Dispose()
  542. {
  543. Dispose(true);
  544. }
  545. /// <summary>
  546. /// Releases unmanaged and - optionally - managed resources.
  547. /// </summary>
  548. /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  549. protected virtual void Dispose(bool dispose)
  550. {
  551. if (dispose)
  552. {
  553. var type = GetType();
  554. Logger.Info("Disposing " + type.Name);
  555. var parts = DisposableParts.Distinct().Where(i => i.GetType() != type).ToList();
  556. DisposableParts.Clear();
  557. foreach (var part in parts)
  558. {
  559. Logger.Info("Disposing " + part.GetType().Name);
  560. part.Dispose();
  561. }
  562. }
  563. }
  564. /// <summary>
  565. /// Restarts this instance.
  566. /// </summary>
  567. public abstract Task Restart();
  568. /// <summary>
  569. /// Gets or sets a value indicating whether this instance can self update.
  570. /// </summary>
  571. /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
  572. public abstract bool CanSelfUpdate { get; }
  573. /// <summary>
  574. /// Checks for update.
  575. /// </summary>
  576. /// <param name="cancellationToken">The cancellation token.</param>
  577. /// <param name="progress">The progress.</param>
  578. /// <returns>Task{CheckForUpdateResult}.</returns>
  579. public abstract Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken,
  580. IProgress<double> progress);
  581. /// <summary>
  582. /// Updates the application.
  583. /// </summary>
  584. /// <param name="package">The package that contains the update</param>
  585. /// <param name="cancellationToken">The cancellation token.</param>
  586. /// <param name="progress">The progress.</param>
  587. /// <returns>Task.</returns>
  588. public abstract Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken,
  589. IProgress<double> progress);
  590. /// <summary>
  591. /// Shuts down.
  592. /// </summary>
  593. public abstract Task Shutdown();
  594. /// <summary>
  595. /// Called when [application updated].
  596. /// </summary>
  597. /// <param name="newVersion">The new version.</param>
  598. protected void OnApplicationUpdated(Version newVersion)
  599. {
  600. Logger.Info("Application has been updated to version {0}", newVersion);
  601. EventHelper.QueueEventIfNotNull(ApplicationUpdated, this, new GenericEventArgs<Version> { Argument = newVersion }, Logger);
  602. NotifyPendingRestart();
  603. }
  604. }
  605. }