Files
ServiceDashBored/Endpoint/HttpEndpointConfiguration.cs
T
2025-10-11 09:44:08 -04:00

129 lines
3.9 KiB
C#

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