diff options
| author | Bond-009 <bond.009@outlook.com> | 2019-11-07 10:50:55 +0100 |
|---|---|---|
| committer | Bond-009 <bond.009@outlook.com> | 2019-11-07 10:50:55 +0100 |
| commit | 983d38a43bd617de11724196f35822f07860a2eb (patch) | |
| tree | 0eb15c7d7a5a4c270f966b6c4a8aee60f4a1a60e /Emby.Server.Implementations/Updates/InstallationManager.cs | |
| parent | 81c135c5bb01fbfb62ce67dc091e3e9f1c6d2c10 (diff) | |
| parent | 2779d9d3bc9a9fd731e118f57d4601de4a55d032 (diff) | |
Merge branch 'master' into installationmanager
Diffstat (limited to 'Emby.Server.Implementations/Updates/InstallationManager.cs')
| -rw-r--r-- | Emby.Server.Implementations/Updates/InstallationManager.cs | 91 |
1 files changed, 47 insertions, 44 deletions
diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index 2ac754eb6..8dcfb0996 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -19,52 +19,18 @@ using MediaBrowser.Model.IO; using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Updates; using Microsoft.Extensions.Logging; -using static MediaBrowser.Common.HexHelper; namespace Emby.Server.Implementations.Updates { /// <summary> - /// Manages all install, uninstall and update operations (both plugins and system) + /// Manages all install, uninstall and update operations (both plugins and system). /// </summary> public class InstallationManager : IInstallationManager { - public event EventHandler<InstallationEventArgs> PackageInstalling; - public event EventHandler<InstallationEventArgs> PackageInstallationCompleted; - public event EventHandler<InstallationFailedEventArgs> PackageInstallationFailed; - public event EventHandler<InstallationEventArgs> PackageInstallationCancelled; - - /// <summary> - /// The current installations - /// </summary> - private List<(InstallationInfo info, CancellationTokenSource token)> _currentInstallations { get; set; } - /// <summary> - /// The completed installations - /// </summary> - private ConcurrentBag<InstallationInfo> _completedInstallationsInternal; - - public IEnumerable<InstallationInfo> CompletedInstallations => _completedInstallationsInternal; - - /// <summary> - /// Occurs when [plugin uninstalled]. - /// </summary> - public event EventHandler<GenericEventArgs<IPlugin>> PluginUninstalled; - - /// <summary> - /// Occurs when [plugin updated]. - /// </summary> - public event EventHandler<GenericEventArgs<(IPlugin, PackageVersionInfo)>> PluginUpdated; - - /// <summary> - /// Occurs when [plugin updated]. - /// </summary> - public event EventHandler<GenericEventArgs<PackageVersionInfo>> PluginInstalled; - - /// <summary> - /// The _logger + /// The _logger. /// </summary> private readonly ILogger _logger; - private readonly IApplicationPaths _appPaths; private readonly IHttpClient _httpClient; private readonly IJsonSerializer _jsonSerializer; @@ -79,6 +45,18 @@ namespace Emby.Server.Implementations.Updates private readonly IZipClient _zipClient; + private readonly object _currentInstallationsLock = new object(); + + /// <summary> + /// The current installations. + /// </summary> + private List<(InstallationInfo info, CancellationTokenSource token)> _currentInstallations; + + /// <summary> + /// The completed installations. + /// </summary> + private ConcurrentBag<InstallationInfo> _completedInstallationsInternal; + public InstallationManager( ILogger<InstallationManager> logger, IApplicationHost appHost, @@ -107,6 +85,31 @@ namespace Emby.Server.Implementations.Updates _zipClient = zipClient; } + public event EventHandler<InstallationEventArgs> PackageInstalling; + + public event EventHandler<InstallationEventArgs> PackageInstallationCompleted; + + public event EventHandler<InstallationFailedEventArgs> PackageInstallationFailed; + + public event EventHandler<InstallationEventArgs> PackageInstallationCancelled; + + /// <summary> + /// Occurs when a plugin is uninstalled. + /// </summary> + public event EventHandler<GenericEventArgs<IPlugin>> PluginUninstalled; + + /// <summary> + /// Occurs when a plugin plugin is updated. + /// </summary> + public event EventHandler<GenericEventArgs<(IPlugin, PackageVersionInfo)>> PluginUpdated; + + /// <summary> + /// Occurs when a plugin plugin is installed. + /// </summary> + public event EventHandler<GenericEventArgs<PackageVersionInfo>> PluginInstalled; + + public IEnumerable<InstallationInfo> CompletedInstallations => _completedInstallationsInternal; + /// <inheritdoc /> public async Task<IReadOnlyList<PackageInfo>> GetAvailablePackages(CancellationToken cancellationToken = default) { @@ -225,7 +228,7 @@ namespace Emby.Server.Implementations.Updates var tuple = (installationInfo, innerCancellationTokenSource); // Add it to the in-progress list - lock (_currentInstallations) + lock (_currentInstallationsLock) { _currentInstallations.Add(tuple); } @@ -244,7 +247,7 @@ namespace Emby.Server.Implementations.Updates { await InstallPackageInternal(package, linkedToken).ConfigureAwait(false); - lock (_currentInstallations) + lock (_currentInstallationsLock) { _currentInstallations.Remove(tuple); } @@ -255,7 +258,7 @@ namespace Emby.Server.Implementations.Updates } catch (OperationCanceledException) { - lock (_currentInstallations) + lock (_currentInstallationsLock) { _currentInstallations.Remove(tuple); } @@ -270,7 +273,7 @@ namespace Emby.Server.Implementations.Updates { _logger.LogError(ex, "Package installation failed"); - lock (_currentInstallations) + lock (_currentInstallationsLock) { _currentInstallations.Remove(tuple); } @@ -334,7 +337,7 @@ namespace Emby.Server.Implementations.Updates // Always override the passed-in target (which is a file) and figure it out again string targetDir = Path.Combine(_appPaths.PluginsPath, package.name); -// CA5351: Do Not Use Broken Cryptographic Algorithms + // CA5351: Do Not Use Broken Cryptographic Algorithms #pragma warning disable CA5351 using (var res = await _httpClient.SendAsync( new HttpRequestOptions @@ -350,7 +353,7 @@ namespace Emby.Server.Implementations.Updates { cancellationToken.ThrowIfCancellationRequested(); - var hash = ToHexString(md5.ComputeHash(stream)); + var hash = Hex.Encode(md5.ComputeHash(stream)); if (!string.Equals(package.checksum, hash, StringComparison.OrdinalIgnoreCase)) { _logger.LogError( @@ -430,7 +433,7 @@ namespace Emby.Server.Implementations.Updates /// <inheritdoc/> public bool CancelInstallation(Guid id) { - lock (_currentInstallations) + lock (_currentInstallationsLock) { var install = _currentInstallations.Find(x => x.info.Id == id); if (install == default((InstallationInfo, CancellationTokenSource))) @@ -459,7 +462,7 @@ namespace Emby.Server.Implementations.Updates { if (dispose) { - lock (_currentInstallations) + lock (_currentInstallationsLock) { foreach (var tuple in _currentInstallations) { |
