DiscoveryServiceExtension.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.ServiceModel.Discovery / System / ServiceModel / Discovery / DiscoveryServiceExtension.cs / 1305376 / DiscoveryServiceExtension.cs

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

namespace System.ServiceModel.Discovery 
{
    using System; 
    using System.Collections.ObjectModel; 
    using System.Runtime;
    using SR2 = System.ServiceModel.Discovery.SR; 

    [Fx.Tag.XamlVisible(false)]
    public abstract class DiscoveryServiceExtension : IExtension
    { 
        ServiceHostBase owner;
        PublishedEndpointCollection publishedEndpoints; 
        ReadOnlyCollection readOnlyPublishedEndpoints; 

        protected DiscoveryServiceExtension() 
        {
            this.publishedEndpoints = new PublishedEndpointCollection();
            this.readOnlyPublishedEndpoints = new ReadOnlyCollection(this.publishedEndpoints);
        } 

        public ReadOnlyCollection PublishedEndpoints 
        { 
            get
            { 
                return this.readOnlyPublishedEndpoints;
            }
        }
 
        internal Collection InternalPublishedEndpoints
        { 
            get 
            {
                return this.publishedEndpoints; 
            }
        }

        void IExtension.Attach(ServiceHostBase owner) 
        {
            if (owner == null) 
            { 
                throw FxTrace.Exception.ArgumentNull("owner");
            } 
            if (this.owner != null)
            {
                throw FxTrace.Exception.AsError(new InvalidOperationException(SR2.DiscoveryExtensionAlreadyAttached));
            } 

            this.owner = owner; 
        } 

        void IExtension.Detach(ServiceHostBase owner) 
        {
            if (owner == null)
            {
                throw FxTrace.Exception.ArgumentNull("owner"); 
            }
            if (this.owner != null) 
            { 
                throw FxTrace.Exception.AsError(new InvalidOperationException(SR2.DiscoveryExtensionCannotBeDetached));
            } 
        }

        internal DiscoveryService ValidateAndGetDiscoveryService()
        { 
            DiscoveryService discoveryService = this.GetDiscoveryService();
 
            if (discoveryService == null) 
            {
                throw FxTrace.Exception.AsError( 
                    new InvalidOperationException(
                        SR.DiscoveryMethodImplementationReturnsNull("GetDiscoveryService", this.GetType())));
            }
 
            return discoveryService;
        } 
 
        protected abstract DiscoveryService GetDiscoveryService();
 
        class PublishedEndpointCollection : NonNullItemCollection
        {
            protected override void InsertItem(int index, EndpointDiscoveryMetadata item)
            { 
                base.InsertItem(index, item);
                item.Open(); 
            } 

            protected override void SetItem(int index, EndpointDiscoveryMetadata item) 
            {
                base.SetItem(index, item);
                item.Open();
            } 
        }
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.


                        

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