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;
                    }
                }
            }
        }
        public bool IsMatch(EndpointDiscoveryMetadata endpointDiscoveryMetadata)
        {
            if (endpointDiscoveryMetadata == null)
            {
                throw FxTrace.Exception.ArgumentNull("endpointDiscoveryMetadata");
            }

            return(IsMatch(endpointDiscoveryMetadata, ScopeCompiler.CompileMatchCriteria(this.scopes, this.scopeMatchBy)));
        }
        static bool MatchScopes(EndpointDiscoveryMetadata endpointDiscoveryMetadata, CompiledScopeCriteria[] compiledScopeMatchCriterias, Uri scopeMatchBy)
        {
            if (compiledScopeMatchCriterias == null)
            {
                if (scopeMatchBy != FindCriteria.ScopeMatchByNone)
                {
                    return(true);
                }
                else
                {
                    // the criteria matches any service with no scopes defined
                    return(endpointDiscoveryMetadata.Scopes.Count == 0);
                }
            }

            if (scopeMatchBy == FindCriteria.ScopeMatchByNone)
            {
                // if scopeMatchBy is None, the Probe shouldn't have any Scopes defined
                return(false);
            }

            string[] compiledScopes;
            if (endpointDiscoveryMetadata.IsOpen)
            {
                compiledScopes = endpointDiscoveryMetadata.CompiledScopes;
            }
            else
            {
                compiledScopes = ScopeCompiler.Compile(endpointDiscoveryMetadata.Scopes);
            }

            if (compiledScopes == null)
            {
                // non-zero scopes in the criteria, but zero scopes in the metadata
                return(false);
            }

            for (int i = 0; i < compiledScopeMatchCriterias.Length; i++)
            {
                if (!ScopeCompiler.IsMatch(compiledScopeMatchCriterias[i], compiledScopes))
                {
                    return(false);
                }
            }

            return(true);
        }
        internal void Open()
        {
            if (this.contractTypeNames != null)
            {
                this.contractTypeNames.Open();
            }
            if (this.scopes != null)
            {
                this.scopes.Open();
                this.compiledScopes = ScopeCompiler.Compile(this.scopes);
            }
            if (this.listenUris != null)
            {
                this.listenUris.Open();
            }
            if (this.extensions != null)
            {
                this.extensions.Open();
            }

            this.isOpen = true;
        }