Example #1
0
        public static bool IsMatch(CompiledScopeCriteria compiledScopeMatchCriteria, string[] compiledScopes)
        {
            Fx.Assert(compiledScopeMatchCriteria != null, "The compiledScopeMatchCriteria must be non null.");
            Fx.Assert(compiledScopes != null, "The compiledScopes must be non null.");

            if (compiledScopeMatchCriteria.MatchBy == CompiledScopeCriteriaMatchBy.Exact)
            {
                for (int i = 0; i < compiledScopes.Length; i++)
                {
                    if (string.CompareOrdinal(compiledScopes[i], compiledScopeMatchCriteria.CompiledScope) == 0)
                    {
                        return(true);
                    }
                }
            }
            else if (compiledScopeMatchCriteria.MatchBy == CompiledScopeCriteriaMatchBy.StartsWith)
            {
                for (int i = 0; i < compiledScopes.Length; i++)
                {
                    if (compiledScopes[i].StartsWith(compiledScopeMatchCriteria.CompiledScope,
                                                     StringComparison.Ordinal))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public static bool IsMatch(CompiledScopeCriteria compiledScopeMatchCriteria, string[] compiledScopes)
        {
            Fx.Assert(compiledScopeMatchCriteria != null, "The compiledScopeMatchCriteria must be non null.");
            Fx.Assert(compiledScopes != null, "The compiledScopes must be non null.");

            if (compiledScopeMatchCriteria.MatchBy == CompiledScopeCriteriaMatchBy.Exact)
            {
                for (int i = 0; i < compiledScopes.Length; i++)
                {
                    if (string.CompareOrdinal(compiledScopes[i], compiledScopeMatchCriteria.CompiledScope) == 0)
                    {
                        return true;
                    }
                }
            }
            else if (compiledScopeMatchCriteria.MatchBy == CompiledScopeCriteriaMatchBy.StartsWith)
            {
                for (int i = 0; i < compiledScopes.Length; i++)
                {
                    if (compiledScopes[i].StartsWith(compiledScopeMatchCriteria.CompiledScope,
                        StringComparison.Ordinal))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
        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 bool IsMatch(EndpointDiscoveryMetadata endpointDiscoveryMetadata, CompiledScopeCriteria[] compiledScopeMatchCriterias)
 {
     return (MatchTypes(endpointDiscoveryMetadata, this.contractTypeNames) &&
         MatchScopes(endpointDiscoveryMetadata, compiledScopeMatchCriterias, this.scopeMatchBy));
 }