Exemplo n.º 1
0
        private ControllerRouteMapper <C> AddRouteHandler <FunctionType>(AbstractRequestPattern pattern, Expression <FunctionType> handler, Func <C, ControllerContext, ActionResult> handlerFunction)
        {
            var method     = GetMethodInfo(handler);
            var actionName = method.Name;

            this.routes.AddRoute(
                pattern,
                new ControllerRouteHandler <C>(pattern, this.controllerName, actionName, handlerFunction));

            return(this);            // To allow for method chaining.
        }
Exemplo n.º 2
0
        /*
         * public static Route MapRoute(this RouteCollection routes, RequestPattern<UrlPattern> pattern, Func<HttpContextBase, ActionResult> handler)
         * {
         *      return routes.AddRoute(pattern, FuncRouteHandler.Create(pattern, handler));
         * }
         *
         * public static Route MapRoute<P1>(this RouteCollection routes, RequestPattern<UrlPattern<P1>> pattern, Func<HttpContextBase, P1, ActionResult> handler)
         * {
         *      return routes.AddRoute(pattern, FuncRouteHandler.Create(pattern, handler));
         * }
         *
         * public static Route MapRoute<P1, P2>(this RouteCollection routes, RequestPattern<UrlPattern<P1, P2>> pattern, Func<HttpContextBase, P1, P2, ActionResult> handler)
         * {
         *      return routes.AddRoute(pattern, FuncRouteHandler.Create(pattern, handler));
         * }
         *
         * public static Route MapRoute<P1, P2, P3>(this RouteCollection routes, RequestPattern<UrlPattern<P1, P2, P3>> pattern, Func<HttpContextBase, P1, P2, P3, ActionResult> handler)
         * {
         *      return routes.AddRoute(pattern, FuncRouteHandler.Create(pattern, handler));
         * }
         */

        internal static Route AddRoute(this RouteCollection routes, AbstractRequestPattern pattern, AbstractRouteHandler handler)
        {
            var route = new Route(
                url: GetRouteUrl(pattern.Url),
                defaults: GetDefaults(pattern),
                constraints: GetConstraints(pattern),
                routeHandler: handler);
            var routeName = GetRouteName(pattern);

            routes.Add(routeName, route);
            return(route);
        }
Exemplo n.º 3
0
        private static RouteValueDictionary GetConstraints(AbstractRequestPattern requestPattern)
        {
            var url    = requestPattern.Url;
            var result = new RouteValueDictionary();

            for (int i = 0; i < url.PathArity; i++)
            {
                result[url.ParameterName(i)] = url.ParameterRegexes[i];
            }

            var methodConstraints = GetMethodConstraintsOrNull(requestPattern.Method);

            if (methodConstraints != null)
            {
                result["httpMethod"] = methodConstraints;
            }

            return(result);
        }
        private void AddRouteHandler(AbstractRequestPattern pattern, MethodInfo method, Func <C, RequestContext, ActionResult> handler)
        {
            var actionName = GetActionName(pattern.Method, method);

            this.routes.AddRoute(pattern, new ControllerRouteHandler <C>(pattern, this.controllerName, actionName, handler));
        }
Exemplo n.º 5
0
 private static string GetRouteName(AbstractRequestPattern pattern)
 {
     return(pattern.Method + pattern.Url.Description);
 }
Exemplo n.º 6
0
 private static RouteValueDictionary GetDefaults(AbstractRequestPattern requestPattern)
 {
     return(new RouteValueDictionary());
 }