InstallationManager.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  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.QueueEventIfNotNull(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.version, newVersion.classification);
  66. EventHelper.QueueEventIfNotNull(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.version, package.classification);
  82. EventHelper.QueueEventIfNotNull(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. /// <summary>
  119. /// Gets all available packages.
  120. /// </summary>
  121. /// <param name="cancellationToken">The cancellation token.</param>
  122. /// <param name="packageType">Type of the package.</param>
  123. /// <param name="applicationVersion">The application version.</param>
  124. /// <returns>Task{List{PackageInfo}}.</returns>
  125. public async Task<IEnumerable<PackageInfo>> GetAvailablePackages(CancellationToken cancellationToken,
  126. PackageType? packageType = null,
  127. Version applicationVersion = null)
  128. {
  129. var data = new Dictionary<string, string> { { "key", _securityManager.SupporterKey }, { "mac", _networkManager.GetMacAddress() } };
  130. using (var json = await _httpClient.Post(Constants.Constants.MbAdminUrl + "service/package/retrieveall", data, cancellationToken).ConfigureAwait(false))
  131. {
  132. cancellationToken.ThrowIfCancellationRequested();
  133. var packages = _jsonSerializer.DeserializeFromStream<List<PackageInfo>>(json).ToList();
  134. return FilterPackages(packages, packageType, applicationVersion);
  135. }
  136. }
  137. private Tuple<List<PackageInfo>, DateTime> _lastPackageListResult;
  138. /// <summary>
  139. /// Gets all available packages.
  140. /// </summary>
  141. /// <param name="cancellationToken">The cancellation token.</param>
  142. /// <returns>Task{List{PackageInfo}}.</returns>
  143. public async Task<IEnumerable<PackageInfo>> GetAvailablePackagesWithoutRegistrationInfo(CancellationToken cancellationToken)
  144. {
  145. if (_lastPackageListResult != null)
  146. {
  147. // Let dev users get results more often for testing purposes
  148. var cacheLength = _config.CommonConfiguration.SystemUpdateLevel == PackageVersionClass.Dev
  149. ? TimeSpan.FromMinutes(5)
  150. : TimeSpan.FromHours(12);
  151. if ((DateTime.UtcNow - _lastPackageListResult.Item2) < cacheLength)
  152. {
  153. return _lastPackageListResult.Item1;
  154. }
  155. }
  156. using (var json = await _httpClient.Get(Constants.Constants.MbAdminUrl + "service/MB3Packages.json", cancellationToken).ConfigureAwait(false))
  157. {
  158. cancellationToken.ThrowIfCancellationRequested();
  159. var packages = _jsonSerializer.DeserializeFromStream<List<PackageInfo>>(json).ToList();
  160. packages = FilterPackages(packages).ToList();
  161. _lastPackageListResult = new Tuple<List<PackageInfo>, DateTime>(packages, DateTime.UtcNow);
  162. return _lastPackageListResult.Item1;
  163. }
  164. }
  165. protected IEnumerable<PackageInfo> FilterPackages(List<PackageInfo> packages)
  166. {
  167. foreach (var package in packages)
  168. {
  169. package.versions = package.versions.Where(v => !string.IsNullOrWhiteSpace(v.sourceUrl))
  170. .OrderByDescending(v => v.version).ToList();
  171. }
  172. // Remove packages with no versions
  173. packages = packages.Where(p => p.versions.Any()).ToList();
  174. return packages;
  175. }
  176. protected IEnumerable<PackageInfo> FilterPackages(List<PackageInfo> packages, PackageType? packageType, Version applicationVersion)
  177. {
  178. foreach (var package in packages)
  179. {
  180. package.versions = package.versions.Where(v => !string.IsNullOrWhiteSpace(v.sourceUrl))
  181. .OrderByDescending(v => v.version).ToList();
  182. }
  183. if (packageType.HasValue)
  184. {
  185. packages = packages.Where(p => p.type == packageType.Value).ToList();
  186. }
  187. // If an app version was supplied, filter the versions for each package to only include supported versions
  188. if (applicationVersion != null)
  189. {
  190. foreach (var package in packages)
  191. {
  192. package.versions = package.versions.Where(v => IsPackageVersionUpToDate(v, applicationVersion)).ToList();
  193. }
  194. }
  195. // Remove packages with no versions
  196. packages = packages.Where(p => p.versions.Any()).ToList();
  197. return packages;
  198. }
  199. /// <summary>
  200. /// Determines whether [is package version up to date] [the specified package version info].
  201. /// </summary>
  202. /// <param name="packageVersionInfo">The package version info.</param>
  203. /// <param name="currentServerVersion">The current server version.</param>
  204. /// <returns><c>true</c> if [is package version up to date] [the specified package version info]; otherwise, <c>false</c>.</returns>
  205. private bool IsPackageVersionUpToDate(PackageVersionInfo packageVersionInfo, Version currentServerVersion)
  206. {
  207. if (string.IsNullOrEmpty(packageVersionInfo.requiredVersionStr))
  208. {
  209. return true;
  210. }
  211. Version requiredVersion;
  212. return Version.TryParse(packageVersionInfo.requiredVersionStr, out requiredVersion) && currentServerVersion >= requiredVersion;
  213. }
  214. /// <summary>
  215. /// Gets the package.
  216. /// </summary>
  217. /// <param name="name">The name.</param>
  218. /// <param name="guid">The assembly guid</param>
  219. /// <param name="classification">The classification.</param>
  220. /// <param name="version">The version.</param>
  221. /// <returns>Task{PackageVersionInfo}.</returns>
  222. public async Task<PackageVersionInfo> GetPackage(string name, string guid, PackageVersionClass classification, Version version)
  223. {
  224. var packages = await GetAvailablePackages(CancellationToken.None).ConfigureAwait(false);
  225. var package = packages.FirstOrDefault(p => string.Equals(p.guid, guid ?? "none", StringComparison.OrdinalIgnoreCase))
  226. ?? packages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase));
  227. if (package == null)
  228. {
  229. return null;
  230. }
  231. return package.versions.FirstOrDefault(v => v.version.Equals(version) && v.classification == classification);
  232. }
  233. /// <summary>
  234. /// Gets the latest compatible version.
  235. /// </summary>
  236. /// <param name="name">The name.</param>
  237. /// <param name="guid">The assembly guid if this is a plug-in</param>
  238. /// <param name="currentServerVersion">The current server version.</param>
  239. /// <param name="classification">The classification.</param>
  240. /// <returns>Task{PackageVersionInfo}.</returns>
  241. public async Task<PackageVersionInfo> GetLatestCompatibleVersion(string name, string guid, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release)
  242. {
  243. var packages = await GetAvailablePackages(CancellationToken.None).ConfigureAwait(false);
  244. return GetLatestCompatibleVersion(packages, name, guid, currentServerVersion, classification);
  245. }
  246. /// <summary>
  247. /// Gets the latest compatible version.
  248. /// </summary>
  249. /// <param name="availablePackages">The available packages.</param>
  250. /// <param name="name">The name.</param>
  251. /// <param name="currentServerVersion">The current server version.</param>
  252. /// <param name="classification">The classification.</param>
  253. /// <returns>PackageVersionInfo.</returns>
  254. public PackageVersionInfo GetLatestCompatibleVersion(IEnumerable<PackageInfo> availablePackages, string name, string guid, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release)
  255. {
  256. var package = availablePackages.FirstOrDefault(p => string.Equals(p.guid, guid ?? "none", StringComparison.OrdinalIgnoreCase))
  257. ?? availablePackages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase));
  258. if (package == null)
  259. {
  260. return null;
  261. }
  262. return package.versions
  263. .OrderByDescending(v => v.version)
  264. .FirstOrDefault(v => v.classification <= classification && IsPackageVersionUpToDate(v, currentServerVersion));
  265. }
  266. /// <summary>
  267. /// Gets the available plugin updates.
  268. /// </summary>
  269. /// <param name="applicationVersion">The current server version.</param>
  270. /// <param name="withAutoUpdateEnabled">if set to <c>true</c> [with auto update enabled].</param>
  271. /// <param name="cancellationToken">The cancellation token.</param>
  272. /// <returns>Task{IEnumerable{PackageVersionInfo}}.</returns>
  273. public async Task<IEnumerable<PackageVersionInfo>> GetAvailablePluginUpdates(Version applicationVersion, bool withAutoUpdateEnabled, CancellationToken cancellationToken)
  274. {
  275. var catalog = await GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
  276. var plugins = _applicationHost.Plugins.ToList();
  277. if (withAutoUpdateEnabled)
  278. {
  279. plugins = plugins
  280. .Where(p => _config.CommonConfiguration.EnableAutoUpdate)
  281. .ToList();
  282. }
  283. // Figure out what needs to be installed
  284. var packages = plugins.Select(p =>
  285. {
  286. var latestPluginInfo = GetLatestCompatibleVersion(catalog, p.Name, p.Id.ToString(), applicationVersion, _config.CommonConfiguration.SystemUpdateLevel);
  287. return latestPluginInfo != null && latestPluginInfo.version != null && latestPluginInfo.version > p.Version ? latestPluginInfo : null;
  288. }).Where(i => i != null).ToList();
  289. return packages
  290. .Where(p => !string.IsNullOrWhiteSpace(p.sourceUrl) && !CompletedInstallations.Any(i => string.Equals(i.AssemblyGuid, p.guid, StringComparison.OrdinalIgnoreCase)));
  291. }
  292. /// <summary>
  293. /// Installs the package.
  294. /// </summary>
  295. /// <param name="package">The package.</param>
  296. /// <param name="progress">The progress.</param>
  297. /// <param name="cancellationToken">The cancellation token.</param>
  298. /// <returns>Task.</returns>
  299. /// <exception cref="System.ArgumentNullException">package</exception>
  300. public async Task InstallPackage(PackageVersionInfo package, IProgress<double> progress, CancellationToken cancellationToken)
  301. {
  302. if (package == null)
  303. {
  304. throw new ArgumentNullException("package");
  305. }
  306. if (progress == null)
  307. {
  308. throw new ArgumentNullException("progress");
  309. }
  310. var installationInfo = new InstallationInfo
  311. {
  312. Id = Guid.NewGuid().ToString("N"),
  313. Name = package.name,
  314. AssemblyGuid = package.guid,
  315. UpdateClass = package.classification,
  316. Version = package.versionStr
  317. };
  318. var innerCancellationTokenSource = new CancellationTokenSource();
  319. var tuple = new Tuple<InstallationInfo, CancellationTokenSource>(installationInfo, innerCancellationTokenSource);
  320. // Add it to the in-progress list
  321. lock (CurrentInstallations)
  322. {
  323. CurrentInstallations.Add(tuple);
  324. }
  325. var innerProgress = new ActionableProgress<double>();
  326. // Whenever the progress updates, update the outer progress object and InstallationInfo
  327. innerProgress.RegisterAction(percent =>
  328. {
  329. progress.Report(percent);
  330. installationInfo.PercentComplete = percent;
  331. });
  332. var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, innerCancellationTokenSource.Token).Token;
  333. var installationEventArgs = new InstallationEventArgs
  334. {
  335. InstallationInfo = installationInfo,
  336. PackageVersionInfo = package
  337. };
  338. EventHelper.QueueEventIfNotNull(PackageInstalling, this, installationEventArgs, _logger);
  339. try
  340. {
  341. await InstallPackageInternal(package, innerProgress, linkedToken).ConfigureAwait(false);
  342. lock (CurrentInstallations)
  343. {
  344. CurrentInstallations.Remove(tuple);
  345. }
  346. progress.Report(100);
  347. CompletedInstallations.Add(installationInfo);
  348. EventHelper.QueueEventIfNotNull(PackageInstallationCompleted, this, installationEventArgs, _logger);
  349. }
  350. catch (OperationCanceledException)
  351. {
  352. lock (CurrentInstallations)
  353. {
  354. CurrentInstallations.Remove(tuple);
  355. }
  356. _logger.Info("Package installation cancelled: {0} {1}", package.name, package.versionStr);
  357. EventHelper.QueueEventIfNotNull(PackageInstallationCancelled, this, installationEventArgs, _logger);
  358. throw;
  359. }
  360. catch (Exception ex)
  361. {
  362. _logger.ErrorException("Package installation failed", ex);
  363. lock (CurrentInstallations)
  364. {
  365. CurrentInstallations.Remove(tuple);
  366. }
  367. EventHelper.QueueEventIfNotNull(PackageInstallationFailed, this, new InstallationFailedEventArgs
  368. {
  369. InstallationInfo = installationInfo,
  370. Exception = ex
  371. }, _logger);
  372. throw;
  373. }
  374. finally
  375. {
  376. // Dispose the progress object and remove the installation from the in-progress list
  377. innerProgress.Dispose();
  378. tuple.Item2.Dispose();
  379. }
  380. }
  381. /// <summary>
  382. /// Installs the package internal.
  383. /// </summary>
  384. /// <param name="package">The package.</param>
  385. /// <param name="progress">The progress.</param>
  386. /// <param name="cancellationToken">The cancellation token.</param>
  387. /// <returns>Task.</returns>
  388. private async Task InstallPackageInternal(PackageVersionInfo package, IProgress<double> progress, CancellationToken cancellationToken)
  389. {
  390. // Do the install
  391. await PerformPackageInstallation(progress, package, cancellationToken).ConfigureAwait(false);
  392. var extension = Path.GetExtension(package.targetFilename) ?? "";
  393. // Do plugin-specific processing
  394. if (!string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase) && !string.Equals(extension, ".rar", StringComparison.OrdinalIgnoreCase) && !string.Equals(extension, ".7z", StringComparison.OrdinalIgnoreCase))
  395. {
  396. // Set last update time if we were installed before
  397. var plugin = _applicationHost.Plugins.FirstOrDefault(p => string.Equals(p.Id.ToString(), package.guid, StringComparison.OrdinalIgnoreCase))
  398. ?? _applicationHost.Plugins.FirstOrDefault(p => p.Name.Equals(package.name, StringComparison.OrdinalIgnoreCase));
  399. if (plugin != null)
  400. {
  401. OnPluginUpdated(plugin, package);
  402. }
  403. else
  404. {
  405. OnPluginInstalled(package);
  406. }
  407. }
  408. }
  409. private async Task PerformPackageInstallation(IProgress<double> progress, PackageVersionInfo package, CancellationToken cancellationToken)
  410. {
  411. // Target based on if it is an archive or single assembly
  412. // zip archives are assumed to contain directory structures relative to our ProgramDataPath
  413. var extension = Path.GetExtension(package.targetFilename);
  414. var isArchive = string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".rar", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".7z", StringComparison.OrdinalIgnoreCase);
  415. var target = Path.Combine(isArchive ? _appPaths.TempUpdatePath : _appPaths.PluginsPath, package.targetFilename);
  416. // Download to temporary file so that, if interrupted, it won't destroy the existing installation
  417. var tempFile = await _httpClient.GetTempFile(new HttpRequestOptions
  418. {
  419. Url = package.sourceUrl,
  420. CancellationToken = cancellationToken,
  421. Progress = progress
  422. }).ConfigureAwait(false);
  423. cancellationToken.ThrowIfCancellationRequested();
  424. // Validate with a checksum
  425. var packageChecksum = string.IsNullOrWhiteSpace(package.checksum) ? Guid.Empty : new Guid(package.checksum);
  426. if (packageChecksum != Guid.Empty) // support for legacy uploads for now
  427. {
  428. using (var crypto = new MD5CryptoServiceProvider())
  429. using (var stream = new BufferedStream(File.OpenRead(tempFile), 100000))
  430. {
  431. var check = Guid.Parse(BitConverter.ToString(crypto.ComputeHash(stream)).Replace("-", String.Empty));
  432. if (check != packageChecksum)
  433. {
  434. throw new ApplicationException(string.Format("Download validation failed for {0}. Probably corrupted during transfer.", package.name));
  435. }
  436. }
  437. }
  438. cancellationToken.ThrowIfCancellationRequested();
  439. // Success - move it to the real target
  440. try
  441. {
  442. Directory.CreateDirectory(Path.GetDirectoryName(target));
  443. File.Copy(tempFile, target, true);
  444. //If it is an archive - write out a version file so we know what it is
  445. if (isArchive)
  446. {
  447. File.WriteAllText(target + ".ver", package.versionStr);
  448. }
  449. }
  450. catch (IOException e)
  451. {
  452. _logger.ErrorException("Error attempting to move file from {0} to {1}", e, tempFile, target);
  453. throw;
  454. }
  455. try
  456. {
  457. File.Delete(tempFile);
  458. }
  459. catch (IOException e)
  460. {
  461. // Don't fail because of this
  462. _logger.ErrorException("Error deleting temp file {0]", e, tempFile);
  463. }
  464. }
  465. /// <summary>
  466. /// Uninstalls a plugin
  467. /// </summary>
  468. /// <param name="plugin">The plugin.</param>
  469. /// <exception cref="System.ArgumentException"></exception>
  470. public void UninstallPlugin(IPlugin plugin)
  471. {
  472. plugin.OnUninstalling();
  473. // Remove it the quick way for now
  474. _applicationHost.RemovePlugin(plugin);
  475. File.Delete(plugin.AssemblyFilePath);
  476. OnPluginUninstalled(plugin);
  477. _applicationHost.NotifyPendingRestart();
  478. }
  479. /// <summary>
  480. /// Releases unmanaged and - optionally - managed resources.
  481. /// </summary>
  482. /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  483. protected virtual void Dispose(bool dispose)
  484. {
  485. if (dispose)
  486. {
  487. lock (CurrentInstallations)
  488. {
  489. foreach (var tuple in CurrentInstallations)
  490. {
  491. tuple.Item2.Dispose();
  492. }
  493. CurrentInstallations.Clear();
  494. }
  495. }
  496. }
  497. public void Dispose()
  498. {
  499. Dispose(true);
  500. }
  501. }
  502. }