diff options
Diffstat (limited to 'src/DotNetOpenAuth.Messaging/Configuration')
4 files changed, 58 insertions, 54 deletions
diff --git a/src/DotNetOpenAuth.Messaging/Configuration/DotNetOpenAuthSection.cs b/src/DotNetOpenAuth.Messaging/Configuration/DotNetOpenAuthSection.cs index d41460b..5e2a494 100644 --- a/src/DotNetOpenAuth.Messaging/Configuration/DotNetOpenAuthSection.cs +++ b/src/DotNetOpenAuth.Messaging/Configuration/DotNetOpenAuthSection.cs @@ -13,16 +13,11 @@ namespace DotNetOpenAuth.Configuration { /// this library's settings. /// </summary> [ContractVerification(true)] - public class DotNetOpenAuthSection : ConfigurationSection { + public class DotNetOpenAuthSection : ConfigurationSectionGroup { /// <summary> /// The name of the section under which this library's settings must be found. /// </summary> - private const string SectionName = "dotNetOpenAuth"; - - /// <summary> - /// The name of the <messaging> sub-element. - /// </summary> - private const string MessagingElementName = "messaging"; + internal const string SectionName = "dotNetOpenAuth"; /// <summary> /// The name of the <openid> sub-element. @@ -35,21 +30,9 @@ namespace DotNetOpenAuth.Configuration { private const string OAuthElementName = "oauth"; /// <summary> - /// The name of the <reporting> sub-element. - /// </summary> - private const string ReportingElementName = "reporting"; - - /// <summary> - /// The name of the <webResourceUrlProvider> sub-element. - /// </summary> - private const string WebResourceUrlProviderName = "webResourceUrlProvider"; - - /// <summary> /// Initializes a new instance of the <see cref="DotNetOpenAuthSection"/> class. /// </summary> internal DotNetOpenAuthSection() { - Contract.Assume(this.SectionInformation != null); - this.SectionInformation.AllowLocation = false; } /// <summary> @@ -62,43 +45,17 @@ namespace DotNetOpenAuth.Configuration { } } - /// <summary> - /// Gets or sets the configuration for the messaging framework. - /// </summary> - [ConfigurationProperty(MessagingElementName)] - public MessagingElement Messaging { - get { - Contract.Ensures(Contract.Result<MessagingElement>() != null); - return (MessagingElement)this[MessagingElementName] ?? new MessagingElement(); - } - - set { - this[MessagingElementName] = value; - } + public static MessagingElement Messaging { + get { return MessagingElement.Configuration; } } - /// <summary> - /// Gets or sets the configuration for reporting. - /// </summary> - [ConfigurationProperty(ReportingElementName)] - internal ReportingElement Reporting { - get { - Contract.Ensures(Contract.Result<ReportingElement>() != null); - return (ReportingElement)this[ReportingElementName] ?? new ReportingElement(); - } - - set { - this[ReportingElementName] = value; - } + internal TypeConfigurationElement<IEmbeddedResourceRetrieval> EmbeddedResourceRetrievalProvider { + get { return /*(TypeConfigurationElement<IEmbeddedResourceRetrieval>)this[WebResourceUrlProviderName] ??*/ new TypeConfigurationElement<IEmbeddedResourceRetrieval>(); } + set { /*this[WebResourceUrlProviderName] = value;*/ } } - /// <summary> - /// Gets or sets the type to use for obtaining URLs that fetch embedded resource streams. - /// </summary> - [ConfigurationProperty(WebResourceUrlProviderName)] - internal TypeConfigurationElement<IEmbeddedResourceRetrieval> EmbeddedResourceRetrievalProvider { - get { return (TypeConfigurationElement<IEmbeddedResourceRetrieval>)this[WebResourceUrlProviderName] ?? new TypeConfigurationElement<IEmbeddedResourceRetrieval>(); } - set { this[WebResourceUrlProviderName] = value; } + internal static ReportingElement Reporting { + get { return ReportingElement.Configuration; } } } } diff --git a/src/DotNetOpenAuth.Messaging/Configuration/MessagingElement.cs b/src/DotNetOpenAuth.Messaging/Configuration/MessagingElement.cs index 1c46bcf..cec2552 100644 --- a/src/DotNetOpenAuth.Messaging/Configuration/MessagingElement.cs +++ b/src/DotNetOpenAuth.Messaging/Configuration/MessagingElement.cs @@ -15,7 +15,7 @@ namespace DotNetOpenAuth.Configuration { /// Represents the <messaging> element in the host's .config file. /// </summary> [ContractVerification(true)] - public class MessagingElement : ConfigurationElement { + public class MessagingElement : ConfigurationSection { /// <summary> /// The name of the <untrustedWebRequest> sub-element. /// </summary> @@ -61,6 +61,21 @@ namespace DotNetOpenAuth.Configuration { private const string PrivateSecretMaximumAgeConfigName = "privateSecretMaximumAge"; /// <summary> + /// The name of the <messaging> sub-element. + /// </summary> + private const string MessagingElementName = DotNetOpenAuthSection.SectionName + "/messaging"; + + /// <summary> + /// Gets the configuration section from the .config file. + /// </summary> + public static MessagingElement Configuration { + get { + Contract.Ensures(Contract.Result<MessagingElement>() != null); + return (MessagingElement)ConfigurationManager.GetSection(MessagingElementName) ?? new MessagingElement(); + } + } + + /// <summary> /// Gets the actual maximum message lifetime that a program should allow. /// </summary> /// <value>The sum of the <see cref="MaximumMessageLifetime"/> and diff --git a/src/DotNetOpenAuth.Messaging/Configuration/ReportingElement.cs b/src/DotNetOpenAuth.Messaging/Configuration/ReportingElement.cs index 2374448..3cd0af1 100644 --- a/src/DotNetOpenAuth.Messaging/Configuration/ReportingElement.cs +++ b/src/DotNetOpenAuth.Messaging/Configuration/ReportingElement.cs @@ -10,11 +10,12 @@ namespace DotNetOpenAuth.Configuration { using System.Configuration; using System.Linq; using System.Text; + using System.Diagnostics.Contracts; /// <summary> /// Represents the <reporting> element in the host's .config file. /// </summary> - internal class ReportingElement : ConfigurationElement { + internal class ReportingElement : ConfigurationSection { /// <summary> /// The name of the @enabled attribute. /// </summary> @@ -51,6 +52,11 @@ namespace DotNetOpenAuth.Configuration { private const string IncludeCulturesAttributeName = "includeCultures"; /// <summary> + /// The name of the <reporting> sub-element. + /// </summary> + private const string ReportingElementName = DotNetOpenAuthSection.SectionName + "/reporting"; + + /// <summary> /// The default value for the @minimumFlushInterval attribute. /// </summary> #if DEBUG @@ -66,6 +72,16 @@ namespace DotNetOpenAuth.Configuration { } /// <summary> + /// Gets the configuration section from the .config file. + /// </summary> + public static ReportingElement Configuration { + get { + Contract.Ensures(Contract.Result<ReportingElement>() != null); + return (ReportingElement)ConfigurationManager.GetSection(ReportingElementName) ?? new ReportingElement(); + } + } + + /// <summary> /// Gets or sets a value indicating whether this reporting is enabled. /// </summary> /// <value><c>true</c> if enabled; otherwise, <c>false</c>.</value> diff --git a/src/DotNetOpenAuth.Messaging/Configuration/UntrustedWebRequestElement.cs b/src/DotNetOpenAuth.Messaging/Configuration/UntrustedWebRequestElement.cs index 89cd435..40a3d0c 100644 --- a/src/DotNetOpenAuth.Messaging/Configuration/UntrustedWebRequestElement.cs +++ b/src/DotNetOpenAuth.Messaging/Configuration/UntrustedWebRequestElement.cs @@ -7,12 +7,18 @@ namespace DotNetOpenAuth.Configuration { using System; using System.Configuration; + using System.Diagnostics.Contracts; /// <summary> /// Represents the section of a .config file where security policies regarding web requests /// to user-provided, untrusted servers is controlled. /// </summary> internal class UntrustedWebRequestElement : ConfigurationElement { + /// <summary> + /// The name of the <webResourceUrlProvider> sub-element. + /// </summary> + private const string WebResourceUrlProviderName = "webResourceUrlProvider"; + #region Attribute names /// <summary> @@ -58,6 +64,16 @@ namespace DotNetOpenAuth.Configuration { #endregion /// <summary> + /// Gets the configuration section from the .config file. + /// </summary> + public static UntrustedWebRequestElement Configuration { + get { + Contract.Ensures(Contract.Result<UntrustedWebRequestElement>() != null); + return (UntrustedWebRequestElement)ConfigurationManager.GetSection(WebResourceUrlProviderName) ?? new UntrustedWebRequestElement(); + } + } + + /// <summary> /// Gets or sets the read/write timeout after which an HTTP request will fail. /// </summary> [ConfigurationProperty(ReadWriteTimeoutConfigName, DefaultValue = "00:00:01.500")] |