コード例 #1
0
        public UriMatchCondition(InputParser inputParser, string input, string pattern, UriMatchPart uriMatchPart, bool ignoreCase, bool negate)
        {
            var regexOptions = RegexOptions.CultureInvariant | RegexOptions.Compiled;

            regexOptions = ignoreCase ? regexOptions | RegexOptions.IgnoreCase : regexOptions;
            var regex = new Regex(
                pattern,
                regexOptions,
                _regexTimeout
                );

            Input = inputParser.ParseInputString(input, uriMatchPart);
            Match = new RegexMatch(regex, negate);
        }
コード例 #2
0
        private void ParseCondition(XElement conditionElement, UrlRewriteRuleBuilder builder, PatternSyntax patternSyntax)
        {
            var ignoreCase        = ParseBool(conditionElement, RewriteTags.IgnoreCase, defaultValue: true);
            var negate            = ParseBool(conditionElement, RewriteTags.Negate, defaultValue: false);
            var matchType         = ParseEnum(conditionElement, RewriteTags.MatchType, MatchType.Pattern);
            var parsedInputString = conditionElement.Attribute(RewriteTags.Input)?.Value;

            if (parsedInputString == null)
            {
                throw new InvalidUrlRewriteFormatException(conditionElement, "Conditions must have an input attribute");
            }

            var       parsedPatternString = conditionElement.Attribute(RewriteTags.Pattern)?.Value;
            Condition condition;

            switch (patternSyntax)
            {
            case PatternSyntax.ECMAScript:
            {
                switch (matchType)
                {
                case MatchType.Pattern:
                {
                    if (string.IsNullOrEmpty(parsedPatternString))
                    {
                        throw new FormatException("Match does not have an associated pattern attribute in condition");
                    }
                    condition = new UriMatchCondition(_inputParser, parsedInputString, parsedPatternString, builder.UriMatchPart, ignoreCase, negate);
                    break;
                }

                case MatchType.IsDirectory:
                {
                    condition = new Condition(_inputParser.ParseInputString(parsedInputString, builder.UriMatchPart), new IsDirectoryMatch(negate));
                    break;
                }

                case MatchType.IsFile:
                {
                    condition = new Condition(_inputParser.ParseInputString(parsedInputString, builder.UriMatchPart), new IsFileMatch(negate));
                    break;
                }

                default:
                    throw new FormatException("Unrecognized matchType");
                }
                break;
            }

            case PatternSyntax.Wildcard:
                throw new NotSupportedException("Wildcard syntax is not supported");

            case PatternSyntax.ExactMatch:
                if (string.IsNullOrEmpty(parsedPatternString))
                {
                    throw new FormatException("Match does not have an associated pattern attribute in condition");
                }
                condition = new Condition(_inputParser.ParseInputString(parsedInputString, builder.UriMatchPart), new ExactMatch(ignoreCase, parsedPatternString, negate));
                break;

            default:
                throw new FormatException("Unrecognized pattern syntax");
            }

            builder.AddUrlCondition(condition);
        }
コード例 #3
0
 private static Pattern CreatePattern(InputParser inputParser, string input, UriMatchPart uriMatchPart)
 {
     return(inputParser.ParseInputString(input, uriMatchPart));
 }