DefaultDiscoveryService.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 / DefaultDiscoveryService.cs / 1305376 / DefaultDiscoveryService.cs

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

namespace System.ServiceModel.Discovery 
{
    using System.Collections.ObjectModel; 
    using System.Runtime; 

    class DefaultDiscoveryService : DiscoveryService 
    {
        readonly ReadOnlyCollection publishedEndpoints;

        public DefaultDiscoveryService( 
            DiscoveryServiceExtension discoveryServiceExtension,
            DiscoveryMessageSequenceGenerator discoveryMessageSequenceGenerator, 
            int duplicateMessageHistoryLength) 
            : base(discoveryMessageSequenceGenerator, duplicateMessageHistoryLength)
 
        {
            Fx.Assert(discoveryServiceExtension != null, "The discoveryServiceExtension must be non null.");
            this.publishedEndpoints = discoveryServiceExtension.PublishedEndpoints;
        } 

        protected override IAsyncResult OnBeginFind( 
            FindRequestContext findRequestContext, 
            AsyncCallback callback,
            object state) 
        {
            this.Match(findRequestContext);
            return new CompletedAsyncResult(callback, state);
        } 

        protected override void OnEndFind(IAsyncResult result) 
        { 
            CompletedAsyncResult.End(result);
        } 

        protected override IAsyncResult OnBeginResolve(ResolveCriteria resolveCriteria, AsyncCallback callback, object state)
        {
            return new CompletedAsyncResult( 
                this.Match(resolveCriteria),
                callback, 
                state); 
        }
 
        protected override EndpointDiscoveryMetadata OnEndResolve(IAsyncResult result)
        {
            return CompletedAsyncResult.End(result);
        } 

        EndpointDiscoveryMetadata Match(ResolveCriteria criteria) 
        { 
            for (int i = 0; i < this.publishedEndpoints.Count; i++)
            { 
                if (this.publishedEndpoints[i].Address.Equals(criteria.Address))
                {
                    return this.publishedEndpoints[i];
                } 
            }
 
            return null; 
        }
 
        void Match(FindRequestContext findRequestContext)
        {
            FindCriteria criteria = findRequestContext.Criteria;
 
            if (!ScopeCompiler.IsSupportedMatchingRule(criteria.ScopeMatchBy))
            { 
                return; 
            }
 
            CompiledScopeCriteria[] compiledScopeCriterias = ScopeCompiler.CompileMatchCriteria(
                criteria.InternalScopes,
                criteria.ScopeMatchBy);
 
            int matchingEndpointCount = 0;
            for (int i = 0; i < this.publishedEndpoints.Count; i++) 
            { 
                if (criteria.IsMatch(this.publishedEndpoints[i], compiledScopeCriterias))
                { 
                    findRequestContext.AddMatchingEndpoint(this.publishedEndpoints[i]);
                    matchingEndpointCount++;

                    if (matchingEndpointCount == criteria.MaxResults) 
                    {
                        break; 
                    } 
                }
            } 
        }
    }
}

// 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