From 9018f8d8be10bc4812f7d1bd230a1516eca61eea Mon Sep 17 00:00:00 2001 From: telans Date: Tue, 16 Jun 2020 10:37:52 +1200 Subject: Add full stop at end of comments (SA1629) --- MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs') diff --git a/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs b/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs index cdd322c94..54f4fb293 100644 --- a/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs +++ b/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs @@ -12,7 +12,7 @@ namespace MediaBrowser.Model.Configuration public class BaseApplicationConfiguration { /// - /// The number of days we should retain log files + /// The number of days we should retain log files. /// /// The log file retention days. public int LogFileRetentionDays { get; set; } -- cgit v1.2.3 From 3d42f3753889f15f7013d0216f577a7ba6e3120c Mon Sep 17 00:00:00 2001 From: Bond-009 Date: Mon, 22 Jun 2020 15:35:53 +0200 Subject: Minor changes --- .../Updates/InstallationManager.cs | 18 +++++---------- .../Updates/IInstallationManager.cs | 3 +-- .../Configuration/BaseApplicationConfiguration.cs | 26 +++++++++++----------- MediaBrowser.Model/Updates/RepositoryInfo.cs | 7 ++---- 4 files changed, 22 insertions(+), 32 deletions(-) (limited to 'MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs') diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index b1bab8cdd..b8769cd23 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -1,7 +1,6 @@ #pragma warning disable CS1591 using System; -using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; @@ -17,12 +16,10 @@ using MediaBrowser.Common.Net; using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Updates; using MediaBrowser.Controller.Configuration; -using MediaBrowser.Model.Events; using MediaBrowser.Model.IO; using MediaBrowser.Model.Net; using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Updates; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.Updates @@ -49,7 +46,6 @@ namespace Emby.Server.Implementations.Updates private readonly IApplicationHost _applicationHost; private readonly IZipClient _zipClient; - private readonly IConfiguration _appConfig; private readonly object _currentInstallationsLock = new object(); @@ -71,8 +67,7 @@ namespace Emby.Server.Implementations.Updates IJsonSerializer jsonSerializer, IServerConfigurationManager config, IFileSystem fileSystem, - IZipClient zipClient, - IConfiguration appConfig) + IZipClient zipClient) { if (logger == null) { @@ -90,7 +85,6 @@ namespace Emby.Server.Implementations.Updates _config = config; _fileSystem = fileSystem; _zipClient = zipClient; - _appConfig = appConfig; } /// @@ -118,7 +112,7 @@ namespace Emby.Server.Implementations.Updates public IEnumerable CompletedInstallations => _completedInstallationsInternal; /// - public async Task> GetPackages(string manifest, CancellationToken cancellationToken = default) + public async Task> GetPackages(string manifest, CancellationToken cancellationToken = default) { try { @@ -140,19 +134,19 @@ namespace Emby.Server.Implementations.Updates catch (SerializationException ex) { _logger.LogError(ex, "Failed to deserialize the plugin manifest retrieved from {Manifest}", manifest); - return Enumerable.Empty(); + return Array.Empty(); } } } catch (UriFormatException ex) { _logger.LogError(ex, "The URL configured for the plugin repository manifest URL is not valid: {Manifest}", manifest); - return Enumerable.Empty(); + return Array.Empty(); } catch (HttpException ex) { _logger.LogError(ex, "An error occurred while accessing the plugin manifest: {Manifest}", manifest); - return Enumerable.Empty(); + return Array.Empty(); } } @@ -165,7 +159,7 @@ namespace Emby.Server.Implementations.Updates result.AddRange(await GetPackages(repository.Url, cancellationToken).ConfigureAwait(true)); } - return result.AsReadOnly(); + return result; } /// diff --git a/MediaBrowser.Common/Updates/IInstallationManager.cs b/MediaBrowser.Common/Updates/IInstallationManager.cs index a5025aee9..4b4030bc2 100644 --- a/MediaBrowser.Common/Updates/IInstallationManager.cs +++ b/MediaBrowser.Common/Updates/IInstallationManager.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Common.Plugins; -using MediaBrowser.Model.Events; using MediaBrowser.Model.Updates; namespace MediaBrowser.Common.Updates @@ -46,7 +45,7 @@ namespace MediaBrowser.Common.Updates /// The URL to query. /// The cancellation token. /// Task{IReadOnlyList{PackageInfo}}. - Task> GetPackages(string manifest, CancellationToken cancellationToken = default); + Task> GetPackages(string manifest, CancellationToken cancellationToken = default); /// /// Gets all available packages. diff --git a/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs b/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs index 54f4fb293..66f3e1a94 100644 --- a/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs +++ b/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs @@ -12,7 +12,15 @@ namespace MediaBrowser.Model.Configuration public class BaseApplicationConfiguration { /// - /// The number of days we should retain log files. + /// Initializes a new instance of the class. + /// + public BaseApplicationConfiguration() + { + LogFileRetentionDays = 3; + } + + /// + /// Gets or sets the number of days we should retain log files. /// /// The log file retention days. public int LogFileRetentionDays { get; set; } @@ -30,29 +38,21 @@ namespace MediaBrowser.Model.Configuration public string CachePath { get; set; } /// - /// Last known version that was ran using the configuration. + /// Gets or sets the last known version that was ran using the configuration. /// /// The version from previous run. [XmlIgnore] public Version PreviousVersion { get; set; } /// - /// Stringified PreviousVersion to be stored/loaded, - /// because System.Version itself isn't xml-serializable + /// Gets or sets the stringified PreviousVersion to be stored/loaded, + /// because System.Version itself isn't xml-serializable. /// - /// String value of PreviousVersion + /// String value of PreviousVersion. public string PreviousVersionStr { get => PreviousVersion?.ToString(); set => PreviousVersion = Version.Parse(value); } - - /// - /// Initializes a new instance of the class. - /// - public BaseApplicationConfiguration() - { - LogFileRetentionDays = 3; - } } } diff --git a/MediaBrowser.Model/Updates/RepositoryInfo.cs b/MediaBrowser.Model/Updates/RepositoryInfo.cs index 905327c36..bd42e77f0 100644 --- a/MediaBrowser.Model/Updates/RepositoryInfo.cs +++ b/MediaBrowser.Model/Updates/RepositoryInfo.cs @@ -1,6 +1,3 @@ -#nullable disable -using System; - namespace MediaBrowser.Model.Updates { /// @@ -12,12 +9,12 @@ namespace MediaBrowser.Model.Updates /// Gets or sets the name. /// /// The name. - public string Name { get; set; } + public string? Name { get; set; } /// /// Gets or sets the URL. /// /// The URL. - public string Url { get; set; } + public string? Url { get; set; } } } -- cgit v1.2.3 From ee03b919f98032d2c49bd1613a5ca0874790062d Mon Sep 17 00:00:00 2001 From: David Date: Sun, 12 Jul 2020 20:11:59 +0200 Subject: Fix parsing --- .../Controllers/ConfigurationController.cs | 3 +- Jellyfin.Api/Controllers/PluginsController.cs | 3 +- .../Json/Converters/JsonDoubleConverter.cs | 56 ++++++++++++++++++++++ MediaBrowser.Common/Json/JsonDefaults.cs | 1 + .../Configuration/BaseApplicationConfiguration.cs | 8 +++- 5 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 MediaBrowser.Common/Json/Converters/JsonDoubleConverter.cs (limited to 'MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs') diff --git a/Jellyfin.Api/Controllers/ConfigurationController.cs b/Jellyfin.Api/Controllers/ConfigurationController.cs index 13933cb33..d3c29969b 100644 --- a/Jellyfin.Api/Controllers/ConfigurationController.cs +++ b/Jellyfin.Api/Controllers/ConfigurationController.cs @@ -2,6 +2,7 @@ using System.Text.Json; using System.Threading.Tasks; using Jellyfin.Api.Constants; using Jellyfin.Api.Models.ConfigurationDtos; +using MediaBrowser.Common.Json; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Model.Configuration; @@ -87,7 +88,7 @@ namespace Jellyfin.Api.Controllers public async Task UpdateNamedConfiguration([FromRoute] string? key) { var configurationType = _configurationManager.GetConfigurationType(key); - var configuration = await JsonSerializer.DeserializeAsync(Request.Body, configurationType).ConfigureAwait(false); + var configuration = await JsonSerializer.DeserializeAsync(Request.Body, configurationType, JsonDefaults.GetOptions()).ConfigureAwait(false); _configurationManager.SaveConfiguration(key, configuration); return NoContent(); } diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index 056395a51..9b5529c37 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Jellyfin.Api.Constants; using Jellyfin.Api.Models.PluginDtos; using MediaBrowser.Common; +using MediaBrowser.Common.Json; using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Updates; using MediaBrowser.Model.Plugins; @@ -118,7 +119,7 @@ namespace Jellyfin.Api.Controllers return NotFound(); } - var configuration = (BasePluginConfiguration)await JsonSerializer.DeserializeAsync(Request.Body, plugin.ConfigurationType) + var configuration = (BasePluginConfiguration)await JsonSerializer.DeserializeAsync(Request.Body, plugin.ConfigurationType, JsonDefaults.GetOptions()) .ConfigureAwait(false); plugin.UpdateConfiguration(configuration); diff --git a/MediaBrowser.Common/Json/Converters/JsonDoubleConverter.cs b/MediaBrowser.Common/Json/Converters/JsonDoubleConverter.cs new file mode 100644 index 000000000..e5e9f28da --- /dev/null +++ b/MediaBrowser.Common/Json/Converters/JsonDoubleConverter.cs @@ -0,0 +1,56 @@ +using System; +using System.Buffers; +using System.Buffers.Text; +using System.Globalization; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace MediaBrowser.Common.Json.Converters +{ + /// + /// Double to String JSON converter. + /// Web client send quoted doubles. + /// + public class JsonDoubleConverter : JsonConverter + { + /// + /// Read JSON string as double. + /// + /// . + /// Type. + /// Options. + /// Parsed value. + public override double Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType == JsonTokenType.String) + { + // try to parse number directly from bytes + var span = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan; + if (Utf8Parser.TryParse(span, out double number, out var bytesConsumed) && span.Length == bytesConsumed) + { + return number; + } + + // try to parse from a string if the above failed, this covers cases with other escaped/UTF characters + if (double.TryParse(reader.GetString(), out number)) + { + return number; + } + } + + // fallback to default handling + return reader.GetDouble(); + } + + /// + /// Write double to JSON string. + /// + /// . + /// Value to write. + /// Options. + public override void Write(Utf8JsonWriter writer, double value, JsonSerializerOptions options) + { + writer.WriteStringValue(value.ToString(NumberFormatInfo.InvariantInfo)); + } + } +} diff --git a/MediaBrowser.Common/Json/JsonDefaults.cs b/MediaBrowser.Common/Json/JsonDefaults.cs index 13f2f060b..36ab6d900 100644 --- a/MediaBrowser.Common/Json/JsonDefaults.cs +++ b/MediaBrowser.Common/Json/JsonDefaults.cs @@ -32,6 +32,7 @@ namespace MediaBrowser.Common.Json options.Converters.Add(new JsonStringEnumConverter()); options.Converters.Add(new JsonNonStringKeyDictionaryConverterFactory()); options.Converters.Add(new JsonInt64Converter()); + options.Converters.Add(new JsonDoubleConverter()); return options; } diff --git a/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs b/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs index cdd322c94..db06c06fc 100644 --- a/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs +++ b/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs @@ -44,7 +44,13 @@ namespace MediaBrowser.Model.Configuration public string PreviousVersionStr { get => PreviousVersion?.ToString(); - set => PreviousVersion = Version.Parse(value); + set + { + if (Version.TryParse(value, out var version)) + { + PreviousVersion = version; + } + } } /// -- cgit v1.2.3