private IEnumerable <Match> MatchSingleValue(JValue input, JValue pattern) { switch (pattern.Type) { case JTokenType.String: var patternValue = pattern.Value <string>(); if (PlaceholderHelper.IsPlaceholder(patternValue, out var placeholder)) { return(MatchCollectionHelper.CreateWithSingleGroup(new CapturingGroup { Key = placeholder, Value = (input as JValue).GetPrimitiveAsObject(), Path = input.Path })); } else { return(string.Equals(input.Value <string>(), PlaceholderHelper.Unescape(patternValue), this.stringComparison) ? MatchCollectionHelper.CreateWithEmptyMatch() : null); } case JTokenType.Integer: return(input.Value <long>() == pattern.Value <long>() ? MatchCollectionHelper.CreateWithEmptyMatch() : null); case JTokenType.Boolean: return(input.Value <bool>() == pattern.Value <bool>() ? MatchCollectionHelper.CreateWithEmptyMatch() : null); default: throw new NotSupportedJTokenTypeException(pattern); } }
public IEnumerable <string> LoadRules() { var ruleRepository = new ServiceParityRuleRepository(this.context.ConfigManager); this.context.TelemetryManager.WriteLog( TelemetryLogLevel.Information, TelemetryLogSection, "Retrieving rules from configuration store..."); this.rules = ruleRepository.GetRules(); this.context.TelemetryManager.WriteLog( TelemetryLogLevel.Information, TelemetryLogSection, FormattableString.Invariant($"{this.rules.Count()} rules retrieved from configuration store")); return(this.rules .Select(r => r.Pattern.Value <string>("type")) .Where(s => !PlaceholderHelper.IsPlaceholder(s, out var unused)) .Distinct(StringComparer.OrdinalIgnoreCase)); }