using System;
using System.Configuration;
using System.Xml.Serialization;
namespace Endpoint
{
///
/// Defines a configuration for an http service endpoint
///
public class HttpEndpointConfiguration : ConfigurationElement, IHttpEndpointConfiguration
{
///
/// Gets or sets the name.
///
/// The name.
[ConfigurationProperty("name", DefaultValue = "", IsKey = true, IsRequired = true)]
public string Name
{
get { return (string) base["name"]; }
set { base["name"] = value; }
}
///
/// URI of the service
///
[XmlIgnore]
public Uri Uri
{
get { return new Uri((string) base["uri"]); }
}
///
/// Gets or sets the URI string.
///
/// The URI string.
[ConfigurationProperty("uri", DefaultValue = "", IsKey = false, IsRequired = true)]
public string UriString
{
get { return (string)base["uri"]; }
set { base["uri"] = value; }
}
///
/// Initializes a new instance of the class.
///
/// The name.
/// The uri.
public HttpEndpointConfiguration(string serviceName, Uri uri)
{
Name = serviceName;
UriString = uri.OriginalString;
}
///
/// Initializes a new instance of the class.
///
internal protected HttpEndpointConfiguration()
{
}
///
/// Determines whether the specified is equal to the current .
///
/// The to compare with the current .
///
/// true if the specified is equal to the current ; otherwise, false.
///
/// The parameter is null.
public override bool Equals(object obj)
{
HttpEndpointConfiguration value = obj as HttpEndpointConfiguration;
if (value == null)
return false;
if (value.Uri != Uri)
return false;
return true;
}
///
/// Serves as a hash function for a particular type.
///
///
/// A hash code for the current .
///
public override int GetHashCode()
{
return Uri.GetHashCode();
}
}
///
///
///
public class HttpEndpointConfigurationCollection : ConfigurationElementCollection
{
///
/// When overridden in a derived class, creates a new .
///
///
/// A new .
///
protected override ConfigurationElement CreateNewElement()
{
return new HttpEndpointConfiguration();
}
///
/// Gets the element key for a specified configuration element when overridden in a derived class.
///
///
/// An that acts as the key for the specified .
///
/// The to return the key for.
protected override object GetElementKey(ConfigurationElement element)
{
return ((HttpEndpointConfiguration) element).Name;
}
}
///
///
///
public class HttpEndpointConfigurationSection : ConfigurationSection
{
[ConfigurationProperty("endpoints")]
public HttpEndpointConfigurationCollection Endpoints { get { return (HttpEndpointConfigurationCollection)(base["endpoints"]); } }
}
}