IConfigurationManager.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Collections.Generic;
  4. using MediaBrowser.Model.Configuration;
  5. namespace MediaBrowser.Common.Configuration
  6. {
  7. public interface IConfigurationManager
  8. {
  9. /// <summary>
  10. /// Occurs when [configuration updating].
  11. /// </summary>
  12. event EventHandler<ConfigurationUpdateEventArgs> NamedConfigurationUpdating;
  13. /// <summary>
  14. /// Occurs when [configuration updated].
  15. /// </summary>
  16. event EventHandler<EventArgs> ConfigurationUpdated;
  17. /// <summary>
  18. /// Occurs when [named configuration updated].
  19. /// </summary>
  20. event EventHandler<ConfigurationUpdateEventArgs> NamedConfigurationUpdated;
  21. /// <summary>
  22. /// Gets the application paths.
  23. /// </summary>
  24. /// <value>The application paths.</value>
  25. IApplicationPaths CommonApplicationPaths { get; }
  26. /// <summary>
  27. /// Gets the configuration.
  28. /// </summary>
  29. /// <value>The configuration.</value>
  30. BaseApplicationConfiguration CommonConfiguration { get; }
  31. /// <summary>
  32. /// Saves the configuration.
  33. /// </summary>
  34. void SaveConfiguration();
  35. /// <summary>
  36. /// Replaces the configuration.
  37. /// </summary>
  38. /// <param name="newConfiguration">The new configuration.</param>
  39. void ReplaceConfiguration(BaseApplicationConfiguration newConfiguration);
  40. /// <summary>
  41. /// Gets the configuration.
  42. /// </summary>
  43. /// <param name="key">The key.</param>
  44. /// <param name="objectType">Optional parameter containing the key object to create, if it hasn't been registered.</param>
  45. /// <returns>System.Object.</returns>
  46. object GetConfiguration(string key, Type objectType = null);
  47. /// <summary>
  48. /// Gets the type of the configuration.
  49. /// </summary>
  50. /// <param name="key">The key.</param>
  51. /// <returns>Type.</returns>
  52. Type GetConfigurationType(string key);
  53. /// <summary>
  54. /// Saves the configuration.
  55. /// </summary>
  56. /// <param name="key">The key.</param>
  57. /// <param name="configuration">The configuration.</param>
  58. void SaveConfiguration(string key, object configuration);
  59. /// <summary>
  60. /// Adds the parts.
  61. /// </summary>
  62. /// <param name="factories">The factories.</param>
  63. void AddParts(IEnumerable<IConfigurationFactory> factories);
  64. }
  65. public static class ConfigurationManagerExtensions
  66. {
  67. public static T GetConfiguration<T>(this IConfigurationManager manager, string key)
  68. {
  69. return (T)manager.GetConfiguration(key);
  70. }
  71. }
  72. }