summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OpenId/Configuration/XriResolverElement.cs
blob: e5dcefbb750d802b699d61239608f118f1ab7579 (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
//-----------------------------------------------------------------------
// <copyright file="XriResolverElement.cs" company="Outercurve Foundation">
//     Copyright (c) Outercurve Foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.Configuration {
	using System.Configuration;

	/// <summary>
	/// Represents the &lt;xriResolver&gt; element in the host's .config file.
	/// </summary>
	internal class XriResolverElement : ConfigurationElement {
		/// <summary>
		/// Gets the name of the @enabled attribute.
		/// </summary>
		private const string EnabledAttributeName = "enabled";

		/// <summary>
		/// The default value for <see cref="Enabled"/>.
		/// </summary>
		private const bool EnabledDefaultValue = true;

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

		/// <summary>
		/// The default XRI proxy resolver to use.
		/// </summary>
		private static readonly HostNameElement ProxyDefault = new HostNameElement("xri.net");

		/// <summary>
		/// Initializes a new instance of the <see cref="XriResolverElement"/> class.
		/// </summary>
		internal XriResolverElement() {
		}

		/// <summary>
		/// Gets or sets a value indicating whether this XRI resolution is enabled.
		/// </summary>
		/// <value>The default value is <c>true</c>.</value>
		[ConfigurationProperty(EnabledAttributeName, DefaultValue = EnabledDefaultValue)]
		internal bool Enabled {
			get { return (bool)this[EnabledAttributeName]; }
			set { this[EnabledAttributeName] = value; }
		}

		/// <summary>
		/// Gets or sets the proxy to use for resolving XRIs.
		/// </summary>
		/// <value>The default value is "xri.net".</value>
		[ConfigurationProperty(ProxyElementName)]
		internal HostNameElement Proxy {
			get {
				var host = (HostNameElement)this[ProxyElementName] ?? ProxyDefault;
				return string.IsNullOrEmpty(host.Name.Trim()) ? ProxyDefault : host;
			}

			set {
				this[ProxyElementName] = value;
			}
		}
	}
}