112 lines
4.1 KiB
C#
112 lines
4.1 KiB
C#
#pragma warning disable CS1591
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using MediaBrowser.Model.Configuration;
|
|
|
|
namespace MediaBrowser.Common.Configuration
|
|
{
|
|
public interface IConfigurationManager
|
|
{
|
|
/// <summary>
|
|
/// Occurs when [configuration updating].
|
|
/// </summary>
|
|
event EventHandler<ConfigurationUpdateEventArgs> NamedConfigurationUpdating;
|
|
|
|
/// <summary>
|
|
/// Occurs when [configuration updated].
|
|
/// </summary>
|
|
event EventHandler<EventArgs> ConfigurationUpdated;
|
|
|
|
/// <summary>
|
|
/// Occurs when [named configuration updated].
|
|
/// </summary>
|
|
event EventHandler<ConfigurationUpdateEventArgs> NamedConfigurationUpdated;
|
|
|
|
/// <summary>
|
|
/// Gets the application paths.
|
|
/// </summary>
|
|
/// <value>The application paths.</value>
|
|
IApplicationPaths CommonApplicationPaths { get; }
|
|
|
|
/// <summary>
|
|
/// Gets the configuration.
|
|
/// </summary>
|
|
/// <value>The configuration.</value>
|
|
BaseApplicationConfiguration CommonConfiguration { get; }
|
|
|
|
/// <summary>
|
|
/// Saves the configuration.
|
|
/// </summary>
|
|
void SaveConfiguration();
|
|
|
|
/// <summary>
|
|
/// Replaces the configuration.
|
|
/// </summary>
|
|
/// <param name="newConfiguration">The new configuration.</param>
|
|
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>
|
|
/// <returns>System.Object.</returns>
|
|
object GetConfiguration(string key);
|
|
|
|
/// <summary>
|
|
/// Gets the array of configuration stores.
|
|
/// </summary>
|
|
/// <returns>Array of ConfigurationStore.</returns>
|
|
ConfigurationStore[] GetConfigurationStores();
|
|
|
|
/// <summary>
|
|
/// Gets the type of the configuration.
|
|
/// </summary>
|
|
/// <param name="key">The key.</param>
|
|
/// <returns>Type.</returns>
|
|
Type GetConfigurationType(string key);
|
|
|
|
/// <summary>
|
|
/// Saves the configuration.
|
|
/// </summary>
|
|
/// <param name="key">The key.</param>
|
|
/// <param name="configuration">The configuration.</param>
|
|
void SaveConfiguration(string key, object configuration);
|
|
|
|
/// <summary>
|
|
/// Adds the parts.
|
|
/// </summary>
|
|
/// <param name="factories">The factories.</param>
|
|
void AddParts(IEnumerable<IConfigurationFactory> factories);
|
|
|
|
/// <summary>
|
|
/// Drops the locally cached copy of configuration another instance has written to the shared
|
|
/// configuration directory, so the next read reloads it, and raises the local update event.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// An implementation predating the invalidation bus keeps the default, which reports that it
|
|
/// cannot drop its cache rather than quietly leaving it stale. The caller applying a remote
|
|
/// notice treats that as a failed apply and logs it.
|
|
/// </remarks>
|
|
/// <param name="key">The named configuration key, or <c>null</c> for the system configuration.</param>
|
|
/// <exception cref="NotSupportedException">The implementation cannot drop its cached configuration.</exception>
|
|
void InvalidateCachedConfiguration(string? key)
|
|
=> throw new NotSupportedException(GetType().Name + " cannot drop configuration cached from the shared configuration directory, so writes by other instances will not be picked up.");
|
|
}
|
|
|
|
public static class ConfigurationManagerExtensions
|
|
{
|
|
public static T GetConfiguration<T>(this IConfigurationManager manager, string key)
|
|
{
|
|
return (T)manager.GetConfiguration(key);
|
|
}
|
|
}
|
|
}
|