From d7748cfa0476280cce9dba34b4512cc58760c8bb Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Wed, 11 Oct 2023 18:32:57 +0200 Subject: Multiple Stream changes * Remove useless MemoryStream in DlnaHttpClient * Use HttpContent.ReadFromJsonAsync extension * Call ConfigureAwait for IAsyncDisposable * Use HttpContent.CopyToAsync where possible --- Emby.Server.Implementations/Plugins/PluginManager.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'Emby.Server.Implementations/Plugins/PluginManager.cs') diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs index d7189ef0c..20793ee39 100644 --- a/Emby.Server.Implementations/Plugins/PluginManager.cs +++ b/Emby.Server.Implementations/Plugins/PluginManager.cs @@ -386,11 +386,11 @@ namespace Emby.Server.Implementations.Plugins var url = new Uri(packageInfo.ImageUrl); imagePath = Path.Join(path, url.Segments[^1]); - await using var fileStream = AsyncFile.OpenWrite(imagePath); - + var fileStream = AsyncFile.OpenWrite(imagePath); + Stream? downloadStream = null; try { - await using var downloadStream = await HttpClientFactory + downloadStream = await HttpClientFactory .CreateClient(NamedClient.Default) .GetStreamAsync(url) .ConfigureAwait(false); @@ -402,6 +402,14 @@ namespace Emby.Server.Implementations.Plugins _logger.LogError(ex, "Failed to download image to path {Path} on disk.", imagePath); imagePath = string.Empty; } + finally + { + await fileStream.DisposeAsync().ConfigureAwait(false); + if (downloadStream is not null) + { + await downloadStream.DisposeAsync().ConfigureAwait(false); + } + } } var manifest = new PluginManifest @@ -421,7 +429,7 @@ namespace Emby.Server.Implementations.Plugins ImagePath = imagePath }; - if (!await ReconcileManifest(manifest, path)) + if (!await ReconcileManifest(manifest, path).ConfigureAwait(false)) { // An error occurred during reconciliation and saving could be undesirable. return false; @@ -458,7 +466,7 @@ namespace Emby.Server.Implementations.Plugins } using var metaStream = File.OpenRead(metafile); - var localManifest = await JsonSerializer.DeserializeAsync(metaStream, _jsonOptions); + var localManifest = await JsonSerializer.DeserializeAsync(metaStream, _jsonOptions).ConfigureAwait(false); localManifest ??= new PluginManifest(); if (!Equals(localManifest.Id, manifest.Id)) -- cgit v1.2.3 From 1e1e1560a47439c02931e67736bcd87b606cf35c Mon Sep 17 00:00:00 2001 From: Patrick Barron Date: Thu, 9 Nov 2023 15:09:51 -0500 Subject: Add IServerApplicationHost parameter to IPluginServiceRegistrator --- Emby.Server.Implementations/Plugins/PluginManager.cs | 11 ++++++----- .../Plugins/IPluginServiceRegistrator.cs | 19 ------------------- .../Plugins/IPluginServiceRegistrator.cs | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 24 deletions(-) delete mode 100644 MediaBrowser.Common/Plugins/IPluginServiceRegistrator.cs create mode 100644 MediaBrowser.Controller/Plugins/IPluginServiceRegistrator.cs (limited to 'Emby.Server.Implementations/Plugins/PluginManager.cs') diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs index 20793ee39..db82a2900 100644 --- a/Emby.Server.Implementations/Plugins/PluginManager.cs +++ b/Emby.Server.Implementations/Plugins/PluginManager.cs @@ -12,10 +12,11 @@ using System.Threading.Tasks; using Emby.Server.Implementations.Library; using Jellyfin.Extensions.Json; using Jellyfin.Extensions.Json.Converters; -using MediaBrowser.Common; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; using MediaBrowser.Common.Plugins; +using MediaBrowser.Controller; +using MediaBrowser.Controller.Plugins; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.IO; using MediaBrowser.Model.Plugins; @@ -37,7 +38,7 @@ namespace Emby.Server.Implementations.Plugins private readonly List _assemblyLoadContexts; private readonly JsonSerializerOptions _jsonOptions; private readonly ILogger _logger; - private readonly IApplicationHost _appHost; + private readonly IServerApplicationHost _appHost; private readonly ServerConfiguration _config; private readonly List _plugins; private readonly Version _minimumVersion; @@ -48,13 +49,13 @@ namespace Emby.Server.Implementations.Plugins /// Initializes a new instance of the class. /// /// The . - /// The . + /// The . /// The . /// The plugin path. /// The application version. public PluginManager( ILogger logger, - IApplicationHost appHost, + IServerApplicationHost appHost, ServerConfiguration config, string pluginsPath, Version appVersion) @@ -222,7 +223,7 @@ namespace Emby.Server.Implementations.Plugins try { var instance = (IPluginServiceRegistrator?)Activator.CreateInstance(pluginServiceRegistrator); - instance?.RegisterServices(serviceCollection); + instance?.RegisterServices(serviceCollection, _appHost); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) diff --git a/MediaBrowser.Common/Plugins/IPluginServiceRegistrator.cs b/MediaBrowser.Common/Plugins/IPluginServiceRegistrator.cs deleted file mode 100644 index 3afe874c5..000000000 --- a/MediaBrowser.Common/Plugins/IPluginServiceRegistrator.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace MediaBrowser.Common.Plugins -{ - using Microsoft.Extensions.DependencyInjection; - - /// - /// Defines the . - /// - public interface IPluginServiceRegistrator - { - /// - /// Registers the plugin's services with the service collection. - /// - /// - /// This interface is only used for service registration and requires a parameterless constructor. - /// - /// The service collection. - void RegisterServices(IServiceCollection serviceCollection); - } -} diff --git a/MediaBrowser.Controller/Plugins/IPluginServiceRegistrator.cs b/MediaBrowser.Controller/Plugins/IPluginServiceRegistrator.cs new file mode 100644 index 000000000..8b62f3808 --- /dev/null +++ b/MediaBrowser.Controller/Plugins/IPluginServiceRegistrator.cs @@ -0,0 +1,19 @@ +using Microsoft.Extensions.DependencyInjection; + +namespace MediaBrowser.Controller.Plugins; + +/// +/// Defines the . +/// +/// +/// This interface is only used for service registration and requires a parameterless constructor. +/// +public interface IPluginServiceRegistrator +{ + /// + /// Registers the plugin's services with the service collection. + /// + /// The service collection. + /// The server application host. + void RegisterServices(IServiceCollection serviceCollection, IServerApplicationHost applicationHost); +} -- cgit v1.2.3