BaseApplicationHost.cs 24 KB

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