From 2e96ba58624ad6d5ffc743dfd1fed954980c690c Mon Sep 17 00:00:00 2001 From: harshgMSFT Date: Wed, 21 May 2014 18:28:08 -0700 Subject: [PATCH] Updating Class and file names according to PR feedback. --- .../Constraints/CompositeRouteConstraint.cs | 19 +-- .../Constraints/CompoundRouteConstraint.cs | 46 -------- .../InlineRouteParameterParser.cs | 1 - .../InlineRouteTemplateParser.cs | 110 ------------------ 4 files changed, 2 insertions(+), 174 deletions(-) delete mode 100644 src/Microsoft.AspNet.Routing/Constraints/CompoundRouteConstraint.cs delete mode 100644 src/Microsoft.AspNet.Routing/InlineRouteTemplateParser.cs diff --git a/src/Microsoft.AspNet.Routing/Constraints/CompositeRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/CompositeRouteConstraint.cs index ff9ace0bb6..bfe5e2e216 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/CompositeRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/CompositeRouteConstraint.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using Microsoft.AspNet.Http; -namespace Microsoft.AspNet.Routing.Constraints +namespace Microsoft.AspNet.Routing { /// /// Constrains a route by several child constraints. @@ -25,22 +25,7 @@ namespace Microsoft.AspNet.Routing.Constraints /// public IEnumerable Constraints { get; private set; } - /// - /// Calls Match on the child constraints. - /// The call returns as soon as one of the child constraints does not match. - /// - /// The HTTP context associated with the current call. - /// The route that is being constrained. - /// The route key used for the constraint. - /// The route value dictionary. - /// The direction of the routing, - /// i.e. incoming request or URL generation. - /// True if all the constraints Match, - /// false as soon as one of the child constraints does not match. - /// - /// There is no guarantee for the order in which child constraints are invoked, - /// also the method returns as soon as one of the constraints does not match. - /// + /// public bool Match([NotNull] HttpContext httpContext, [NotNull] IRouter route, [NotNull] string routeKey, diff --git a/src/Microsoft.AspNet.Routing/Constraints/CompoundRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/CompoundRouteConstraint.cs deleted file mode 100644 index c03a2854b3..0000000000 --- a/src/Microsoft.AspNet.Routing/Constraints/CompoundRouteConstraint.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using Microsoft.AspNet.Http; - -namespace Microsoft.AspNet.Routing -{ - /// - /// Constrains a route by several child constraints. - /// - public class CompoundRouteConstraint : IRouteConstraint - { - /// - /// Initializes a new instance of the class. - /// - /// The child constraints that must match for this constraint to match. - public CompoundRouteConstraint([NotNull] IEnumerable constraints) - { - Constraints = constraints; - } - - /// - /// Gets the child constraints that must match for this constraint to match. - /// - public IEnumerable Constraints { get; private set; } - - /// - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, - RouteDirection routeDirection) - { - foreach (var constraint in Constraints) - { - if (!constraint.Match(httpContext, route, routeKey, values, routeDirection)) - { - return false; - } - } - - return true; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Routing/InlineRouteParameterParser.cs b/src/Microsoft.AspNet.Routing/InlineRouteParameterParser.cs index 5209b40e87..c05c323af6 100644 --- a/src/Microsoft.AspNet.Routing/InlineRouteParameterParser.cs +++ b/src/Microsoft.AspNet.Routing/InlineRouteParameterParser.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Text.RegularExpressions; using Microsoft.AspNet.Routing.Template; -using Microsoft.AspNet.Routing.Constraints; namespace Microsoft.AspNet.Routing { diff --git a/src/Microsoft.AspNet.Routing/InlineRouteTemplateParser.cs b/src/Microsoft.AspNet.Routing/InlineRouteTemplateParser.cs deleted file mode 100644 index 03903511b7..0000000000 --- a/src/Microsoft.AspNet.Routing/InlineRouteTemplateParser.cs +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Diagnostics.Contracts; -using System.Text.RegularExpressions; -using Microsoft.AspNet.Routing.Template; - -namespace Microsoft.AspNet.Routing -{ - public static class InlineRouteParameterParser - { - // One or more characters, matches "id" - private const string ParameterNamePattern = @"(?.+?)"; - - // Zero or more inline constraints that start with a colon followed by zero or more characters - // Optionally the constraint can have arguments within parentheses - // - necessary to capture characters like ":" and "}" - // Matches ":int", ":length(2)", ":regex(\})", ":regex(:)" zero or more times - private const string ConstraintPattern = @"(:(?.*?(\(.*?\))?))*"; - - // A default value with an equal sign followed by zero or more characters - // Matches "=", "=abc" - private const string DefaultValueParameter = @"(?(=.*?))?"; - - private static readonly Regex _parameterRegex = new Regex( - "^" + ParameterNamePattern + ConstraintPattern + DefaultValueParameter + "$", - RegexOptions.CultureInvariant | RegexOptions.IgnoreCase); - public static TemplatePart ParseRouteParameter([NotNull] string routeParameter, - [NotNull] IInlineConstraintResolver constraintResolver) - { - var isCatchAll = routeParameter.StartsWith("*", StringComparison.Ordinal); - var isOptional = routeParameter.EndsWith("?", StringComparison.Ordinal); - - routeParameter = isCatchAll ? routeParameter.Substring(1) : routeParameter; - routeParameter = isOptional ? routeParameter.Substring(0, routeParameter.Length - 1) : routeParameter; - - var parameterMatch = _parameterRegex.Match(routeParameter); - if (!parameterMatch.Success) - { - return TemplatePart.CreateParameter(name: string.Empty, - isCatchAll: isCatchAll, - isOptional: isOptional, - defaultValue: null, - inlineConstraint: null - ); - } - - var parameterName = parameterMatch.Groups["parameterName"].Value; - - // Add the default value if present - var defaultValueGroup = parameterMatch.Groups["defaultValue"]; - var defaultValue = GetDefaultValue(defaultValueGroup); - - // Register inline constraints if present - var constraintGroup = parameterMatch.Groups["constraint"]; - var inlineConstraint = GetInlineConstraint(constraintGroup, constraintResolver); - - return TemplatePart.CreateParameter(parameterName, - isCatchAll, - isOptional, - defaultValue, - inlineConstraint); - } - - private static string GetDefaultValue(Group defaultValueGroup) - { - if (defaultValueGroup.Success) - { - var defaultValueMatch = defaultValueGroup.Value; - - // Strip out the equal sign at the beginning - Contract.Assert(defaultValueMatch.StartsWith("=", StringComparison.Ordinal)); - return defaultValueMatch.Substring(1); - } - - return null; - } - - private static IRouteConstraint GetInlineConstraint(Group constraintGroup, - IInlineConstraintResolver constraintResolver) - { - var parameterConstraints = new List(); - foreach (Capture constraintCapture in constraintGroup.Captures) - { - var inlineConstraint = constraintCapture.Value; - var constraint = constraintResolver.ResolveConstraint(inlineConstraint); - if (constraint == null) - { - throw new InvalidOperationException( - Resources.FormatInlineRouteParser_CouldNotResolveConstraint( - constraintResolver.GetType().Name, inlineConstraint)); - } - - parameterConstraints.Add(constraint); - } - - if (parameterConstraints.Count > 0) - { - var constraint = parameterConstraints.Count == 1 ? - parameterConstraints[0] : - new CompoundRouteConstraint(parameterConstraints); - return constraint; - } - - return null; - } - } -} \ No newline at end of file