InstallationManager.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. using MediaBrowser.Common.Configuration;
  2. using MediaBrowser.Common.Events;
  3. using MediaBrowser.Common.Net;
  4. using MediaBrowser.Common.Plugins;
  5. using MediaBrowser.Common.Progress;
  6. using MediaBrowser.Common.Security;
  7. using MediaBrowser.Common.Updates;
  8. using MediaBrowser.Model.Events;
  9. using MediaBrowser.Model.Logging;
  10. using MediaBrowser.Model.Serialization;
  11. using MediaBrowser.Model.Updates;
  12. using System;
  13. using System.Collections.Concurrent;
  14. using System.Collections.Generic;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Security.Cryptography;
  18. using System.Threading;
  19. using System.Threading.Tasks;
  20. namespace MediaBrowser.Common.Implementations.Updates
  21. {
  22. /// <summary>
  23. /// Manages all install, uninstall and update operations (both plugins and system)
  24. /// </summary>
  25. public class InstallationManager : IInstallationManager
  26. {
  27. public event EventHandler<InstallationEventArgs> PackageInstalling;
  28. public event EventHandler<InstallationEventArgs> PackageInstallationCompleted;
  29. public event EventHandler<InstallationFailedEventArgs> PackageInstallationFailed;
  30. public event EventHandler<InstallationEventArgs> PackageInstallationCancelled;
  31. /// <summary>
  32. /// The current installations
  33. /// </summary>
  34. public List<Tuple<InstallationInfo, CancellationTokenSource>> CurrentInstallations { get; set; }
  35. /// <summary>
  36. /// The completed installations
  37. /// </summary>
  38. public ConcurrentBag<InstallationInfo> CompletedInstallations { get; set; }
  39. #region PluginUninstalled Event
  40. /// <summary>
  41. /// Occurs when [plugin uninstalled].
  42. /// </summary>
  43. public event EventHandler<GenericEventArgs<IPlugin>> PluginUninstalled;
  44. /// <summary>
  45. /// Called when [plugin uninstalled].
  46. /// </summary>
  47. /// <param name="plugin">The plugin.</param>
  48. private void OnPluginUninstalled(IPlugin plugin)
  49. {
  50. EventHelper.FireEventIfNotNull(PluginUninstalled, this, new GenericEventArgs<IPlugin> { Argument = plugin }, _logger);
  51. }
  52. #endregion
  53. #region PluginUpdated Event
  54. /// <summary>
  55. /// Occurs when [plugin updated].
  56. /// </summary>
  57. public event EventHandler<GenericEventArgs<Tuple<IPlugin, PackageVersionInfo>>> PluginUpdated;
  58. /// <summary>
  59. /// Called when [plugin updated].
  60. /// </summary>
  61. /// <param name="plugin">The plugin.</param>
  62. /// <param name="newVersion">The new version.</param>
  63. private void OnPluginUpdated(IPlugin plugin, PackageVersionInfo newVersion)
  64. {
  65. _logger.Info("Plugin updated: {0} {1} {2}", newVersion.name, newVersion.versionStr ?? string.Empty, newVersion.classification);
  66. EventHelper.FireEventIfNotNull(PluginUpdated, this, new GenericEventArgs<Tuple<IPlugin, PackageVersionInfo>> { Argument = new Tuple<IPlugin, PackageVersionInfo>(plugin, newVersion) }, _logger);
  67. _applicationHost.NotifyPendingRestart();
  68. }
  69. #endregion
  70. #region PluginInstalled Event
  71. /// <summary>
  72. /// Occurs when [plugin updated].
  73. /// </summary>
  74. public event EventHandler<GenericEventArgs<PackageVersionInfo>> PluginInstalled;
  75. /// <summary>
  76. /// Called when [plugin installed].
  77. /// </summary>
  78. /// <param name="package">The package.</param>
  79. private void OnPluginInstalled(PackageVersionInfo package)
  80. {
  81. _logger.Info("New plugin installed: {0} {1} {2}", package.name, package.versionStr ?? string.Empty, package.classification);
  82. EventHelper.FireEventIfNotNull(PluginInstalled, this, new GenericEventArgs<PackageVersionInfo> { Argument = package }, _logger);
  83. _applicationHost.NotifyPendingRestart();
  84. }
  85. #endregion
  86. /// <summary>
  87. /// The _logger
  88. /// </summary>
  89. private readonly ILogger _logger;
  90. private readonly IApplicationPaths _appPaths;
  91. private readonly IHttpClient _httpClient;
  92. private readonly IJsonSerializer _jsonSerializer;
  93. private readonly ISecurityManager _securityManager;
  94. private readonly INetworkManager _networkManager;
  95. private readonly IConfigurationManager _config;
  96. /// <summary>
  97. /// Gets the application host.
  98. /// </summary>
  99. /// <value>The application host.</value>
  100. private readonly IApplicationHost _applicationHost;
  101. public InstallationManager(ILogger logger, IApplicationHost appHost, IApplicationPaths appPaths, IHttpClient httpClient, IJsonSerializer jsonSerializer, ISecurityManager securityManager, INetworkManager networkManager, IConfigurationManager config)
  102. {
  103. if (logger == null)
  104. {
  105. throw new ArgumentNullException("logger");
  106. }
  107. CurrentInstallations = new List<Tuple<InstallationInfo, CancellationTokenSource>>();
  108. CompletedInstallations = new ConcurrentBag<InstallationInfo>();
  109. _applicationHost = appHost;
  110. _appPaths = appPaths;
  111. _httpClient = httpClient;
  112. _jsonSerializer = jsonSerializer;
  113. _securityManager = securityManager;
  114. _networkManager = networkManager;
  115. _config = config;
  116. _logger = logger;
  117. }
  118. private Version GetPackageVersion(PackageVersionInfo version)
  119. {
  120. return new Version(ValueOrDefault(version.versionStr, "0.0.0.1"));
  121. }
  122. private static string ValueOrDefault(string str, string def)
  123. {
  124. return string.IsNullOrEmpty(str) ? def : str;
  125. }
  126. /// <summary>
  127. /// Gets all available packages.
  128. /// </summary>
  129. /// <param name="cancellationToken">The cancellation token.</param>
  130. /// <param name="packageType">Type of the package.</param>
  131. /// <param name="applicationVersion">The application version.</param>
  132. /// <returns>Task{List{PackageInfo}}.</returns>
  133. public async Task<IEnumerable<PackageInfo>> GetAvailablePackages(CancellationToken cancellationToken,
  134. PackageType? packageType = null,
  135. Version applicationVersion = null)
  136. {
  137. var data = new Dictionary<string, string> { { "key", _securityManager.SupporterKey }, { "mac", _networkManager.GetMacAddress() } };
  138. using (var json = await _httpClient.Post(Constants.Constants.MbAdminUrl + "service/package/retrieveall", data, cancellationToken).ConfigureAwait(false))
  139. {
  140. cancellationToken.ThrowIfCancellationRequested();
  141. var packages = _jsonSerializer.DeserializeFromStream<List<PackageInfo>>(json).ToList();
  142. return FilterPackages(packages, packageType, applicationVersion);
  143. }
  144. }
  145. private Tuple<List<PackageInfo>, DateTime> _lastPackageListResult;
  146. /// <summary>
  147. /// Gets all available packages.
  148. /// </summary>
  149. /// <param name="cancellationToken">The cancellation token.</param>
  150. /// <returns>Task{List{PackageInfo}}.</returns>
  151. public async Task<IEnumerable<PackageInfo>> GetAvailablePackagesWithoutRegistrationInfo(CancellationToken cancellationToken)
  152. {
  153. if (_lastPackageListResult != null)
  154. {
  155. // Let dev users get results more often for testing purposes
  156. var cacheLength = _config.CommonConfiguration.SystemUpdateLevel == PackageVersionClass.Dev
  157. ? TimeSpan.FromMinutes(3)
  158. : TimeSpan.FromHours(6);
  159. if ((DateTime.UtcNow - _lastPackageListResult.Item2) < cacheLength)
  160. {
  161. return _lastPackageListResult.Item1;
  162. }
  163. }
  164. using (var json = await _httpClient.Get(Constants.Constants.MbAdminUrl + "service/MB3Packages.json", cancellationToken).ConfigureAwait(false))
  165. {
  166. cancellationToken.ThrowIfCancellationRequested();
  167. var packages = _jsonSerializer.DeserializeFromStream<List<PackageInfo>>(json).ToList();
  168. packages = FilterPackages(packages).ToList();
  169. _lastPackageListResult = new Tuple<List<PackageInfo>, DateTime>(packages, DateTime.UtcNow);
  170. return _lastPackageListResult.Item1;
  171. }
  172. }
  173. protected IEnumerable<PackageInfo> FilterPackages(List<PackageInfo> packages)
  174. {
  175. foreach (var package in packages)
  176. {
  177. package.versions = package.versions.Where(v => !string.IsNullOrWhiteSpace(v.sourceUrl))
  178. .OrderByDescending(GetPackageVersion).ToList();
  179. }
  180. // Remove packages with no versions
  181. packages = packages.Where(p => p.versions.Any()).ToList();
  182. return packages;
  183. }
  184. protected IEnumerable<PackageInfo> FilterPackages(List<PackageInfo> packages, PackageType? packageType, Version applicationVersion)
  185. {
  186. foreach (var package in packages)
  187. {
  188. package.versions = package.versions.Where(v => !string.IsNullOrWhiteSpace(v.sourceUrl))
  189. .OrderByDescending(GetPackageVersion).ToList();
  190. }
  191. if (packageType.HasValue)
  192. {
  193. packages = packages.Where(p => p.type == packageType.Value).ToList();
  194. }
  195. // If an app version was supplied, filter the versions for each package to only include supported versions
  196. if (applicationVersion != null)
  197. {
  198. foreach (var package in packages)
  199. {
  200. package.versions = package.versions.Where(v => IsPackageVersionUpToDate(v, applicationVersion)).ToList();
  201. }
  202. }
  203. // Remove packages with no versions
  204. packages = packages.Where(p => p.versions.Any()).ToList();
  205. return packages;
  206. }
  207. /// <summary>
  208. /// Determines whether [is package version up to date] [the specified package version info].
  209. /// </summary>
  210. /// <param name="packageVersionInfo">The package version info.</param>
  211. /// <param name="currentServerVersion">The current server version.</param>
  212. /// <returns><c>true</c> if [is package version up to date] [the specified package version info]; otherwise, <c>false</c>.</returns>
  213. private bool IsPackageVersionUpToDate(PackageVersionInfo packageVersionInfo, Version currentServerVersion)
  214. {
  215. if (string.IsNullOrEmpty(packageVersionInfo.requiredVersionStr))
  216. {
  217. return true;
  218. }
  219. Version requiredVersion;
  220. return Version.TryParse(packageVersionInfo.requiredVersionStr, out requiredVersion) && currentServerVersion >= requiredVersion;
  221. }
  222. /// <summary>
  223. /// Gets the package.
  224. /// </summary>
  225. /// <param name="name">The name.</param>
  226. /// <param name="guid">The assembly guid</param>
  227. /// <param name="classification">The classification.</param>
  228. /// <param name="version">The version.</param>
  229. /// <returns>Task{PackageVersionInfo}.</returns>
  230. public async Task<PackageVersionInfo> GetPackage(string name, string guid, PackageVersionClass classification, Version version)
  231. {
  232. var packages = await GetAvailablePackages(CancellationToken.None).ConfigureAwait(false);
  233. var package = packages.FirstOrDefault(p => string.Equals(p.guid, guid ?? "none", StringComparison.OrdinalIgnoreCase))
  234. ?? packages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase));
  235. if (package == null)
  236. {
  237. return null;
  238. }
  239. return package.versions.FirstOrDefault(v => GetPackageVersion(v).Equals(version) && v.classification == classification);
  240. }
  241. /// <summary>
  242. /// Gets the latest compatible version.
  243. /// </summary>
  244. /// <param name="name">The name.</param>
  245. /// <param name="guid">The assembly guid if this is a plug-in</param>
  246. /// <param name="currentServerVersion">The current server version.</param>
  247. /// <param name="classification">The classification.</param>
  248. /// <returns>Task{PackageVersionInfo}.</returns>
  249. public async Task<PackageVersionInfo> GetLatestCompatibleVersion(string name, string guid, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release)
  250. {
  251. var packages = await GetAvailablePackages(CancellationToken.None).ConfigureAwait(false);
  252. return GetLatestCompatibleVersion(packages, name, guid, currentServerVersion, classification);
  253. }
  254. /// <summary>
  255. /// Gets the latest compatible version.
  256. /// </summary>
  257. /// <param name="availablePackages">The available packages.</param>
  258. /// <param name="name">The name.</param>
  259. /// <param name="currentServerVersion">The current server version.</param>
  260. /// <param name="classification">The classification.</param>
  261. /// <returns>PackageVersionInfo.</returns>
  262. public PackageVersionInfo GetLatestCompatibleVersion(IEnumerable<PackageInfo> availablePackages, string name, string guid, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release)
  263. {
  264. var package = availablePackages.FirstOrDefault(p => string.Equals(p.guid, guid ?? "none", StringComparison.OrdinalIgnoreCase))
  265. ?? availablePackages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase));
  266. if (package == null)
  267. {
  268. return null;
  269. }
  270. return package.versions
  271. .OrderByDescending(GetPackageVersion)
  272. .FirstOrDefault(v => v.classification <= classification && IsPackageVersionUpToDate(v, currentServerVersion));
  273. }
  274. /// <summary>
  275. /// Gets the available plugin updates.
  276. /// </summary>
  277. /// <param name="applicationVersion">The current server version.</param>
  278. /// <param name="withAutoUpdateEnabled">if set to <c>true</c> [with auto update enabled].</param>
  279. /// <param name="cancellationToken">The cancellation token.</param>
  280. /// <returns>Task{IEnumerable{PackageVersionInfo}}.</returns>
  281. public async Task<IEnumerable<PackageVersionInfo>> GetAvailablePluginUpdates(Version applicationVersion, bool withAutoUpdateEnabled, CancellationToken cancellationToken)
  282. {
  283. var catalog = await GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
  284. var plugins = _applicationHost.Plugins.ToList();
  285. if (withAutoUpdateEnabled)
  286. {
  287. plugins = plugins
  288. .Where(p => _config.CommonConfiguration.EnableAutoUpdate)
  289. .ToList();
  290. }
  291. // Figure out what needs to be installed
  292. var packages = plugins.Select(p =>
  293. {
  294. var latestPluginInfo = GetLatestCompatibleVersion(catalog, p.Name, p.Id.ToString(), applicationVersion, _config.CommonConfiguration.SystemUpdateLevel);
  295. return latestPluginInfo != null && GetPackageVersion(latestPluginInfo) > p.Version ? latestPluginInfo : null;
  296. }).Where(i => i != null).ToList();
  297. return packages
  298. .Where(p => !string.IsNullOrWhiteSpace(p.sourceUrl) && !CompletedInstallations.Any(i => string.Equals(i.AssemblyGuid, p.guid, StringComparison.OrdinalIgnoreCase)));
  299. }
  300. /// <summary>
  301. /// Installs the package.
  302. /// </summary>
  303. /// <param name="package">The package.</param>
  304. /// <param name="progress">The progress.</param>
  305. /// <param name="cancellationToken">The cancellation token.</param>
  306. /// <returns>Task.</returns>
  307. /// <exception cref="System.ArgumentNullException">package</exception>
  308. public async Task InstallPackage(PackageVersionInfo package, IProgress<double> progress, CancellationToken cancellationToken)
  309. {
  310. if (package == null)
  311. {
  312. throw new ArgumentNullException("package");
  313. }
  314. if (progress == null)
  315. {
  316. throw new ArgumentNullException("progress");
  317. }
  318. var installationInfo = new InstallationInfo
  319. {
  320. Id = Guid.NewGuid().ToString("N"),
  321. Name = package.name,
  322. AssemblyGuid = package.guid,
  323. UpdateClass = package.classification,
  324. Version = package.versionStr
  325. };
  326. var innerCancellationTokenSource = new CancellationTokenSource();
  327. var tuple = new Tuple<InstallationInfo, CancellationTokenSource>(installationInfo, innerCancellationTokenSource);
  328. // Add it to the in-progress list
  329. lock (CurrentInstallations)
  330. {
  331. CurrentInstallations.Add(tuple);
  332. }
  333. var innerProgress = new ActionableProgress<double>();
  334. // Whenever the progress updates, update the outer progress object and InstallationInfo
  335. innerProgress.RegisterAction(percent =>
  336. {
  337. progress.Report(percent);
  338. installationInfo.PercentComplete = percent;
  339. });
  340. var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, innerCancellationTokenSource.Token).Token;
  341. var installationEventArgs = new InstallationEventArgs
  342. {
  343. InstallationInfo = installationInfo,
  344. PackageVersionInfo = package
  345. };
  346. EventHelper.FireEventIfNotNull(PackageInstalling, this, installationEventArgs, _logger);
  347. try
  348. {
  349. await InstallPackageInternal(package, innerProgress, linkedToken).ConfigureAwait(false);
  350. lock (CurrentInstallations)
  351. {
  352. CurrentInstallations.Remove(tuple);
  353. }
  354. progress.Report(100);
  355. CompletedInstallations.Add(installationInfo);
  356. EventHelper.FireEventIfNotNull(PackageInstallationCompleted, this, installationEventArgs, _logger);
  357. }
  358. catch (OperationCanceledException)
  359. {
  360. lock (CurrentInstallations)
  361. {
  362. CurrentInstallations.Remove(tuple);
  363. }
  364. _logger.Info("Package installation cancelled: {0} {1}", package.name, package.versionStr);
  365. EventHelper.FireEventIfNotNull(PackageInstallationCancelled, this, installationEventArgs, _logger);
  366. throw;
  367. }
  368. catch (Exception ex)
  369. {
  370. _logger.ErrorException("Package installation failed", ex);
  371. lock (CurrentInstallations)
  372. {
  373. CurrentInstallations.Remove(tuple);
  374. }
  375. EventHelper.FireEventIfNotNull(PackageInstallationFailed, this, new InstallationFailedEventArgs
  376. {
  377. InstallationInfo = installationInfo,
  378. Exception = ex
  379. }, _logger);
  380. throw;
  381. }
  382. finally
  383. {
  384. // Dispose the progress object and remove the installation from the in-progress list
  385. innerProgress.Dispose();
  386. tuple.Item2.Dispose();
  387. }
  388. }
  389. /// <summary>
  390. /// Installs the package internal.
  391. /// </summary>
  392. /// <param name="package">The package.</param>
  393. /// <param name="progress">The progress.</param>
  394. /// <param name="cancellationToken">The cancellation token.</param>
  395. /// <returns>Task.</returns>
  396. private async Task InstallPackageInternal(PackageVersionInfo package, IProgress<double> progress, CancellationToken cancellationToken)
  397. {
  398. // Do the install
  399. await PerformPackageInstallation(progress, package, cancellationToken).ConfigureAwait(false);
  400. var extension = Path.GetExtension(package.targetFilename) ?? "";
  401. // Do plugin-specific processing
  402. if (!string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase) && !string.Equals(extension, ".rar", StringComparison.OrdinalIgnoreCase) && !string.Equals(extension, ".7z", StringComparison.OrdinalIgnoreCase))
  403. {
  404. // Set last update time if we were installed before
  405. var plugin = _applicationHost.Plugins.FirstOrDefault(p => string.Equals(p.Id.ToString(), package.guid, StringComparison.OrdinalIgnoreCase))
  406. ?? _applicationHost.Plugins.FirstOrDefault(p => p.Name.Equals(package.name, StringComparison.OrdinalIgnoreCase));
  407. if (plugin != null)
  408. {
  409. OnPluginUpdated(plugin, package);
  410. }
  411. else
  412. {
  413. OnPluginInstalled(package);
  414. }
  415. }
  416. }
  417. private async Task PerformPackageInstallation(IProgress<double> progress, PackageVersionInfo package, CancellationToken cancellationToken)
  418. {
  419. // Target based on if it is an archive or single assembly
  420. // zip archives are assumed to contain directory structures relative to our ProgramDataPath
  421. var extension = Path.GetExtension(package.targetFilename);
  422. var isArchive = string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".rar", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".7z", StringComparison.OrdinalIgnoreCase);
  423. var target = Path.Combine(isArchive ? _appPaths.TempUpdatePath : _appPaths.PluginsPath, package.targetFilename);
  424. // Download to temporary file so that, if interrupted, it won't destroy the existing installation
  425. var tempFile = await _httpClient.GetTempFile(new HttpRequestOptions
  426. {
  427. Url = package.sourceUrl,
  428. CancellationToken = cancellationToken,
  429. Progress = progress
  430. }).ConfigureAwait(false);
  431. cancellationToken.ThrowIfCancellationRequested();
  432. // Validate with a checksum
  433. var packageChecksum = string.IsNullOrWhiteSpace(package.checksum) ? Guid.Empty : new Guid(package.checksum);
  434. if (packageChecksum != Guid.Empty) // support for legacy uploads for now
  435. {
  436. using (var crypto = new MD5CryptoServiceProvider())
  437. using (var stream = new BufferedStream(File.OpenRead(tempFile), 100000))
  438. {
  439. var check = Guid.Parse(BitConverter.ToString(crypto.ComputeHash(stream)).Replace("-", String.Empty));
  440. if (check != packageChecksum)
  441. {
  442. throw new ApplicationException(string.Format("Download validation failed for {0}. Probably corrupted during transfer.", package.name));
  443. }
  444. }
  445. }
  446. cancellationToken.ThrowIfCancellationRequested();
  447. // Success - move it to the real target
  448. try
  449. {
  450. Directory.CreateDirectory(Path.GetDirectoryName(target));
  451. File.Copy(tempFile, target, true);
  452. //If it is an archive - write out a version file so we know what it is
  453. if (isArchive)
  454. {
  455. File.WriteAllText(target + ".ver", package.versionStr);
  456. }
  457. }
  458. catch (IOException e)
  459. {
  460. _logger.ErrorException("Error attempting to move file from {0} to {1}", e, tempFile, target);
  461. throw;
  462. }
  463. try
  464. {
  465. File.Delete(tempFile);
  466. }
  467. catch (IOException e)
  468. {
  469. // Don't fail because of this
  470. _logger.ErrorException("Error deleting temp file {0]", e, tempFile);
  471. }
  472. }
  473. /// <summary>
  474. /// Uninstalls a plugin
  475. /// </summary>
  476. /// <param name="plugin">The plugin.</param>
  477. /// <exception cref="System.ArgumentException"></exception>
  478. public void UninstallPlugin(IPlugin plugin)
  479. {
  480. plugin.OnUninstalling();
  481. // Remove it the quick way for now
  482. _applicationHost.RemovePlugin(plugin);
  483. File.Delete(plugin.AssemblyFilePath);
  484. OnPluginUninstalled(plugin);
  485. _applicationHost.NotifyPendingRestart();
  486. }
  487. /// <summary>
  488. /// Releases unmanaged and - optionally - managed resources.
  489. /// </summary>
  490. /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  491. protected virtual void Dispose(bool dispose)
  492. {
  493. if (dispose)
  494. {
  495. lock (CurrentInstallations)
  496. {
  497. foreach (var tuple in CurrentInstallations)
  498. {
  499. tuple.Item2.Dispose();
  500. }
  501. CurrentInstallations.Clear();
  502. }
  503. }
  504. }
  505. public void Dispose()
  506. {
  507. Dispose(true);
  508. }
  509. }
  510. }