mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-17 13:10:28 +01:00
Merge branch 'master' into NetworkPR2
This commit is contained in:
@@ -50,8 +50,12 @@ namespace MediaBrowser.Common.Configuration
|
||||
/// Manually pre-loads a factory so that it is available pre system initialisation.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Class to register.</typeparam>
|
||||
void RegisterConfiguration<T>();
|
||||
void RegisterConfiguration<T>()
|
||||
where T : IConfigurationFactory;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the configuration.
|
||||
/// </summary>
|
||||
object GetConfiguration(string key);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -26,19 +26,40 @@ namespace MediaBrowser.Common.Json.Converters
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
var stringEntries = reader.GetString()?.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var stringEntries = reader.GetString()?.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (stringEntries == null || stringEntries.Length == 0)
|
||||
{
|
||||
return Array.Empty<T>();
|
||||
}
|
||||
|
||||
var entries = new T[stringEntries.Length];
|
||||
var parsedValues = new object[stringEntries.Length];
|
||||
var convertedCount = 0;
|
||||
for (var i = 0; i < stringEntries.Length; i++)
|
||||
{
|
||||
entries[i] = (T)_typeConverter.ConvertFrom(stringEntries[i].Trim());
|
||||
try
|
||||
{
|
||||
parsedValues[i] = _typeConverter.ConvertFrom(stringEntries[i].Trim());
|
||||
convertedCount++;
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
// TODO log when upgraded to .Net5
|
||||
// _logger.LogWarning(e, "Error converting value.");
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
var typedValues = new T[convertedCount];
|
||||
var typedValueIndex = 0;
|
||||
for (var i = 0; i < stringEntries.Length; i++)
|
||||
{
|
||||
if (parsedValues[i] != null)
|
||||
{
|
||||
typedValues.SetValue(parsedValues[i], typedValueIndex);
|
||||
typedValueIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
return typedValues;
|
||||
}
|
||||
|
||||
return JsonSerializer.Deserialize<T[]>(ref reader, options);
|
||||
@@ -50,4 +71,4 @@ namespace MediaBrowser.Common.Json.Converters
|
||||
JsonSerializer.Serialize(writer, value, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ namespace MediaBrowser.Common.Json.Converters
|
||||
/// <inheritdoc />
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
var structType = typeToConvert.GetElementType();
|
||||
var structType = typeToConvert.GetElementType() ?? typeToConvert.GenericTypeArguments[0];
|
||||
return (JsonConverter)Activator.CreateInstance(typeof(JsonCommaDelimitedArrayConverter<>).MakeGenericType(structType));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.9" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
|
||||
<PackageReference Include="Microsoft.Net.Http.Headers" Version="2.2.8" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
|
||||
@@ -83,16 +83,6 @@ 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)
|
||||
{
|
||||
@@ -185,6 +175,11 @@ namespace MediaBrowser.Common.Plugins
|
||||
/// <value>The type of the configuration.</value>
|
||||
public Type ConfigurationType => typeof(TConfigurationType);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the event handler that is triggered when this configuration changes.
|
||||
/// </summary>
|
||||
public EventHandler<BasePluginConfiguration> ConfigurationChanged { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name the assembly file.
|
||||
/// </summary>
|
||||
@@ -280,6 +275,8 @@ namespace MediaBrowser.Common.Plugins
|
||||
Configuration = (TConfigurationType)configuration;
|
||||
|
||||
SaveConfiguration();
|
||||
|
||||
ConfigurationChanged.Invoke(this, configuration);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -62,18 +62,6 @@ 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
|
||||
|
||||
19
MediaBrowser.Common/Plugins/IPluginServiceRegistrator.cs
Normal file
19
MediaBrowser.Common/Plugins/IPluginServiceRegistrator.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace MediaBrowser.Common.Plugins
|
||||
{
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// Defines the <see cref="IPluginServiceRegistrator" />.
|
||||
/// </summary>
|
||||
public interface IPluginServiceRegistrator
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers the plugin's services with the service collection.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This interface is only used for service registration and requires a parameterless constructor.
|
||||
/// </remarks>
|
||||
/// <param name="serviceCollection">The service collection.</param>
|
||||
void RegisterServices(IServiceCollection serviceCollection);
|
||||
}
|
||||
}
|
||||
113
MediaBrowser.Common/Plugins/LocalPlugin.cs
Normal file
113
MediaBrowser.Common/Plugins/LocalPlugin.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
namespace MediaBrowser.Common.Plugins
|
||||
{
|
||||
/// <summary>
|
||||
/// Local plugin struct.
|
||||
/// </summary>
|
||||
public class LocalPlugin : IEquatable<LocalPlugin>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LocalPlugin"/> class.
|
||||
/// </summary>
|
||||
/// <param name="id">The plugin id.</param>
|
||||
/// <param name="name">The plugin name.</param>
|
||||
/// <param name="version">The plugin version.</param>
|
||||
/// <param name="path">The plugin path.</param>
|
||||
public LocalPlugin(Guid id, string name, Version version, string path)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
Version = version;
|
||||
Path = path;
|
||||
DllFiles = new List<string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin id.
|
||||
/// </summary>
|
||||
public Guid Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin name.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin version.
|
||||
/// </summary>
|
||||
public Version Version { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin path.
|
||||
/// </summary>
|
||||
public string Path { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of dll files for this plugin.
|
||||
/// </summary>
|
||||
public List<string> DllFiles { get; }
|
||||
|
||||
/// <summary>
|
||||
/// == operator.
|
||||
/// </summary>
|
||||
/// <param name="left">Left item.</param>
|
||||
/// <param name="right">Right item.</param>
|
||||
/// <returns>Comparison result.</returns>
|
||||
public static bool operator ==(LocalPlugin left, LocalPlugin right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// != operator.
|
||||
/// </summary>
|
||||
/// <param name="left">Left item.</param>
|
||||
/// <param name="right">Right item.</param>
|
||||
/// <returns>Comparison result.</returns>
|
||||
public static bool operator !=(LocalPlugin left, LocalPlugin right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compare two <see cref="LocalPlugin"/>.
|
||||
/// </summary>
|
||||
/// <param name="a">The first item.</param>
|
||||
/// <param name="b">The second item.</param>
|
||||
/// <returns>Comparison result.</returns>
|
||||
public static int Compare(LocalPlugin a, LocalPlugin b)
|
||||
{
|
||||
var compare = string.Compare(a.Name, b.Name, true, CultureInfo.InvariantCulture);
|
||||
|
||||
// Id is not equal but name is.
|
||||
if (a.Id != b.Id && compare == 0)
|
||||
{
|
||||
compare = a.Id.CompareTo(b.Id);
|
||||
}
|
||||
|
||||
return compare == 0 ? a.Version.CompareTo(b.Version) : compare;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is LocalPlugin other && this.Equals(other);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Name.GetHashCode(StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Equals(LocalPlugin other)
|
||||
{
|
||||
return Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase)
|
||||
&& Id.Equals(other.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user