//-----------------------------------------------------------------------
//
// Copyright (c) Andrew Arnott. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Configuration {
using System;
using System.Configuration;
using System.Diagnostics.Contracts;
using System.Web;
using System.Web.Configuration;
///
/// Represents the section in the host's .config file that configures
/// this library's settings.
///
[ContractVerification(true)]
public class DotNetOpenAuthSection : ConfigurationSectionGroup {
///
/// The name of the section under which this library's settings must be found.
///
internal const string SectionName = "dotNetOpenAuth";
///
/// The name of the <openid> sub-element.
///
private const string OpenIdElementName = "openid";
///
/// The name of the <oauth> sub-element.
///
private const string OAuthElementName = "oauth";
///
/// A value indicating whether this instance came from a real Configuration instance.
///
private bool synthesizedInstance;
///
/// Initializes a new instance of the class.
///
internal DotNetOpenAuthSection() {
}
///
/// Initializes a new instance of the class.
///
private DotNetOpenAuthSection(bool synthesized) {
this.synthesizedInstance = synthesized;
}
///
/// Gets the configuration section from the .config file.
///
public static DotNetOpenAuthSection Configuration {
get {
Contract.Ensures(Contract.Result() != null);
Configuration configuration;
if (HttpContext.Current != null) {
configuration = HttpContext.Current.Request.ApplicationPath != null
? WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath)
: ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
} else {
configuration = ConfigurationManager.OpenExeConfiguration(null);
}
return (DotNetOpenAuthSection)configuration.GetSectionGroup(SectionName) ?? new DotNetOpenAuthSection(true);
}
}
///
/// Gets the messaging configuration element.
///
public static MessagingElement Messaging {
get { return MessagingElement.Configuration; }
}
///
/// Gets the reporting configuration element.
///
internal static ReportingElement Reporting {
get { return ReportingElement.Configuration; }
}
///
/// Gets a named section in this section group, or null if no such section is defined.
///
internal ConfigurationSection GetNamedSection(string name) {
return this.synthesizedInstance ? null : this.Sections[name];
}
}
}