aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Common')
-rw-r--r--MediaBrowser.Common/Configuration/IConfigurationManager.cs7
-rw-r--r--MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverter.cs31
-rw-r--r--MediaBrowser.Common/MediaBrowser.Common.csproj8
-rw-r--r--MediaBrowser.Common/Plugins/BasePlugin.cs17
-rw-r--r--MediaBrowser.Common/Plugins/IPlugin.cs12
-rw-r--r--MediaBrowser.Common/Plugins/IPluginServiceRegistrator.cs19
6 files changed, 63 insertions, 31 deletions
diff --git a/MediaBrowser.Common/Configuration/IConfigurationManager.cs b/MediaBrowser.Common/Configuration/IConfigurationManager.cs
index fe726090d..fc63d9350 100644
--- a/MediaBrowser.Common/Configuration/IConfigurationManager.cs
+++ b/MediaBrowser.Common/Configuration/IConfigurationManager.cs
@@ -47,6 +47,13 @@ namespace MediaBrowser.Common.Configuration
void ReplaceConfiguration(BaseApplicationConfiguration newConfiguration);
/// <summary>
+ /// Manually pre-loads a factory so that it is available pre system initialisation.
+ /// </summary>
+ /// <typeparam name="T">Class to register.</typeparam>
+ void RegisterConfiguration<T>()
+ where T : IConfigurationFactory;
+
+ /// <summary>
/// Gets the configuration.
/// </summary>
/// <param name="key">The key.</param>
diff --git a/MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverter.cs b/MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverter.cs
index bf7048c37..06a29a0db 100644
--- a/MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverter.cs
+++ b/MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverter.cs
@@ -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);
}
}
-} \ No newline at end of file
+}
diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj
index 777136f8b..c2145aec5 100644
--- a/MediaBrowser.Common/MediaBrowser.Common.csproj
+++ b/MediaBrowser.Common/MediaBrowser.Common.csproj
@@ -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>
diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs
index 8545fd5dc..e21d8c7d1 100644
--- a/MediaBrowser.Common/Plugins/BasePlugin.cs
+++ b/MediaBrowser.Common/Plugins/BasePlugin.cs
@@ -84,16 +84,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)
{
AssemblyFilePath = assemblyFilePath;
@@ -186,6 +176,11 @@ namespace MediaBrowser.Common.Plugins
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>
/// <value>The name of the assembly file.</value>
@@ -280,6 +275,8 @@ namespace MediaBrowser.Common.Plugins
Configuration = (TConfigurationType)configuration;
SaveConfiguration();
+
+ ConfigurationChanged.Invoke(this, configuration);
}
/// <inheritdoc />
diff --git a/MediaBrowser.Common/Plugins/IPlugin.cs b/MediaBrowser.Common/Plugins/IPlugin.cs
index 1844eb124..d583a5887 100644
--- a/MediaBrowser.Common/Plugins/IPlugin.cs
+++ b/MediaBrowser.Common/Plugins/IPlugin.cs
@@ -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
diff --git a/MediaBrowser.Common/Plugins/IPluginServiceRegistrator.cs b/MediaBrowser.Common/Plugins/IPluginServiceRegistrator.cs
new file mode 100644
index 000000000..3afe874c5
--- /dev/null
+++ b/MediaBrowser.Common/Plugins/IPluginServiceRegistrator.cs
@@ -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);
+ }
+}