aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common
diff options
context:
space:
mode:
authorMatt Montgomery <33811686+ConfusedPolarBear@users.noreply.github.com>2020-08-26 10:29:37 -0500
committerMatt Montgomery <33811686+ConfusedPolarBear@users.noreply.github.com>2020-08-26 10:29:37 -0500
commit2974a0248a5941f8b784a7bc99c17b1080b7d06f (patch)
tree1eec54868d88648684ca96e1ed6405e4372d5a95 /MediaBrowser.Common
parent1ff4f8e6c64b453eb9096b8da09f4041dbd463fc (diff)
parent4e3f26b647a9fe996b5a96ea10fa1f2468ea41fb (diff)
Merge remote-tracking branch 'upstream/master' into quickconnect
Diffstat (limited to 'MediaBrowser.Common')
-rw-r--r--MediaBrowser.Common/IApplicationHost.cs3
-rw-r--r--MediaBrowser.Common/Json/Converters/JsonInt32Converter.cs2
-rw-r--r--MediaBrowser.Common/Json/Converters/JsonInt64Converter.cs6
-rw-r--r--MediaBrowser.Common/Json/Converters/JsonNullableInt32Converter.cs55
-rw-r--r--MediaBrowser.Common/Json/Converters/JsonNullableInt64Converter.cs70
-rw-r--r--MediaBrowser.Common/Json/JsonDefaults.cs5
-rw-r--r--MediaBrowser.Common/MediaBrowser.Common.csproj3
-rw-r--r--MediaBrowser.Common/Plugins/BasePlugin.cs11
-rw-r--r--MediaBrowser.Common/Plugins/IPlugin.cs13
-rw-r--r--MediaBrowser.Common/Updates/InstallationEventArgs.cs3
10 files changed, 162 insertions, 9 deletions
diff --git a/MediaBrowser.Common/IApplicationHost.cs b/MediaBrowser.Common/IApplicationHost.cs
index e8d9282e40..7a76be7223 100644
--- a/MediaBrowser.Common/IApplicationHost.cs
+++ b/MediaBrowser.Common/IApplicationHost.cs
@@ -116,8 +116,7 @@ namespace MediaBrowser.Common
/// <summary>
/// Initializes this instance.
/// </summary>
- /// <param name="serviceCollection">The service collection.</param>
- void Init(IServiceCollection serviceCollection);
+ void Init();
/// <summary>
/// Creates the instance.
diff --git a/MediaBrowser.Common/Json/Converters/JsonInt32Converter.cs b/MediaBrowser.Common/Json/Converters/JsonInt32Converter.cs
index 70c375b8cd..7ed9d6766d 100644
--- a/MediaBrowser.Common/Json/Converters/JsonInt32Converter.cs
+++ b/MediaBrowser.Common/Json/Converters/JsonInt32Converter.cs
@@ -7,7 +7,7 @@ using System.Text.Json.Serialization;
namespace MediaBrowser.Common.Json.Converters
{
/// <summary>
- /// Converts a GUID object or value to/from JSON.
+ /// Converts a int32 object or value to/from JSON.
/// </summary>
public class JsonInt32Converter : JsonConverter<int>
{
diff --git a/MediaBrowser.Common/Json/Converters/JsonInt64Converter.cs b/MediaBrowser.Common/Json/Converters/JsonInt64Converter.cs
index d18fd95d5f..427f1fa7e0 100644
--- a/MediaBrowser.Common/Json/Converters/JsonInt64Converter.cs
+++ b/MediaBrowser.Common/Json/Converters/JsonInt64Converter.cs
@@ -8,7 +8,7 @@ using System.Text.Json.Serialization;
namespace MediaBrowser.Common.Json.Converters
{
/// <summary>
- /// Long to String JSON converter.
+ /// Parse JSON string as long.
/// Javascript does not support 64-bit integers.
/// </summary>
public class JsonInt64Converter : JsonConverter<long>
@@ -43,14 +43,14 @@ namespace MediaBrowser.Common.Json.Converters
}
/// <summary>
- /// Write long to JSON string.
+ /// Write long to JSON long.
/// </summary>
/// <param name="writer"><see cref="Utf8JsonWriter"/>.</param>
/// <param name="value">Value to write.</param>
/// <param name="options">Options.</param>
public override void Write(Utf8JsonWriter writer, long value, JsonSerializerOptions options)
{
- writer.WriteStringValue(value.ToString(NumberFormatInfo.InvariantInfo));
+ writer.WriteNumberValue(value);
}
}
}
diff --git a/MediaBrowser.Common/Json/Converters/JsonNullableInt32Converter.cs b/MediaBrowser.Common/Json/Converters/JsonNullableInt32Converter.cs
new file mode 100644
index 0000000000..c1660fe761
--- /dev/null
+++ b/MediaBrowser.Common/Json/Converters/JsonNullableInt32Converter.cs
@@ -0,0 +1,55 @@
+using System;
+using System.Buffers;
+using System.Buffers.Text;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+
+namespace MediaBrowser.Common.Json.Converters
+{
+ /// <summary>
+ /// Converts a nullable int32 object or value to/from JSON.
+ /// </summary>
+ public class JsonNullableInt32Converter : JsonConverter<int?>
+ {
+ /// <inheritdoc />
+ public override int? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ {
+ if (reader.TokenType == JsonTokenType.String)
+ {
+ ReadOnlySpan<byte> span = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan;
+ if (Utf8Parser.TryParse(span, out int number, out int bytesConsumed) && span.Length == bytesConsumed)
+ {
+ return number;
+ }
+
+ var stringValue = reader.GetString().AsSpan();
+
+ // value is null or empty, just return null.
+ if (stringValue.IsEmpty)
+ {
+ return null;
+ }
+
+ if (int.TryParse(stringValue, out number))
+ {
+ return number;
+ }
+ }
+
+ return reader.GetInt32();
+ }
+
+ /// <inheritdoc />
+ public override void Write(Utf8JsonWriter writer, int? value, JsonSerializerOptions options)
+ {
+ if (value is null)
+ {
+ writer.WriteNullValue();
+ }
+ else
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/MediaBrowser.Common/Json/Converters/JsonNullableInt64Converter.cs b/MediaBrowser.Common/Json/Converters/JsonNullableInt64Converter.cs
new file mode 100644
index 0000000000..53e5f6e9df
--- /dev/null
+++ b/MediaBrowser.Common/Json/Converters/JsonNullableInt64Converter.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Buffers;
+using System.Buffers.Text;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+
+namespace MediaBrowser.Common.Json.Converters
+{
+ /// <summary>
+ /// Parse JSON string as nullable long.
+ /// Javascript does not support 64-bit integers.
+ /// </summary>
+ public class JsonNullableInt64Converter : JsonConverter<long?>
+ {
+ /// <summary>
+ /// Read JSON string as int64.
+ /// </summary>
+ /// <param name="reader"><see cref="Utf8JsonReader"/>.</param>
+ /// <param name="type">Type.</param>
+ /// <param name="options">Options.</param>
+ /// <returns>Parsed value.</returns>
+ public override long? Read(ref Utf8JsonReader reader, Type type, 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 long number, out var bytesConsumed) && span.Length == bytesConsumed)
+ {
+ return number;
+ }
+
+ var stringValue = reader.GetString().AsSpan();
+
+ // value is null or empty, just return null.
+ if (stringValue.IsEmpty)
+ {
+ return null;
+ }
+
+ // try to parse from a string if the above failed, this covers cases with other escaped/UTF characters
+ if (long.TryParse(stringValue, out number))
+ {
+ return number;
+ }
+ }
+
+ // fallback to default handling
+ return reader.GetInt64();
+ }
+
+ /// <summary>
+ /// Write long to JSON long.
+ /// </summary>
+ /// <param name="writer"><see cref="Utf8JsonWriter"/>.</param>
+ /// <param name="value">Value to write.</param>
+ /// <param name="options">Options.</param>
+ public override void Write(Utf8JsonWriter writer, long? value, JsonSerializerOptions options)
+ {
+ if (value is null)
+ {
+ writer.WriteNullValue();
+ }
+ else
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/MediaBrowser.Common/Json/JsonDefaults.cs b/MediaBrowser.Common/Json/JsonDefaults.cs
index 36ab6d900a..891715b3da 100644
--- a/MediaBrowser.Common/Json/JsonDefaults.cs
+++ b/MediaBrowser.Common/Json/JsonDefaults.cs
@@ -24,14 +24,17 @@ namespace MediaBrowser.Common.Json
var options = new JsonSerializerOptions
{
ReadCommentHandling = JsonCommentHandling.Disallow,
- WriteIndented = false
+ WriteIndented = false,
+ IgnoreNullValues = true
};
options.Converters.Add(new JsonGuidConverter());
options.Converters.Add(new JsonInt32Converter());
+ options.Converters.Add(new JsonNullableInt32Converter());
options.Converters.Add(new JsonStringEnumConverter());
options.Converters.Add(new JsonNonStringKeyDictionaryConverterFactory());
options.Converters.Add(new JsonInt64Converter());
+ options.Converters.Add(new JsonNullableInt64Converter());
options.Converters.Add(new JsonDoubleConverter());
return options;
diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj
index 7380f39fda..deb674e456 100644
--- a/MediaBrowser.Common/MediaBrowser.Common.csproj
+++ b/MediaBrowser.Common/MediaBrowser.Common.csproj
@@ -8,8 +8,9 @@
<PropertyGroup>
<Authors>Jellyfin Contributors</Authors>
<PackageId>Jellyfin.Common</PackageId>
- <PackageLicenseUrl>https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt</PackageLicenseUrl>
+ <VersionPrefix>10.7.0</VersionPrefix>
<RepositoryUrl>https://github.com/jellyfin/jellyfin</RepositoryUrl>
+ <PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
</PropertyGroup>
<ItemGroup>
diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs
index f10a1918f7..4b2918d085 100644
--- a/MediaBrowser.Common/Plugins/BasePlugin.cs
+++ b/MediaBrowser.Common/Plugins/BasePlugin.cs
@@ -6,6 +6,7 @@ using System.Reflection;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
+using Microsoft.Extensions.DependencyInjection;
namespace MediaBrowser.Common.Plugins
{
@@ -82,6 +83,16 @@ namespace MediaBrowser.Common.Plugins
}
/// <inheritdoc />
+ public virtual void RegisterServices(IServiceCollection serviceCollection)
+ {
+ }
+
+ /// <inheritdoc />
+ public virtual void UnregisterServices(IServiceCollection serviceCollection)
+ {
+ }
+
+ /// <inheritdoc />
public void SetAttributes(string assemblyFilePath, string dataFolderPath, Version assemblyVersion)
{
AssemblyFilePath = assemblyFilePath;
diff --git a/MediaBrowser.Common/Plugins/IPlugin.cs b/MediaBrowser.Common/Plugins/IPlugin.cs
index 7bd37d2106..1844eb124f 100644
--- a/MediaBrowser.Common/Plugins/IPlugin.cs
+++ b/MediaBrowser.Common/Plugins/IPlugin.cs
@@ -2,6 +2,7 @@
using System;
using MediaBrowser.Model.Plugins;
+using Microsoft.Extensions.DependencyInjection;
namespace MediaBrowser.Common.Plugins
{
@@ -61,6 +62,18 @@ namespace MediaBrowser.Common.Plugins
/// Called when just before the plugin is uninstalled from the server.
/// </summary>
void OnUninstalling();
+
+ /// <summary>
+ /// Registers the plugin's services to the service collection.
+ /// </summary>
+ /// <param name="serviceCollection">The service collection.</param>
+ void RegisterServices(IServiceCollection serviceCollection);
+
+ /// <summary>
+ /// Unregisters the plugin's services from the service collection.
+ /// </summary>
+ /// <param name="serviceCollection">The service collection.</param>
+ void UnregisterServices(IServiceCollection serviceCollection);
}
public interface IHasPluginConfiguration
diff --git a/MediaBrowser.Common/Updates/InstallationEventArgs.cs b/MediaBrowser.Common/Updates/InstallationEventArgs.cs
index 11eb2ad34a..61178f631c 100644
--- a/MediaBrowser.Common/Updates/InstallationEventArgs.cs
+++ b/MediaBrowser.Common/Updates/InstallationEventArgs.cs
@@ -1,10 +1,11 @@
#pragma warning disable CS1591
+using System;
using MediaBrowser.Model.Updates;
namespace MediaBrowser.Common.Updates
{
- public class InstallationEventArgs
+ public class InstallationEventArgs : EventArgs
{
public InstallationInfo InstallationInfo { get; set; }