2
0

BaseApplicationHost.cs 24 KB

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