The Free Software Media System - Server Backend & API
Changes to support network config
Greenback6dc81ec8e8e2
diff --git a/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs b/Emby.Server.Implementations/AppBase/BaseConfigurationManager.csindex fa4b3080c9..8503a358e4 100644--- a/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs+++ b/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs@@ -134,6 +134,35 @@ namespace Emby.Server.Implementations.AppBase}}+ /// <summary>+ /// Manually pre-loads a factory so that it is available pre system initialisation.+ /// </summary>+ /// <typeparam name="T">Class to register.</typeparam>+ public virtual void RegisterConfiguration<T>()+ {+ if (!typeof(IConfigurationFactory).IsAssignableFrom(typeof(T)))+ {+ throw new ArgumentException("Parameter does not implement IConfigurationFactory");+ }++ IConfigurationFactory factory = (IConfigurationFactory)Activator.CreateInstance(typeof(T));++ if (_configurationFactories == null)+ {+ _configurationFactories = new IConfigurationFactory[] { factory };+ }+ else+ {+ var list = _configurationFactories.ToList<IConfigurationFactory>();+ list.Add(factory);+ _configurationFactories = list.ToArray();+ }++ _configurationStores = _configurationFactories+ .SelectMany(i => i.GetConfigurations())+ .ToArray();+ }+/// <summary>/// Adds parts./// </summary>@@ -269,7 +298,7 @@ namespace Emby.Server.Implementations.AppBase}/// <inheritdoc />- public object GetConfiguration(string key, Type objectType = null)+ public object GetConfiguration(string key){return _configurations.GetOrAdd(key, k =>{@@ -278,12 +307,12 @@ namespace Emby.Server.Implementations.AppBasevar configurationInfo = _configurationStores.FirstOrDefault(i => string.Equals(i.Key, key, StringComparison.OrdinalIgnoreCase));- if (configurationInfo == null && objectType == null)+ if (configurationInfo == null){throw new ResourceNotFoundException("Configuration with key " + key + " not found.");}- var configurationType = configurationInfo?.ConfigurationType ?? objectType;+ var configurationType = configurationInfo.ConfigurationType;lock (_configurationSyncLock){diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.csindex ecd26c0d84..768f7a9c8d 100644--- a/Emby.Server.Implementations/ApplicationHost.cs+++ b/Emby.Server.Implementations/ApplicationHost.cs@@ -276,9 +276,11 @@ namespace Emby.Server.Implementations_fileSystemManager = fileSystem;ConfigurationManager = new ServerConfigurationManager(ApplicationPaths, LoggerFactory, _xmlSerializer, _fileSystemManager);+ MigrateNetworkConfiguration();+ // Have to pre-register the NetworkConfigurationFactory.+ ConfigurationManager.RegisterConfiguration<NetworkConfigurationFactory>();NetManager = new NetworkManager((IServerConfigurationManager)ConfigurationManager, LoggerFactory.CreateLogger<NetworkManager>());- NetManager.UpdateSettings(GetNetworkConfiguration());Logger = LoggerFactory.CreateLogger<ApplicationHost>();@@ -304,7 +306,7 @@ namespace Emby.Server.ImplementationsApplicationUserAgent = Name.Replace(' ', '-') + "/" + ApplicationVersionString;}- private NetworkConfiguration GetNetworkConfiguration()+ private void MigrateNetworkConfiguration(){string path = Path.Combine(ConfigurationManager.CommonApplicationPaths.ConfigurationDirectoryPath, "network.xml");if (!File.Exists(path))@@ -312,11 +314,8 @@ namespace Emby.Server.Implementationsvar networkSettings = new NetworkConfiguration();ClassMigrationHelper.CopyProperties(ServerConfigurationManager.Configuration, networkSettings);_xmlSerializer.SerializeToFile(networkSettings, path);-- return networkSettings;+ Logger.LogDebug("Successfully migrated network settings.");}-- return (NetworkConfiguration)ConfigurationManager.GetConfiguration("network", typeof(NetworkConfiguration));}public string ExpandVirtualPath(string path)diff --git a/Jellyfin.Api/Controllers/ConfigurationController.cs b/Jellyfin.Api/Controllers/ConfigurationController.csindex 09d72e8b10..53f94cf375 100644--- a/Jellyfin.Api/Controllers/ConfigurationController.cs+++ b/Jellyfin.Api/Controllers/ConfigurationController.cs@@ -51,10 +51,6 @@ namespace Jellyfin.Api.Controllers[ProducesResponseType(StatusCodes.Status200OK)]public ActionResult<ServerConfiguration> GetConfiguration(){- // TODO: Temp workaround until the web can be changed.- var net = _configurationManager.GetNetworkConfiguration();- ClassMigrationHelper.CopyProperties(net, _configurationManager.Configuration);-return _configurationManager.Configuration;}@@ -70,12 +66,6 @@ namespace Jellyfin.Api.Controllerspublic ActionResult UpdateConfiguration([FromBody, Required] ServerConfiguration configuration){_configurationManager.ReplaceConfiguration(configuration);-- // TODO: Temp workaround until the web can be changed.- var network = _configurationManager.GetNetworkConfiguration();- ClassMigrationHelper.CopyProperties(configuration, network);- _configurationManager.SaveConfiguration("Network", network);-return NoContent();}diff --git a/Jellyfin.Networking/Manager/NetworkManager.cs b/Jellyfin.Networking/Manager/NetworkManager.csindex 26614c85e0..6d6b7ebc4e 100644--- a/Jellyfin.Networking/Manager/NetworkManager.cs+++ b/Jellyfin.Networking/Manager/NetworkManager.cs@@ -110,10 +110,12 @@ namespace Jellyfin.Networking.Manager_publishedServerUrls = new Dictionary<IPNetAddress, string>();_eventFireLock = new object();+ UpdateSettings(_configurationManager.GetNetworkConfiguration());+NetworkChange.NetworkAddressChanged += OnNetworkAddressChanged;NetworkChange.NetworkAvailabilityChanged += OnNetworkAvailabilityChanged;- _configurationManager.ConfigurationUpdated += ConfigurationUpdated;+ _configurationManager.NamedConfigurationUpdated += ConfigurationUpdated;}#pragma warning restore CS8618 // Non-nullable field is uninitialized.@@ -600,7 +602,7 @@ namespace Jellyfin.Networking.Manager{if (disposing){- _configurationManager.ConfigurationUpdated -= ConfigurationUpdated;+ _configurationManager.NamedConfigurationUpdated -= ConfigurationUpdated;NetworkChange.NetworkAddressChanged -= OnNetworkAddressChanged;NetworkChange.NetworkAvailabilityChanged -= OnNetworkAvailabilityChanged;}@@ -609,9 +611,12 @@ namespace Jellyfin.Networking.Manager}}- private void ConfigurationUpdated(object? sender, EventArgs args)+ private void ConfigurationUpdated(object? sender, ConfigurationUpdateEventArgs evt){- UpdateSettings(_configurationManager.GetNetworkConfiguration());+ if (evt.Key.Equals("network", StringComparison.Ordinal))+ {+ UpdateSettings(evt.NewConfiguration);+ }}/// <summary>diff --git a/MediaBrowser.Common/Configuration/IConfigurationManager.cs b/MediaBrowser.Common/Configuration/IConfigurationManager.csindex 7bcd4d8ed3..17520f8a37 100644--- a/MediaBrowser.Common/Configuration/IConfigurationManager.cs+++ b/MediaBrowser.Common/Configuration/IConfigurationManager.cs@@ -47,12 +47,12 @@ namespace MediaBrowser.Common.Configurationvoid ReplaceConfiguration(BaseApplicationConfiguration newConfiguration);/// <summary>- /// Gets the configuration.+ /// Manually pre-loads a factory so that it is available pre system initialisation./// </summary>- /// <param name="key">The key.</param>- /// <param name="objectType">Optional parameter containing the key object to create, if it hasn't been registered.</param>- /// <returns>System.Object.</returns>- object GetConfiguration(string key, Type objectType = null);+ /// <typeparam name="T">Class to register.</typeparam>+ void RegisterConfiguration<T>();++ object GetConfiguration(string key);/// <summary>/// Gets the type of the configuration.