summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Messaging/Configuration/DotNetOpenAuthSection.cs
blob: 409fca92d08215612aa6f380ef294d38f7c62075 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//-----------------------------------------------------------------------
// <copyright file="DotNetOpenAuthSection.cs" company="Andrew Arnott">
//     Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.Configuration {
	using System.Configuration;
	using System.Diagnostics.Contracts;

	/// <summary>
	/// Represents the section in the host's .config file that configures
	/// this library's settings.
	/// </summary>
	[ContractVerification(true)]
	public class DotNetOpenAuthSection : ConfigurationSection {
		/// <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 &lt;messaging&gt; sub-element.
		/// </summary>
		private const string MessagingElementName = "messaging";

		/// <summary>
		/// The name of the &lt;openid&gt; sub-element.
		/// </summary>
		private const string OpenIdElementName = "openid";

		/// <summary>
		/// The name of the &lt;oauth&gt; sub-element.
		/// </summary>
		private const string OAuthElementName = "oauth";

		/// <summary>
		/// The name of the &lt;reporting&gt; sub-element.
		/// </summary>
		private const string ReportingElementName = "reporting";

		/// <summary>
		/// The name of the &lt;webResourceUrlProvider&gt; 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>
		/// Gets the configuration section from the .config file.
		/// </summary>
		public static DotNetOpenAuthSection Configuration {
			get {
				Contract.Ensures(Contract.Result<DotNetOpenAuthSection>() != null);
				return (DotNetOpenAuthSection)ConfigurationManager.GetSection(SectionName) ?? new DotNetOpenAuthSection();
			}
		}

		/// <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;
			}
		}

		/// <summary>
		/// Gets or sets the configuration for OpenID.
		/// </summary>
		[ConfigurationProperty(OpenIdElementName)]
		internal OpenIdElement OpenId {
			get {
				Contract.Ensures(Contract.Result<OpenIdElement>() != null);
				return (OpenIdElement)this[OpenIdElementName] ?? new OpenIdElement();
			}

			set {
				this[OpenIdElementName] = value;
			}
		}

		/// <summary>
		/// Gets or sets the configuration for OAuth.
		/// </summary>
		[ConfigurationProperty(OAuthElementName)]
		internal OAuthElement OAuth {
			get {
				Contract.Ensures(Contract.Result<OAuthElement>() != null);
				return (OAuthElement)this[OAuthElementName] ?? new OAuthElement();
			}

			set {
				this[OAuthElementName] = value;
			}
		}

		/// <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;
			}
		}

		/// <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; }
		}
	}
}