private IEnumerable <QualifiedRoute> ResolveFullMethodRoutes(string route,
                                                                     IRouteConstraint constraint, object dataTokens)
        {
            if (_handlerRoutes != null)
            {
                foreach (var hr in _handlerRoutes)
                {
                    var t = route;
                    if (!string.IsNullOrEmpty(hr.Template))
                    {
                        t = $"{hr.Template.TrimEnd('/')}/{t.TrimStart('/')}";
                    }
                    var c = constraint;
                    if (c == null)
                    {
                        c = hr.Constraint;
                    }
                    else if (hr.Constraint != null)
                    {
                        c = new CompositeRouteConstraint(new[] { c, constraint });
                    }

                    yield return(new QualifiedRoute(t, c, dataTokens));
                }
            }
            else
            {
                yield return(new QualifiedRoute(route, constraint, dataTokens));
            }
        }
        private bool PassConstraint(ParameterDescriptor parameter, IRouteConstraint constraint)
        {
            var isValid = false;

            if (constraint is OptionalRouteConstraint optionalRouteConstraint)
            {
                isValid = IsValidRouteConstraint(parameter, optionalRouteConstraint.InnerConstraint);
            }
            else if (constraint is RegexRouteConstraint regexRouteConstraint)
            {
                var parameterType = parameter.ParameterType;
                if (parameterType.IsValueType)
                {
                    var regex            = regexRouteConstraint.Constraint;
                    var defaultTypeValue = Activator.CreateInstance(parameterType);
                    isValid = regex.IsMatch(defaultTypeValue.ToString());
                }
                else if (constraint is AlphaRouteConstraint && parameter.BindingInfo == null)
                {
                    isValid = true;
                }
            }
            else if (constraint is DateTimeRouteConstraint)
            {
                isValid = parameter.ParameterType == typeof(DateTime);
            }
            else
            {
                isValid = IsValidRouteConstraint(parameter, constraint);
            }

            return(isValid);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CatchAllParameterSegment"/> class.
 /// </summary>
 /// <param name="parameterName">Name of the parameter.</param>
 /// <param name="defaultValue">The default value.</param>
 /// <param name="constraint">The constraint.</param>
 public CatchAllParameterSegment(string parameterName, object defaultValue, object constraint)
 {
     Guard.ArgumentNotNullOrEmpty(parameterName, "parameterName");
     this.parameterName = parameterName;
     this.defaultValue = defaultValue;
     
     if (constraint is string)
     {
         this.constraint = new RegexConstraint((string)constraint);
     }
     else if (constraint is IRouteConstraint)
     {
         this.constraint = (IRouteConstraint)constraint;
     }
     else if (constraint is Regex)
     {
         this.constraint = new RegexConstraint((Regex)constraint);
     }
     else if (constraint == UrlParameter.NotSpecified)
     {
         this.constraint = null;
     }
     else if (constraint != null)
     {
         throw new UnsupportedConstraintException("The parameter '{0}' was given an invalid constraints. Constraints must be strings, Regex's or objects that implement IRouteConstraint");
     }
 }
        public static IRouteBuilder AddDefaultPageRouteForSimpleContent(
            this IRouteBuilder routes,
            IRouteConstraint siteFolderConstraint
            )
        {
            routes.MapRoute(
                name: ProjectConstants.FolderPageEditRouteName,
                template: "{sitefolder}/edit/{slug?}"
                , defaults: new { controller = "Page", action = "Edit" }
                , constraints: new { name = siteFolderConstraint }
                );

            routes.MapRoute(
                name: ProjectConstants.FolderPageDeleteRouteName,
                template: "{sitefolder}/delete/{id}"
                , defaults: new { controller = "Page", action = "Delete" }
                , constraints: new { name = siteFolderConstraint }
                );

            routes.MapRoute(
                name: ProjectConstants.FolderPageIndexRouteName,
                template: "{sitefolder}/{slug=none}"
                , defaults: new { controller = "Page", action = "Index" }
                , constraints: new { name = siteFolderConstraint }
                );



            return(routes);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Gets a regular expression that handles the specified constraint type
 /// </summary>
 /// <param name="constraint"></param>
 /// <returns></returns>
 private static string GetRegexForConstraint(IRouteConstraint constraint)
 {
     if (constraint is RegexRouteConstraint)
     {
         return(((RegexRouteConstraint)constraint).Constraint.ToString());
     }
     if (constraint is BoolRouteConstraint)
     {
         return(@"^(True|False)$");
     }
     if (
         constraint is DecimalRouteConstraint ||
         constraint is DoubleRouteConstraint ||
         constraint is FloatRouteConstraint ||
         constraint is LongRouteConstraint
         )
     {
         return(@"^[+\-]?^\d+\.?\d+$");
     }
     if (constraint is GuidRouteConstraint)
     {
         return("^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$");
     }
     if (constraint is IntRouteConstraint)
     {
         return(@"^[+\-]?\d+$");
     }
     return(null);
 }
Ejemplo n.º 6
0
        protected virtual bool ProcessConstraint(HttpContextBase httpContext, object constraint, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            IRouteConstraint customConstraint = constraint as IRouteConstraint;

            if (customConstraint != null)
            {
                return(customConstraint.Match(httpContext, this, parameterName, values, routeDirection));
            }

            // If there was no custom constraint, then treat the constraint as a string which represents a Regex.
            string constraintsRule = constraint as string;

            if (constraintsRule == null)
            {
                throw new InvalidOperationException(String.Format(
                                                        CultureInfo.CurrentUICulture,
                                                        SR.GetString(SR.Route_ValidationMustBeStringOrCustomConstraint),
                                                        parameterName,
                                                        Url));
            }

            object parameterValue;

            values.TryGetValue(parameterName, out parameterValue);
            string parameterValueString = Convert.ToString(parameterValue, CultureInfo.InvariantCulture);
            string constraintsRegEx     = "^(" + constraintsRule + ")$";

            return(Regex.IsMatch(parameterValueString, constraintsRegEx,
                                 RegexOptions.CultureInvariant | RegexOptions.IgnoreCase));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Determines whether the URL parameter contains a valid value for this constraint.
        /// </summary>
        /// <param name="httpContext">An object that encapsulates information about the HTTP request.</param>
        /// <param name="route">The object that this constraint belongs to.</param>
        /// <param name="parameterName">The name of the parameter that is being checked.</param>
        /// <param name="values">An object that contains the parameters for the URL.</param>
        /// <param name="routeDirection">An object that indicates whether the constraint check is being performed when an incoming request is being handled or when a URL is being generated.</param>
        /// <returns>
        /// true if the URL parameter contains a valid value; otherwise, false.
        /// </returns>
        public bool Match(System.Web.HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            object parameterValue;

            values.TryGetValue(parameterName, out parameterValue);

            string requestedControllerName = Convert.ToString(parameterValue, CultureInfo.InvariantCulture);

            if (!controllerNames.Value.Contains(requestedControllerName))
            {
                return(false);
            }

            if (innerConstraint != null)
            {
                IRouteConstraint customConstraint = innerConstraint as IRouteConstraint;
                if (customConstraint != null)
                {
                    return(customConstraint.Match(httpContext, route, parameterName, values, routeDirection));
                }

                // If there was no custom constraint, then treat the constraint as a string which represents a Regex.
                string constraintsRule = innerConstraint as string;
                if (constraintsRule == null)
                {
                    throw new InvalidOperationException(string.Format("The constraint has an invalid type, {3} or string expected. ParameterName {0}, Route {1}", parameterName, route.Url, typeof(IRouteConstraint).Name));
                }

                string constraintsRegEx = "^(" + constraintsRule + ")$";
                return(Regex.IsMatch(requestedControllerName, constraintsRegEx, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase));
            }

            return(true);
        }
Ejemplo n.º 8
0
 internal static void Constraint(IRouteConstraint constraint)
 {
     if (constraint == null)
     {
         throw Error.ArgumentNull("constraint");
     }
 }
Ejemplo n.º 9
0
        internal UnversionedODataPathRouteConstraint(IRouteConstraint innerConstraint, ApiVersion apiVersion)
        {
            Contract.Requires(innerConstraint != null);

            innerConstraints = new[] { innerConstraint };
            this.apiVersion  = apiVersion;
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Automatically applies the specified constaint against url parameters
 /// with names that match the given regular expression.
 /// </summary>
 /// <param name="keyRegex">The regex used to match url parameter names</param>
 /// <param name="constraint">The constraint to apply to matched parameters</param>
 public void AddDefaultRouteConstraint(string keyRegex, IRouteConstraint constraint)
 {
     if (!DefaultRouteConstraints.ContainsKey(keyRegex))
     {
         DefaultRouteConstraints.Add(keyRegex, constraint);
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CatchAllParameterSegment"/> class.
        /// </summary>
        /// <param name="parameterName">Name of the parameter.</param>
        /// <param name="defaultValue">The default value.</param>
        /// <param name="constraint">The constraint.</param>
        public CatchAllParameterSegment(string parameterName, object defaultValue, object constraint)
        {
            Guard.ArgumentNotNullOrEmpty(parameterName, "parameterName");
            this.parameterName = parameterName;
            this.defaultValue  = defaultValue;

            if (constraint is string)
            {
                this.constraint = new RegexConstraint((string)constraint);
            }
            else if (constraint is IRouteConstraint)
            {
                this.constraint = (IRouteConstraint)constraint;
            }
            else if (constraint is Regex)
            {
                this.constraint = new RegexConstraint((Regex)constraint);
            }
            else if (constraint == UrlParameter.NotSpecified)
            {
                this.constraint = null;
            }
            else if (constraint != null)
            {
                throw new UnsupportedConstraintException("The parameter '{0}' was given an invalid constraints. Constraints must be strings, Regex's or objects that implement IRouteConstraint");
            }
        }
Ejemplo n.º 12
0
        internal static bool ProcessConstraintInternal(HttpContextBase httpContext, Route route, object constraint, string parameterName,
                                                       RouteValueDictionary values, RouteDirection routeDirection, out bool invalidConstraint)
        {
            invalidConstraint = false;
            IRouteConstraint irc = constraint as IRouteConstraint;

            if (irc != null)
            {
                return(irc.Match(httpContext, route, parameterName, values, routeDirection));
            }

            string s = constraint as string;

            if (s != null)
            {
                string v = values [parameterName] as string;
                if (!String.IsNullOrEmpty(v))
                {
                    return(Regex.Match(v, s).Success);
                }
                return(false);
            }

            invalidConstraint = true;
            return(false);
        }
        public static bool Match(this IRouteConstraint constraint, string parameterName, string value)
        {
            var routeValueDictionary = new RouteValueDictionary();

            routeValueDictionary.Add(parameterName, value);
            return(constraint.Match(null, null, parameterName, routeValueDictionary, RouteDirection.IncomingRequest));
        }
Ejemplo n.º 14
0
 public SchemeRouteConstraintTest()
 {
     m_mockHttpContext = MockHttpFactory.GetHttpContext();
     m_constraint      = new SchemeRouteConstraint();
     m_variables       = new NameValueCollection();
     m_variables.Add("X_FORWARDED_PROTO", "https");
 }
        public IgnoreLocalHostConstraintDecorator(IRouteConstraint constraint)
        {
            if ( constraint == null )
                throw new ArgumentNullException("constraint");

            _constraint = constraint;
        }
Ejemplo n.º 16
0
		/// <summary>
		/// Gets a regular expression that handles the specified constraint type
		/// </summary>
		/// <param name="constraint"></param>
		/// <returns></returns>
		private static string GetRegexForConstraint(IRouteConstraint constraint)
		{
			if (constraint is RegexRouteConstraint)
			{
				return ((RegexRouteConstraint) constraint).Constraint.ToString();
			}
			if (constraint is BoolRouteConstraint)
			{
				return @"^(True|False)$";
			}
			if (
				constraint is DecimalRouteConstraint || 
				constraint is DoubleRouteConstraint || 
				constraint is FloatRouteConstraint ||
				constraint is LongRouteConstraint
			)
			{
				return @"^[+\-]?^\d+\.?\d+$";
			}
			if (constraint is GuidRouteConstraint)
			{
				return "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$";
			}
			if (constraint is IntRouteConstraint)
			{
				return @"^[+\-]?\d+$";
			}
			return null;
		}
Ejemplo n.º 17
0
        /// <summary>
        ///   Configures a URL route with the specified constraint object.
        ///   Any existing constraint with an equal key is replaced.
        /// </summary>
        /// <param name="route">The URL route.</param>
        /// <param name="key">The unique key of the constraint.</param>
        /// <param name="constraint">The constraint object.</param>
        /// <returns>The URL route.</returns>
        /// <exception cref="ArgumentNullException">
        ///   Either <paramref name="route"/>, <paramref name="key"/>, or <paramref name="constraint"/> is <c>null</c>.
        /// </exception>
        public static Route WithConstraint(this Route route, string key, IRouteConstraint constraint)
        {
            Require.Route(route);
            Require.Key(key);
            Require.Constraint(constraint);

            return(WithConstraintCore(route, key, constraint));
        }
Ejemplo n.º 18
0
 public static void ConstraintNotMatched(
     this ILogger logger,
     object routeValue,
     string routeKey,
     IRouteConstraint routeConstraint)
 {
     _constraintNotMatched(logger, routeValue, routeKey, routeConstraint, null);
 }
 public static void RouteValueDoesNotMatchConstraint(
     this ILogger logger,
     object routeValue,
     string routeKey,
     IRouteConstraint routeConstraint)
 {
     _routeValueDoesNotMatchConstraint(logger, routeValue, routeKey, routeConstraint, null);
 }
 public static void RouteValueDoesNotMatchConstraint(
     this ILogger logger,
     object routeValue,
     string routeKey,
     IRouteConstraint routeConstraint)
 {
     _routeValueDoesNotMatchConstraint(logger, routeValue, routeKey, routeConstraint, null);
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Creates a new <see cref="OptionalRouteConstraint"/> instance given the <paramref name="innerConstraint"/>.
        /// </summary>
        /// <param name="innerConstraint"></param>
        public OptionalRouteConstraint(IRouteConstraint innerConstraint)
        {
            if (innerConstraint == null)
            {
                throw new ArgumentNullException(nameof(innerConstraint));
            }

            InnerConstraint = innerConstraint;
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Creates a <see cref="RoutePatternParameterPolicyReference"/> from the provided constraint.
        /// </summary>
        /// <param name="constraint">
        /// The constraint object.
        /// </param>
        /// <returns>The <see cref="RoutePatternParameterPolicyReference"/>.</returns>
        public static RoutePatternParameterPolicyReference Constraint(IRouteConstraint constraint)
        {
            if (constraint == null)
            {
                throw new ArgumentNullException(nameof(constraint));
            }

            return(ParameterPolicyCore(constraint));
        }
Ejemplo n.º 23
0
 public static IServiceCollection AddApiRouteConstraint(this IServiceCollection services,
                                                        IRouteConstraint routeConstraint, string namespacePrefix)
 {
     if (namespacePrefix == null)
     {
         throw new ArgumentNullException(nameof(namespacePrefix));
     }
     return(AddApiRouteConstraint(services, routeConstraint, new NamespaceActionTypeFilter(namespacePrefix)));
 }
        public override MatchProcessor Create(string parameterName, IRouteConstraint value, bool optional)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            return(InitializeMatchProcessor(parameterName, optional, value, argument: null));
        }
        public static IRouteBuilder AddBlogRoutesForSimpleContent(
            this IRouteBuilder routes,
            IRouteConstraint siteFolderConstraint
            )
        {
            routes.MapRoute(
                name: ProjectConstants.FolderBlogCategoryRouteName,
                template: "{sitefolder}/blog/category/{category=''}/{pagenumber=1}"
                , defaults: new { controller = "Blog", action = "Category" }
                , constraints: new { name = siteFolderConstraint }
                );

            routes.MapRoute(
                ProjectConstants.FolderBlogArchiveRouteName,
                "{sitefolder}/blog/{year}/{month}/{day}",
                new { controller = "Blog", action = "Archive", month = "00", day = "00" },
                new { name = siteFolderConstraint, year = @"\d{4}", month = @"\d{2}", day = @"\d{2}" }
                );

            routes.MapRoute(
                ProjectConstants.FolderPostWithDateRouteName,
                "{sitefolder}/blog/{year}/{month}/{day}/{slug}",
                new { controller = "Blog", action = "PostWithDate" },
                new { name = siteFolderConstraint, year = @"\d{4}", month = @"\d{2}", day = @"\d{2}" }
                );

            routes.MapRoute(
                name: ProjectConstants.FolderNewPostRouteName,
                template: "{sitefolder}/blog/new"
                , defaults: new { controller = "Blog", action = "New" }
                , constraints: new { name = siteFolderConstraint }
                );

            routes.MapRoute(
                name: ProjectConstants.FolderMostRecentPostRouteName,
                template: "{sitefolder}/blog/mostrecent"
                , defaults: new { controller = "Blog", action = "MostRecent" }
                , constraints: new { name = siteFolderConstraint }
                );

            routes.MapRoute(
                name: ProjectConstants.FolderPostWithoutDateRouteName,
                template: "{sitefolder}/blog/{slug}"
                , defaults: new { controller = "Blog", action = "PostNoDate" }
                , constraints: new { name = siteFolderConstraint }
                );

            routes.MapRoute(
                name: ProjectConstants.FolderBlogIndexRouteName,
                template: "{sitefolder}/blog/"
                , defaults: new { controller = "Blog", action = "Index" }
                , constraints: new { name = siteFolderConstraint }
                );


            return(routes);
        }
Ejemplo n.º 26
0
        public OptionalRouteConstraint(IRouteConstraint innerConstraint)
        {
            if (innerConstraint == null)
            {
                throw new ArgumentNullException(nameof(innerConstraint));
            }

            InnerConstraint = innerConstraint;
        }
 private static bool EasyMatch(IRouteConstraint constraint,
                               string routeKey,
                               RouteValueDictionary values)
 {
     return(constraint.Match(httpContext: new Mock <HttpContext>().Object,
                             route: new Mock <IRouter>().Object,
                             routeKey: routeKey,
                             values: values,
                             routeDirection: RouteDirection.IncomingRequest));
 }
Ejemplo n.º 28
0
        private void Add(string key, IRouteConstraint constraint)
        {
            if (!_constraints.TryGetValue(key, out var list))
            {
                list = new List <IRouteConstraint>();
                _constraints.Add(key, list);
            }

            list.Add(constraint);
        }
        private MatchProcessor InitializeMatchProcessor(
            string parameterName,
            bool optional,
            IRouteConstraint constraint,
            string argument)
        {
            var matchProcessor = (MatchProcessor) new RouteConstraintMatchProcessor(parameterName, constraint);

            return(InitializeMatchProcessor(parameterName, optional, matchProcessor, argument));
        }
        public OptionalRouteConstraint(IRouteConstraint innerConstraint)
#endif
        {
            if (innerConstraint == null)
            {
                throw Error.ArgumentNull("innerConstraint");
            }

            InnerConstraint = innerConstraint;
        }
Ejemplo n.º 31
0
        public OptionalRouteConstraint(IRouteConstraint innerConstraint)
#endif
        {
            if (innerConstraint == null)
            {
                throw Error.ArgumentNull("innerConstraint");
            }

            InnerConstraint = innerConstraint;
        }
Ejemplo n.º 32
0
        public static bool TestConstraint(IRouteConstraint constraint, object value)
        {
            var parameterName = "fake";
            var values        = new RouteValueDictionary()
            {
                { parameterName, value }
            };
            var routeDirection = RouteDirection.IncomingRequest;

            return(constraint.Match(httpContext: null, route: null, parameterName, values, routeDirection));
        }
        internal static string GetKey(this IRouteConstraint routeConstraint)
        {
            if (routeConstraint == null)
            {
                throw new ArgumentNullException(nameof(routeConstraint));
            }

            return(routeConstraint is IKeyedRouteContraint keyedRouteConstraint
                ? keyedRouteConstraint.Key
                : string.Concat(routeConstraint.GetType().ToString(), "_", routeConstraint.GetHashCode()));
        }
Ejemplo n.º 34
0
        private IParameterPolicy InitializeRouteConstraint(
            bool optional,
            IRouteConstraint routeConstraint)
        {
            if (optional)
            {
                routeConstraint = new OptionalRouteConstraint(routeConstraint);
            }

            return(routeConstraint);
        }
Ejemplo n.º 35
0
        internal static bool TestRouteConstraint(IRouteConstraint constraint, object value)
        {
            var route   = new RouteCollection();
            var context = new Mock <HttpContext>();

            const string ParameterName = "fake";
            var          values        = new RouteValueDictionary {
                { ParameterName, value }
            };

            return(constraint.Match(context.Object, route, ParameterName, values, RouteDirection.IncomingRequest));
        }
Ejemplo n.º 36
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataRoute"/> class.
        /// </summary>
        /// <param name="target">The target router.</param>
        /// <param name="routeName">The route name.</param>
        /// <param name="routePrefix">The route prefix.</param>
        /// <param name="routeConstraint">The OData route constraint.</param>
        /// <param name="resolver">The inline constraint resolver.</param>
        /// <remarks>This signature uses types that are AspNetCore-specific.</remarks>
        public ODataRoute(IRouter target, string routeName, string routePrefix, IRouteConstraint routeConstraint, IInlineConstraintResolver resolver)
            : base(target, routeName, GetRouteTemplate(routePrefix), defaults: null, constraints: null, dataTokens: null, inlineConstraintResolver: resolver)
        {
            RouteConstraint = routeConstraint;
            Initialize(routePrefix, routeConstraint as ODataPathRouteConstraint);

            if (routeConstraint != null)
            {
                Constraints.Add(ODataRouteConstants.ConstraintName, routeConstraint);
            }

            Constraints.Add(ODataRouteConstants.VersionConstraintName, new ODataVersionConstraint());
        }
Ejemplo n.º 37
0
        public static bool TestConstraint(IRouteConstraint constraint, object value, Action<IRouter> routeConfig = null)
        {
            var context = new Mock<HttpContext>();

            var route = new RouteCollection();

            if (routeConfig != null)
            {
                routeConfig(route);
            }

            var parameterName = "fake";
            var values = new RouteValueDictionary() { { parameterName, value } };
            var routeDirection = RouteDirection.IncomingRequest;
            return constraint.Match(context.Object, route, parameterName, values, routeDirection);
        }
Ejemplo n.º 38
0
        public void ExtendsRouteConstraintConstraints(RoutesInspector sut, IInspectorContext context, NewRoute route, Route newRoute, IRouteConstraint routeConstraint, IRouteConstraint newRouteConstraint)
        {
            route.Constraints = new RouteValueDictionary { { "controller", routeConstraint } };

            RouteTable.Routes.Clear();
            RouteTable.Routes.Add("Test", route);

            context.ProxyFactory.Setup(x => x.IsWrapClassEligible(typeof(Route))).Returns(true).Verifiable();
            context.ProxyFactory.Setup(x => x.WrapClass((Route)route, It.IsAny<IEnumerable<IAlternateMethod>>(), It.IsAny<IEnumerable<object>>(), It.IsAny<object[]>())).Returns(newRoute).Verifiable();
            context.ProxyFactory.Setup(x => x.IsWrapInterfaceEligible<IRouteConstraint>(typeof(IRouteConstraint))).Returns(true).Verifiable();
            context.ProxyFactory.Setup(x => x.WrapInterface(routeConstraint, It.IsAny<IEnumerable<IAlternateMethod>>(), It.IsAny<IEnumerable<object>>())).Returns(newRouteConstraint).Verifiable();

            sut.Setup(context);

            context.ProxyFactory.VerifyAll();
            Assert.Same(newRouteConstraint, route.Constraints["controller"]);
        }
Ejemplo n.º 39
0
 public void AddRouteConstraint(string inputName, IRouteConstraint constraint)
 {
     _constraints[inputName] = constraint;
 }
Ejemplo n.º 40
0
        protected virtual bool MatchConstraint(HttpContextBase context, 
            IRouteConstraint constraint, ValueDictionary values, 
			RouteDirection direction)
        {
            return constraint.Match(context, this, values, direction);
        }
Ejemplo n.º 41
0
 public NotConstraint(IRouteConstraint constraint)
 {
     _constraint = constraint;
 }
 public OptionalRouteConstraint(IRouteConstraint constraint)
 {
     _constraint = constraint;
 }
 /// <summary>
 /// Automatically applies the specified constaint against url parameters
 /// with names that match the given regular expression.
 /// </summary>
 /// <param name="keyRegex">The regex used to match url parameter names</param>
 /// <param name="constraint">The constraint to apply to matched parameters</param>
 public void AddDefaultRouteConstraint(string keyRegex, IRouteConstraint constraint)
 {
     base.AddDefaultRouteConstraint(keyRegex, constraint);
 }
Ejemplo n.º 44
0
        #pragma warning disable 1573 // Parameter does not have XML comment.
        /// <summary>
        /// Sets constraint for a route URL parameter expressed as an arbitrary route constraint.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If a constraint for the URL parameter is already set it will be overwritten by the <paramref name="constraint"/>.
        /// </para>
        /// <note type="caution">
        /// If the <paramref name="constraint"/> throws an exception, that exception will be propagated to the caller.
        /// </note>
        /// </remarks>
        /// <inheritdoc cref="SetConstraint(Route, string, Predicate{object})" source="param[@name='route']"/>
        /// <inheritdoc cref="SetConstraint(Route, string, Predicate{object})" source="param[@name='urlParameter']"/>
        /// <param name="constraint">Route constraint that checks whether the value of the <paramref name="urlParameter"/> is valid.</param>
        /// <inheritdoc cref="SetDefault(Route, string, object)" source="returns"/>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="route"/> is null.<br/>-or-<br/><paramref name="urlParameter"/> is null.<br/>-or-<br/><paramref name="constraint"/> is null.
        /// </exception>
        /// <exception cref="ArgumentException"><paramref name="urlParameter"/> is empty string.<br/>-or-<br/><paramref name="urlParameter"/> is white space.</exception>
        public static Route SetConstraint(this Route route, string urlParameter, IRouteConstraint constraint)
        {
            Argument.IsNotNull(route, "route");
            Argument.IsNotNullOrWhitespace(urlParameter, "urlParameter");
            Argument.IsNotNull(constraint, "predicate");

            if (route.Constraints == null) route.Constraints = new RouteValueDictionary();

            route.Constraints[urlParameter] = constraint;

            return route;
        }
Ejemplo n.º 45
0
 private static bool EasyMatch(IRouteConstraint constraint,
                               string routeKey,
                               RouteValueDictionary values)
 {
     return constraint.Match(httpContext: new Mock<HttpContext>().Object,
         route: new Mock<IRouter>().Object,
         routeKey: routeKey,
         values: values,
         routeDirection: RouteDirection.IncomingRequest);
 }
Ejemplo n.º 46
0
 public void AddRouteConstraint(string inputName, IRouteConstraint constraint)
 {
 }
 public QueryStringRouteConstraint(IRouteConstraint constraint)
 {
     _constraint = constraint;
 }
Ejemplo n.º 48
0
 public static void Register(string name, IRouteConstraint constraint)
 {
     constraints[name] = constraint;
 }
 public OptionalRouteConstraintWrapper(IRouteConstraint constraint)
 {
     _constraint = constraint;
 }
Ejemplo n.º 50
0
 /// <summary>
 /// Provides a fluent way of adding constraints to a route.
 /// </summary>
 public static Route WithConstraint(this Route route, string key, IRouteConstraint contraint)
 {
     route.Constraints.Add(key, contraint);
     return route;
 }
Ejemplo n.º 51
0
        private void Add(string key, IRouteConstraint constraint)
        {
            List<IRouteConstraint> list;
            if (!_constraints.TryGetValue(key, out list))
            {
                list = new List<IRouteConstraint>();
                _constraints.Add(key, list);
            }

            list.Add(constraint);
        }
Ejemplo n.º 52
0
 ParameterBuilder IParameterBuilder.AddConstraint(IRouteConstraint constraint)
 {
     _constraints.Add(constraint);
     return this;
 }