public bool Match(System.Web.HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
    {
        // for now skip the Url generation
        if (routeDirection.Equals(RouteDirection.UrlGeneration))
        {
            return(false);
        }

        // try to find out our parameters
        object theId1 = null;
        object theId2 = null;

        var parametersExist = values.TryGetValue("theId1", out theId1) &&
                              values.TryGetValue("theId2", out theId2);

        // not our case
        if (!parametersExist)
        {
            return(false);
        }

        // first argument re-inserted
        values["id1"] = theId1;
        values["id3"] = theId1;
        // TODO add other, remove theId1

        // second argument re-inserted
        values["id2"] = theId2;
        values["id4"] = theId2;
        // TODO add other, remove theId2


        return(true);
    }
Example #2
0
			/// <summary>
			/// Attempts to match the current request to an action with the constraint pattern.
			/// </summary>
			/// <param name="httpContext">The current HTTPContext of the request.</param>
			/// <param name="route">The route to which the constraint belongs.</param>
			/// <param name="paramName">Name of the parameter (irrelevant).</param>
			/// <param name="values">The url values to attempt to match.</param>
			/// <param name="routeDirection">The route direction (this method will ignore URL Generations).</param>
			/// <returns>True if a match has been found, false otherwise.</returns>
			public bool Match(HttpContextBase httpContext, Route route, string paramName, RouteValueDictionary values, RouteDirection routeDirection)
			{
				if (routeDirection.Equals(RouteDirection.UrlGeneration)) {
					return false;
				}
				Dictionary<string, object> unMappedList = values.Where(x => x.Key.Contains("param")).OrderBy(xi => xi.Key).ToDictionary(
					kvp => kvp.Key, kvp => kvp.Value);
				string controller = values["controller"] as string;
				string action = values["action"] as string;
				Type cont = TryFindController(controller);
				if (cont != null) {
					MethodInfo actionMethod = cont.GetMethod(action);
					if (actionMethod != null) {
						ParameterInfo[] methodParameters = actionMethod.GetParameters();
						if (validateParameters(methodParameters, unMappedList)) {
							for (int i = 0; i < methodParameters.Length; i++) {                            
								var key = unMappedList.ElementAt(i).Key;
								var value = values[key];
								values.Remove(key);
								values.Add(methodParameters.ElementAt(i).Name, value);
							}
							return true;
						}
					}
				}
				return false;
			}
        protected override bool Match(
			HttpContextBase httpContext,
			Route route,
			string parameterName,
			RouteValueDictionary values,
			RouteDirection routeDirection)
        {
            bool matches;
            if (routeDirection.Equals(RouteDirection.IncomingRequest))
            {
                var formMethod = httpContext.Request.Form["_method"];
                if (formMethod == null)
                {
                    matches = false;
                }
                else
                {
                    matches = base.Match(httpContext, route, parameterName, values, routeDirection);
                }
            }
            else
            {
                // Don't try to generate any URLs for this route; you need to use
                // a form value instead
                matches = false;
            }
            return matches;
        }
        public static bool Match(IReadOnlyDictionary <string, IRouteConstraint> constraints,
                                 [NotNull] IDictionary <string, object> routeValues,
                                 [NotNull] HttpContext httpContext,
                                 [NotNull] IRouter route,
                                 [NotNull] RouteDirection routeDirection,
                                 [NotNull] ILogger logger)
        {
            if (constraints == null)
            {
                return(true);
            }

            foreach (var kvp in constraints)
            {
                var constraint = kvp.Value;
                if (!constraint.Match(httpContext, route, kvp.Key, routeValues, routeDirection))
                {
                    if (routeDirection.Equals(RouteDirection.IncomingRequest) &&
                        logger.IsEnabled(LogLevel.Verbose))
                    {
                        logger.WriteValues(new RouteConstraintMatcherMatchValues()
                        {
                            ConstraintKey = kvp.Key,
                            Constraint    = kvp.Value,
                            Matched       = false
                        });
                    }

                    return(false);
                }

                if (routeDirection.Equals(RouteDirection.IncomingRequest) &&
                    logger.IsEnabled(LogLevel.Verbose))
                {
                    logger.WriteValues(new RouteConstraintMatcherMatchValues()
                    {
                        ConstraintKey = kvp.Key,
                        Constraint    = kvp.Value,
                        Matched       = true
                    });
                }
            }

            return(true);
        }
Example #5
0
        public static bool Match(IReadOnlyDictionary <string, IRouteConstraint> constraints,
                                 IDictionary <string, object> routeValues,
                                 HttpContext httpContext,
                                 IRouter route,
                                 RouteDirection routeDirection,
                                 ILogger logger)
        {
            if (routeValues == null)
            {
                throw new ArgumentNullException(nameof(routeValues));
            }

            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }

            if (route == null)
            {
                throw new ArgumentNullException(nameof(route));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (constraints == null)
            {
                return(true);
            }

            foreach (var kvp in constraints)
            {
                var constraint = kvp.Value;
                if (!constraint.Match(httpContext, route, kvp.Key, routeValues, routeDirection))
                {
                    if (routeDirection.Equals(RouteDirection.IncomingRequest))
                    {
                        object routeValue;
                        routeValues.TryGetValue(kvp.Key, out routeValue);

                        logger.LogVerbose(
                            "Route value '{RouteValue}' with key '{RouteKey}' did not match " +
                            "the constraint '{RouteConstraint}'.",
                            routeValue,
                            kvp.Key,
                            kvp.Value);
                    }

                    return(false);
                }
            }

            return(true);
        }
        public static bool Match(IReadOnlyDictionary<string, IRouteConstraint> constraints,
                                 IDictionary<string, object> routeValues,
                                 HttpContext httpContext,
                                 IRouter route,
                                 RouteDirection routeDirection,
                                 ILogger logger)
        {
            if (routeValues == null)
            {
                throw new ArgumentNullException(nameof(routeValues));
            }

            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }

            if (route == null)
            {
                throw new ArgumentNullException(nameof(route));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (constraints == null)
            {
                return true;
            }

            foreach (var kvp in constraints)
            {
                var constraint = kvp.Value;
                if (!constraint.Match(httpContext, route, kvp.Key, routeValues, routeDirection))
                {
                    if (routeDirection.Equals(RouteDirection.IncomingRequest))
                    {
                        object routeValue;
                        routeValues.TryGetValue(kvp.Key, out routeValue);

                        logger.LogVerbose(
                            "Route value '{RouteValue}' with key '{RouteKey}' did not match " +
                            "the constraint '{RouteConstraint}'.",
                            routeValue,
                            kvp.Key,
                            kvp.Value);
                    }

                    return false;
                }
            }

            return true;
        }
        public static bool Match(
            IDictionary<string, IRouteConstraint> constraints,
            RouteValueDictionary routeValues,
            HttpContext httpContext,
            IRouter route,
            RouteDirection routeDirection,
            ILogger logger)
        {
            if (routeValues == null)
            {
                throw new ArgumentNullException(nameof(routeValues));
            }

            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }

            if (route == null)
            {
                throw new ArgumentNullException(nameof(route));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (constraints == null)
            {
                return true;
            }

            foreach (var kvp in constraints)
            {
                var constraint = kvp.Value;
                if (!constraint.Match(httpContext, route, kvp.Key, routeValues, routeDirection))
                {
                    if (routeDirection.Equals(RouteDirection.IncomingRequest))
                    {
                        object routeValue;
                        routeValues.TryGetValue(kvp.Key, out routeValue);

                        logger.RouteValueDoesNotMatchConstraint(routeValue, kvp.Key, kvp.Value);
                    }

                    return false;
                }
            }

            return true;
        }
        public static bool Match(
            IDictionary <string, IRouteConstraint> constraints,
            RouteValueDictionary routeValues,
            HttpContext httpContext,
            IRouter route,
            RouteDirection routeDirection,
            ILogger logger)
        {
            if (routeValues == null)
            {
                throw new ArgumentNullException(nameof(routeValues));
            }

            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }

            if (route == null)
            {
                throw new ArgumentNullException(nameof(route));
            }

            //if (logger == null)
            //{
            //    throw new ArgumentNullException(nameof(logger));
            //}

            if (constraints == null || constraints.Count == 0)
            {
                return(true);
            }

            foreach (var kvp in constraints)
            {
                var constraint = kvp.Value;
                if (!constraint.Match(httpContext, route, kvp.Key, routeValues, routeDirection))
                {
                    if (routeDirection.Equals(RouteDirection.IncomingRequest))
                    {
                        object routeValue;
                        routeValues.TryGetValue(kvp.Key, out routeValue);

                        ///// logger.RouteValueDoesNotMatchConstraint(routeValue, kvp.Key, kvp.Value);
                    }

                    return(false);
                }
            }

            return(true);
        }