PeerCustomResolverElement.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Configuration / PeerCustomResolverElement.cs / 1 / PeerCustomResolverElement.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------

namespace System.ServiceModel.Configuration 
{
    using System.Configuration; 
    using System.ServiceModel.Description; 
    using System.Globalization;
    using System.Net; 
    using System.Net.Security;
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    using System.ServiceModel.PeerResolvers; 
    using System.ComponentModel;
 
    public sealed partial class PeerCustomResolverElement : ConfigurationElement 
    {
        [ConfigurationProperty(ConfigurationStrings.Address, DefaultValue = null, Options = ConfigurationPropertyOptions.None)] 
        public Uri Address
        {
            get {return (Uri) base[ConfigurationStrings.Address]; }
            set {base[ConfigurationStrings.Address] = value; } 
        }
 
        [ConfigurationProperty(ConfigurationStrings.Headers)] 
        public AddressHeaderCollectionElement Headers
        { 
            get { return (AddressHeaderCollectionElement)base[ConfigurationStrings.Headers]; }
        }

        [ConfigurationProperty(ConfigurationStrings.Identity)] 
        public IdentityElement Identity
        { 
            get { return (IdentityElement)base[ConfigurationStrings.Identity]; } 
        }
 
        [ConfigurationProperty(ConfigurationStrings.Binding, DefaultValue = "")]
        [StringValidator(MinLength = 0)]
        public string Binding
        { 
            get { return (string)base[ConfigurationStrings.Binding]; }
            set { base[ConfigurationStrings.Binding] = value; } 
        } 

        [ConfigurationProperty(ConfigurationStrings.BindingConfiguration, DefaultValue = "")] 
        [StringValidator(MinLength = 0)]
        public string BindingConfiguration
        {
            get { return (string)base[ConfigurationStrings.BindingConfiguration]; } 
            set { base[ConfigurationStrings.BindingConfiguration] = value; }
        } 
 
        [ConfigurationProperty(ConfigurationStrings.PeerResolverType, DefaultValue = "")]
        [StringValidator(MinLength = 0)] 
        public string ResolverType
        {
            get { return (string)base[ConfigurationStrings.PeerResolverType]; }
            set { base[ConfigurationStrings.PeerResolverType] = value; } 
        }
 
        internal void ApplyConfiguration(PeerCustomResolverSettings settings) 
        {
            if (settings == null) 
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("settings");
            }
            if (this.Address != null) 
            {
                settings.Address = new EndpointAddress(this.Address, ConfigLoader.LoadIdentity(this.Identity), this.Headers.Headers); 
            } 
            settings.BindingSection = this.Binding;
            settings.BindingConfiguration = this.BindingConfiguration; 

            if (!String.IsNullOrEmpty(this.Binding) && !String.IsNullOrEmpty(this.BindingConfiguration))
                settings.Binding = ConfigLoader.LookupBinding(this.Binding, this.BindingConfiguration);
            if (!String.IsNullOrEmpty(this.ResolverType)) 
            {
                Type myResolverType = Type.GetType(this.ResolverType, false); 
                if (myResolverType != null) 
                {
                    settings.Resolver = Activator.CreateInstance(myResolverType) as PeerResolver; 
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException( 
                        SR.GetString(SR.PeerResolverInvalid, this.ResolverType)));
                } 
            } 
        }
 
        internal void InitializeFrom(PeerCustomResolverSettings settings)
        {
            if (settings == null)
            { 
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("settings");
            } 
            if(settings.Address != null) 
            {
                this.Address = settings.Address.Uri; 
                this.Identity.InitializeFrom(settings.Address.Identity);
            }
            if(settings.Resolver != null)
            { 
                this.ResolverType = settings.Resolver.GetType().AssemblyQualifiedName;
            } 
            if(settings.Binding != null) 
            {
                this.BindingConfiguration = PeerStrings.PeerCustomResolver+Guid.NewGuid().ToString(); 
                string sectionName;
                BindingsSection.TryAdd(this.BindingConfiguration,
                    settings.Binding,
                    out sectionName); 
                this.Binding = sectionName;
            } 
        } 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK