BaseApplicationHost.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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. // https://github.com/ServiceStack/ServiceStack/blob/master/tests/ServiceStack.WebHost.IntegrationTests/Web.config#L4
  161. Licensing.RegisterLicense("1001-e1JlZjoxMDAxLE5hbWU6VGVzdCBCdXNpbmVzcyxUeXBlOkJ1c2luZXNzLEhhc2g6UHVNTVRPclhvT2ZIbjQ5MG5LZE1mUTd5RUMzQnBucTFEbTE3TDczVEF4QUNMT1FhNXJMOWkzVjFGL2ZkVTE3Q2pDNENqTkQyUktRWmhvUVBhYTBiekJGUUZ3ZE5aZHFDYm9hL3lydGlwUHI5K1JsaTBYbzNsUC85cjVJNHE5QVhldDN6QkE4aTlvdldrdTgyTk1relY2eis2dFFqTThYN2lmc0JveHgycFdjPSxFeHBpcnk6MjAxMy0wMS0wMX0=");
  162. JsonSerializer = CreateJsonSerializer();
  163. IsFirstRun = !ConfigurationManager.CommonConfiguration.IsStartupWizardCompleted;
  164. Logger = LogManager.GetLogger("App");
  165. LogManager.LogSeverity = ConfigurationManager.CommonConfiguration.EnableDebugLevelLogging
  166. ? LogSeverity.Debug
  167. : LogSeverity.Info;
  168. OnLoggerLoaded();
  169. DiscoverTypes();
  170. Logger.Info("Version {0} initializing", ApplicationVersion);
  171. SetHttpLimit();
  172. await RegisterResources().ConfigureAwait(false);
  173. FindParts();
  174. await InstallIsoMounters(CancellationToken.None).ConfigureAwait(false);
  175. }
  176. /// <summary>
  177. /// Called when [logger loaded].
  178. /// </summary>
  179. protected virtual void OnLoggerLoaded()
  180. {
  181. }
  182. protected virtual IJsonSerializer CreateJsonSerializer()
  183. {
  184. return new JsonSerializer();
  185. }
  186. private void SetHttpLimit()
  187. {
  188. try
  189. {
  190. // Increase the max http request limit
  191. ServicePointManager.DefaultConnectionLimit = Math.Max(96, ServicePointManager.DefaultConnectionLimit);
  192. }
  193. catch (Exception ex)
  194. {
  195. Logger.ErrorException("Error setting http limit", ex);
  196. }
  197. }
  198. /// <summary>
  199. /// Installs the iso mounters.
  200. /// </summary>
  201. /// <param name="cancellationToken">The cancellation token.</param>
  202. /// <returns>Task.</returns>
  203. private async Task InstallIsoMounters(CancellationToken cancellationToken)
  204. {
  205. var list = new List<IIsoMounter>();
  206. foreach (var isoMounter in GetExports<IIsoMounter>())
  207. {
  208. try
  209. {
  210. if (isoMounter.RequiresInstallation && !isoMounter.IsInstalled)
  211. {
  212. Logger.Info("Installing {0}", isoMounter.Name);
  213. await isoMounter.Install(cancellationToken).ConfigureAwait(false);
  214. }
  215. list.Add(isoMounter);
  216. }
  217. catch (Exception ex)
  218. {
  219. Logger.ErrorException("{0} failed to load.", ex, isoMounter.Name);
  220. }
  221. }
  222. IsoManager.AddParts(list);
  223. }
  224. /// <summary>
  225. /// Runs the startup tasks.
  226. /// </summary>
  227. /// <returns>Task.</returns>
  228. public virtual Task RunStartupTasks()
  229. {
  230. return Task.Run(() =>
  231. {
  232. Resolve<ITaskManager>().AddTasks(GetExports<IScheduledTask>(false));
  233. Task.Run(() => ConfigureAutorun());
  234. ConfigurationManager.ConfigurationUpdated += OnConfigurationUpdated;
  235. });
  236. }
  237. /// <summary>
  238. /// Configures the autorun.
  239. /// </summary>
  240. private void ConfigureAutorun()
  241. {
  242. try
  243. {
  244. ConfigureAutoRunAtStartup(ConfigurationManager.CommonConfiguration.RunAtStartup);
  245. }
  246. catch (Exception ex)
  247. {
  248. Logger.ErrorException("Error configuring autorun", ex);
  249. }
  250. }
  251. /// <summary>
  252. /// Gets the composable part assemblies.
  253. /// </summary>
  254. /// <returns>IEnumerable{Assembly}.</returns>
  255. protected abstract IEnumerable<Assembly> GetComposablePartAssemblies();
  256. /// <summary>
  257. /// Gets the configuration manager.
  258. /// </summary>
  259. /// <returns>IConfigurationManager.</returns>
  260. protected abstract IConfigurationManager GetConfigurationManager();
  261. /// <summary>
  262. /// Finds the parts.
  263. /// </summary>
  264. protected virtual void FindParts()
  265. {
  266. Plugins = GetExports<IPlugin>();
  267. }
  268. /// <summary>
  269. /// Discovers the types.
  270. /// </summary>
  271. protected void DiscoverTypes()
  272. {
  273. FailedAssemblies.Clear();
  274. var assemblies = GetComposablePartAssemblies().ToList();
  275. foreach (var assembly in assemblies)
  276. {
  277. Logger.Info("Loading {0}", assembly.FullName);
  278. }
  279. AllTypes = assemblies.SelectMany(GetTypes).ToArray();
  280. AllConcreteTypes = AllTypes.Where(t => t.IsClass && !t.IsAbstract && !t.IsInterface && !t.IsGenericType).ToArray();
  281. }
  282. /// <summary>
  283. /// Registers resources that classes will depend on
  284. /// </summary>
  285. /// <returns>Task.</returns>
  286. protected virtual Task RegisterResources()
  287. {
  288. return Task.Run(() =>
  289. {
  290. RegisterSingleInstance(ConfigurationManager);
  291. RegisterSingleInstance<IApplicationHost>(this);
  292. RegisterSingleInstance<IApplicationPaths>(ApplicationPaths);
  293. TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, Logger);
  294. RegisterSingleInstance(JsonSerializer);
  295. RegisterSingleInstance(XmlSerializer);
  296. RegisterSingleInstance(LogManager);
  297. RegisterSingleInstance(Logger);
  298. RegisterSingleInstance(TaskManager);
  299. FileSystemManager = CreateFileSystemManager();
  300. RegisterSingleInstance(FileSystemManager);
  301. HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, Logger, FileSystemManager);
  302. RegisterSingleInstance(HttpClient);
  303. NetworkManager = CreateNetworkManager();
  304. RegisterSingleInstance(NetworkManager);
  305. SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, NetworkManager);
  306. RegisterSingleInstance(SecurityManager);
  307. InstallationManager = new InstallationManager(Logger, this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, NetworkManager, ConfigurationManager);
  308. RegisterSingleInstance(InstallationManager);
  309. ZipClient = new ZipClient();
  310. RegisterSingleInstance(ZipClient);
  311. IsoManager = new IsoManager();
  312. RegisterSingleInstance(IsoManager);
  313. });
  314. }
  315. protected virtual IFileSystem CreateFileSystemManager()
  316. {
  317. return new CommonFileSystem(Logger, true);
  318. }
  319. /// <summary>
  320. /// Gets a list of types within an assembly
  321. /// 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
  322. /// </summary>
  323. /// <param name="assembly">The assembly.</param>
  324. /// <returns>IEnumerable{Type}.</returns>
  325. /// <exception cref="System.ArgumentNullException">assembly</exception>
  326. protected IEnumerable<Type> GetTypes(Assembly assembly)
  327. {
  328. if (assembly == null)
  329. {
  330. throw new ArgumentNullException("assembly");
  331. }
  332. try
  333. {
  334. return assembly.GetTypes();
  335. }
  336. catch (ReflectionTypeLoadException ex)
  337. {
  338. // If it fails we can still get a list of the Types it was able to resolve
  339. return ex.Types.Where(t => t != null);
  340. }
  341. }
  342. protected abstract INetworkManager CreateNetworkManager();
  343. /// <summary>
  344. /// Creates an instance of type and resolves all constructor dependancies
  345. /// </summary>
  346. /// <param name="type">The type.</param>
  347. /// <returns>System.Object.</returns>
  348. public object CreateInstance(Type type)
  349. {
  350. try
  351. {
  352. return Container.GetInstance(type);
  353. }
  354. catch (Exception ex)
  355. {
  356. Logger.Error("Error creating {0}", ex, type.Name);
  357. throw;
  358. }
  359. }
  360. /// <summary>
  361. /// Creates the instance safe.
  362. /// </summary>
  363. /// <param name="type">The type.</param>
  364. /// <returns>System.Object.</returns>
  365. protected object CreateInstanceSafe(Type type)
  366. {
  367. try
  368. {
  369. return Container.GetInstance(type);
  370. }
  371. catch (Exception ex)
  372. {
  373. Logger.Error("Error creating {0}", ex, type.Name);
  374. // Don't blow up in release mode
  375. return null;
  376. }
  377. }
  378. /// <summary>
  379. /// Registers the specified obj.
  380. /// </summary>
  381. /// <typeparam name="T"></typeparam>
  382. /// <param name="obj">The obj.</param>
  383. /// <param name="manageLifetime">if set to <c>true</c> [manage lifetime].</param>
  384. protected void RegisterSingleInstance<T>(T obj, bool manageLifetime = true)
  385. where T : class
  386. {
  387. Container.RegisterSingle(obj);
  388. if (manageLifetime)
  389. {
  390. var disposable = obj as IDisposable;
  391. if (disposable != null)
  392. {
  393. DisposableParts.Add(disposable);
  394. }
  395. }
  396. }
  397. /// <summary>
  398. /// Registers the single instance.
  399. /// </summary>
  400. /// <typeparam name="T"></typeparam>
  401. /// <param name="func">The func.</param>
  402. protected void RegisterSingleInstance<T>(Func<T> func)
  403. where T : class
  404. {
  405. Container.RegisterSingle(func);
  406. }
  407. /// <summary>
  408. /// Resolves this instance.
  409. /// </summary>
  410. /// <typeparam name="T"></typeparam>
  411. /// <returns>``0.</returns>
  412. public T Resolve<T>()
  413. {
  414. return (T)Container.GetRegistration(typeof(T), true).GetInstance();
  415. }
  416. /// <summary>
  417. /// Resolves this instance.
  418. /// </summary>
  419. /// <typeparam name="T"></typeparam>
  420. /// <returns>``0.</returns>
  421. public T TryResolve<T>()
  422. {
  423. var result = Container.GetRegistration(typeof(T), false);
  424. if (result == null)
  425. {
  426. return default(T);
  427. }
  428. return (T)result.GetInstance();
  429. }
  430. /// <summary>
  431. /// Loads the assembly.
  432. /// </summary>
  433. /// <param name="file">The file.</param>
  434. /// <returns>Assembly.</returns>
  435. protected Assembly LoadAssembly(string file)
  436. {
  437. try
  438. {
  439. return Assembly.Load(File.ReadAllBytes((file)));
  440. }
  441. catch (Exception ex)
  442. {
  443. FailedAssemblies.Add(file);
  444. Logger.ErrorException("Error loading assembly {0}", ex, file);
  445. return null;
  446. }
  447. }
  448. /// <summary>
  449. /// Gets the export types.
  450. /// </summary>
  451. /// <typeparam name="T"></typeparam>
  452. /// <returns>IEnumerable{Type}.</returns>
  453. public IEnumerable<Type> GetExportTypes<T>()
  454. {
  455. var currentType = typeof(T);
  456. return AllConcreteTypes.AsParallel().Where(currentType.IsAssignableFrom);
  457. }
  458. /// <summary>
  459. /// Gets the exports.
  460. /// </summary>
  461. /// <typeparam name="T"></typeparam>
  462. /// <param name="manageLiftime">if set to <c>true</c> [manage liftime].</param>
  463. /// <returns>IEnumerable{``0}.</returns>
  464. public IEnumerable<T> GetExports<T>(bool manageLiftime = true)
  465. {
  466. var parts = GetExportTypes<T>()
  467. .Select(CreateInstanceSafe)
  468. .Where(i => i != null)
  469. .Cast<T>()
  470. .ToList();
  471. if (manageLiftime)
  472. {
  473. lock (DisposableParts)
  474. {
  475. DisposableParts.AddRange(parts.OfType<IDisposable>());
  476. }
  477. }
  478. return parts;
  479. }
  480. /// <summary>
  481. /// Gets the current application version
  482. /// </summary>
  483. /// <value>The application version.</value>
  484. public Version ApplicationVersion
  485. {
  486. get
  487. {
  488. return GetType().Assembly.GetName().Version;
  489. }
  490. }
  491. /// <summary>
  492. /// Handles the ConfigurationUpdated event of the ConfigurationManager control.
  493. /// </summary>
  494. /// <param name="sender">The source of the event.</param>
  495. /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
  496. /// <exception cref="System.NotImplementedException"></exception>
  497. protected virtual void OnConfigurationUpdated(object sender, EventArgs e)
  498. {
  499. ConfigureAutorun();
  500. }
  501. protected abstract void ConfigureAutoRunAtStartup(bool autorun);
  502. /// <summary>
  503. /// Removes the plugin.
  504. /// </summary>
  505. /// <param name="plugin">The plugin.</param>
  506. public void RemovePlugin(IPlugin plugin)
  507. {
  508. var list = Plugins.ToList();
  509. list.Remove(plugin);
  510. Plugins = list;
  511. }
  512. /// <summary>
  513. /// Gets a value indicating whether this instance can self restart.
  514. /// </summary>
  515. /// <value><c>true</c> if this instance can self restart; otherwise, <c>false</c>.</value>
  516. public abstract bool CanSelfRestart { get; }
  517. /// <summary>
  518. /// Notifies that the kernel that a change has been made that requires a restart
  519. /// </summary>
  520. public void NotifyPendingRestart()
  521. {
  522. HasPendingRestart = true;
  523. EventHelper.QueueEventIfNotNull(HasPendingRestartChanged, this, EventArgs.Empty, Logger);
  524. }
  525. /// <summary>
  526. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  527. /// </summary>
  528. public void Dispose()
  529. {
  530. Dispose(true);
  531. }
  532. /// <summary>
  533. /// Releases unmanaged and - optionally - managed resources.
  534. /// </summary>
  535. /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  536. protected virtual void Dispose(bool dispose)
  537. {
  538. if (dispose)
  539. {
  540. var type = GetType();
  541. Logger.Info("Disposing " + type.Name);
  542. var parts = DisposableParts.Distinct().Where(i => i.GetType() != type).ToList();
  543. DisposableParts.Clear();
  544. foreach (var part in parts)
  545. {
  546. Logger.Info("Disposing " + part.GetType().Name);
  547. part.Dispose();
  548. }
  549. }
  550. }
  551. /// <summary>
  552. /// Restarts this instance.
  553. /// </summary>
  554. public abstract Task Restart();
  555. /// <summary>
  556. /// Gets or sets a value indicating whether this instance can self update.
  557. /// </summary>
  558. /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
  559. public abstract bool CanSelfUpdate { get; }
  560. /// <summary>
  561. /// Checks for update.
  562. /// </summary>
  563. /// <param name="cancellationToken">The cancellation token.</param>
  564. /// <param name="progress">The progress.</param>
  565. /// <returns>Task{CheckForUpdateResult}.</returns>
  566. public abstract Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken,
  567. IProgress<double> progress);
  568. /// <summary>
  569. /// Updates the application.
  570. /// </summary>
  571. /// <param name="package">The package that contains the update</param>
  572. /// <param name="cancellationToken">The cancellation token.</param>
  573. /// <param name="progress">The progress.</param>
  574. /// <returns>Task.</returns>
  575. public abstract Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken,
  576. IProgress<double> progress);
  577. /// <summary>
  578. /// Shuts down.
  579. /// </summary>
  580. public abstract Task Shutdown();
  581. /// <summary>
  582. /// Called when [application updated].
  583. /// </summary>
  584. /// <param name="newVersion">The new version.</param>
  585. protected void OnApplicationUpdated(Version newVersion)
  586. {
  587. Logger.Info("Application has been updated to version {0}", newVersion);
  588. EventHelper.QueueEventIfNotNull(ApplicationUpdated, this, new GenericEventArgs<Version> { Argument = newVersion }, Logger);
  589. NotifyPendingRestart();
  590. }
  591. }
  592. }