Changes to support network config
This commit is contained in:
parent
ebe650afa9
commit
6dc81ec8e8
|
@ -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.AppBase
|
|||
var 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)
|
||||
{
|
||||
|
|
|
@ -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.Implementations
|
|||
ApplicationUserAgent = 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.Implementations
|
|||
var 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)
|
||||
|
|
|
@ -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.Controllers
|
|||
public 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -47,12 +47,12 @@ namespace MediaBrowser.Common.Configuration
|
|||
void 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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user