protected override void ExecuteCore()
        {
            var queryString = HttpContext.Request.QueryString;

            if (queryString.Keys.Count > 0 && String.Equals(queryString.GetValues(0).First(), "json", StringComparison.OrdinalIgnoreCase))
            {
                ActionInvoker.InvokeAction(ControllerContext, "Internal::Proxy");
                return;
            }

            // This is where the proxy places the action.
            string action = HttpContext.Request.Headers["x-mvc-action"] ?? HttpContext.Request.QueryString["action"];

            if (!RouteData.Values.ContainsKey("action") && !String.IsNullOrEmpty(action))
            {
                RouteData.Values.Add("action", action);
            }

            if (RouteData.Values.ContainsKey("action"))
            {
                base.ExecuteCore();
                return;
            }

            ActionInvoker.InvokeAction(ControllerContext, "Internal::ProxyDefinition");
        }
Esempio n. 2
0
 public virtual void Execute(HttpRequestContext requestContext)
 {
     if (ActionInvoker != null)
     {
         ActionInvoker.InvokeAction(new ControllerContext(requestContext, this), requestContext.Action);
     }
 }
Esempio n. 3
0
        protected override IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
        {
            var queryString = HttpContext.Request.QueryString;

            if (queryString.Keys.Count > 0 && String.Equals(queryString.GetValues(0).First(), "json", StringComparison.OrdinalIgnoreCase))
            {
                ActionInvoker.InvokeAction(ControllerContext, "Internal::Proxy");
                return(new CompletedAsyncResult()
                {
                    AsyncState = state
                });
            }

            // This is where the proxy places the action.
            string action = HttpContext.Request.Headers["x-mvc-action"] ?? HttpContext.Request.QueryString["action"];

            if (!RouteData.Values.ContainsKey("action") && !String.IsNullOrEmpty(action))
            {
                RouteData.Values.Add("action", action);
            }

            if (RouteData.Values.ContainsKey("action"))
            {
                return(base.BeginExecuteCore(callback, state));
            }
            else
            {
                ActionInvoker.InvokeAction(ControllerContext, "Internal::ProxyDefinition");
                return(new CompletedAsyncResult()
                {
                    AsyncState = state
                });
            }
        }
Esempio n. 4
0
        protected override void ExecuteCore()
        {
            ControllerContext.RouteData.Values["action"]     = GetControllerName();
            ControllerContext.RouteData.Values["controller"] = GetNamespace();
            bool succeeded = ActionInvoker.InvokeAction(ControllerContext, CANONICAL_ACTION_NAME);

            if (!succeeded)
            {
                HandleUnknownAction(CANONICAL_ACTION_NAME);
            }
        }
Esempio n. 5
0
 protected override void ExecuteCore()
 {
     if (ControllerContext.RouteData.Route is DiscoverableRoute)
     {
         ActionInvoker.InvokeAction(ControllerContext, "DiscoverControllerActions");
     }
     else
     {
         base.ExecuteCore();
     }
 }
Esempio n. 6
0
        protected override void ExecuteCore() {
            TempData.Load(ControllerContext, TempDataProvider);

            try {
                string actionName = RouteData.GetRequiredString("action");
                if (!ActionInvoker.InvokeAction(ControllerContext, actionName)) {
                    HandleUnknownAction(actionName);
                }
            }
            finally {
                TempData.Save(ControllerContext, TempDataProvider);
            }
        }
Esempio n. 7
0
        protected override IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
        {
            if (RouteData.Values.ContainsKey("action"))
            {
                return(base.BeginExecuteCore(callback, state));
            }

            ActionInvoker.InvokeAction(ControllerContext, AjaxActionInvoker.AjaxProxyAction);
            return(new CompletedAsyncResult()
            {
                AsyncState = state
            });
        }
Esempio n. 8
0
        private HttpResponse Process(HttpRequest request)
        {
            if (request.Method.ToLower() == "options")
            {
                var routes =
                    Assembly.GetEntryAssembly()
                    .GetTypes()
                    .Where(x => x.Name.EndsWith("Controller") && typeof(Controller).IsAssignableFrom(x))
                    .Select(
                        x => new { x.Name, Methods = x.GetMethods().Where(m => m.ReturnType == typeof(IActionResult)) })
                    .SelectMany(
                        x =>
                        x.Methods.Select(
                            m =>
                            string.Format("/{0}/{1}/{{parameter}}", x.Name.Replace("Controller", string.Empty), m.Name)))
                    .ToList();

                return(new HttpResponse(request.ProtocolVersion, HttpStatusCode.OK, string.Join(Environment.NewLine, routes)));
            }
            else if (new StaticFileHandler().CanHandle(request))
            {
                return(new StaticFileHandler().Handle(request));
            }
            else if (request.ProtocolVersion.Major <= 3)
            {
                HttpResponse response;
                try
                {
                    var controller    = CreateController(request);
                    var actionInvoker = new ActionInvoker();
                    var actionResult  = actionInvoker.InvokeAction(controller, request.Action);
                    response = actionResult.GetResponse();
                }
                catch (HttpNotFound exception)
                {
                    response = new HttpResponse(request.ProtocolVersion, HttpStatusCode.NotFound, exception.Message);
                }
                catch (Exception exception)
                {
                    response = new HttpResponse(request.ProtocolVersion, HttpStatusCode.InternalServerError, exception.Message);
                }
                return(response);
            }
            else
            {
                return(new HttpResponse(request.ProtocolVersion, HttpStatusCode.NotImplemented, "Request cannot be handled."));
            }
        }
Esempio n. 9
0
 //看到这可以大致猜出来。最重要的三个对象 可能就是 controllerContext  routeData actionInvoker
 //那我们来各个击破
 //在进入了确定的controller之后,就是通过actionInvoker来执行方法了
 protected override void ExecuteCore()
 {
     // If code in this method needs to be updated, please also check the BeginExecuteCore() and
     // EndExecuteCore() methods of AsyncController to see if that code also must be updated.
     PossiblyLoadTempData();
     try {
         string actionName = RouteData.GetRequiredString("action");
         if (!ActionInvoker.InvokeAction(ControllerContext, actionName))
         {
             HandleUnknownAction(actionName);
         }
     }
     finally {
         PossiblySaveTempData();
     }
 }
Esempio n. 10
0
        protected override void ExecuteCore()
        {
            if (NavigationSection == null)
            {
                object routeNavigationSection = ControllerContext.RouteData.Values["navigationSection"];
                NavigationSection = routeNavigationSection == null ? null : routeNavigationSection.ToString();
            }

            CurrentAction     = ControllerContext.RouteData.Values["action"].ToString();
            CurrentController = ControllerContext.RouteData.Values["controller"].ToString();

            ControllerContext.RouteData.Values["action"]     = GetControllerName();
            ControllerContext.RouteData.Values["controller"] = GetNamespace();
            bool succeeded = ActionInvoker.InvokeAction(ControllerContext, CANONICAL_ACTION_NAME);

            if (!succeeded)
            {
                HandleUnknownAction(CANONICAL_ACTION_NAME);
            }
        }
Esempio n. 11
0
        //
        // GET: /Base/
        protected override void OnException(ExceptionContext filterContext)
        {
            var excepton = filterContext.Exception;

            if (this.GetType().GetMethod(RouteData.Route.GetRouteData(this.HttpContext).Values["action"].ToString()).ReturnType == typeof(JsonResult))
            {
                ModelState.AddModelError("DomainError", excepton.Message);
                filterContext.ExceptionHandled = true;
                ActionInvoker.InvokeAction(filterContext.Controller.ControllerContext, "DomainError");
            }

            if (this.GetType().GetMethod(RouteData.Route.GetRouteData(this.HttpContext).Values["action"].ToString()).ReturnType != typeof(JsonResult))
            {
                // 标记异常已处理
                filterContext.ExceptionHandled = true;
                // 跳转到错误页
                filterContext.Result = new RedirectResult(Url.Action("Error", "Shared"));
                filterContext.HttpContext.Response.Redirect("/Shared/Error");
            }
        }
        protected override void ExecuteCore()
        {
            if (!ControllerContext.IsChildAction)
            {
                base.TempData.Load(ControllerContext, TempDataProvider);
            }

            try
            {
                if (!ActionInvoker.InvokeAction(ControllerContext, "execute"))
                {
                    HandleUnknownAction("execute");
                }
            }
            finally
            {
                if (!ControllerContext.IsChildAction)
                {
                    base.TempData.Save(ControllerContext, TempDataProvider);
                }
            }
        }
Esempio n. 13
0
 protected override void ExecuteCore()
 {
     if (!ControllerContext.IsChildAction)
     {
         TempData.Load(ControllerContext, TempDataProvider);
     }
     try
     {
         string httpMethod = ControllerContext.IsChildAction ? "Get" : ControllerContext.HttpContext.Request.HttpMethod;
         if (!ActionInvoker.InvokeAction(ControllerContext, httpMethod) && !ActionInvoker.InvokeAction(ControllerContext, "Execute"))
         {
             HandleUnknownAction(httpMethod);
         }
     }
     finally
     {
         if (!ControllerContext.IsChildAction)
         {
             TempData.Save(ControllerContext, TempDataProvider);
         }
     }
 }
Esempio n. 14
0
 public bool DoInvokeAction(string action)
 {
     return(ActionInvoker.InvokeAction(ControllerContext, action));
 }
 protected override void HandleUnknownAction(string actionName)
 {
     iscatch = true;
     ActionInvoker.InvokeAction(ControllerContext, "_catch");
 }
Esempio n. 16
0
 protected virtual void Execute()
 {
     ActionInvoker.InvokeAction(this.ActionContext, this.Action);
 }
        private HttpResponse Process(HttpRequest request)
        {
            if (request.Method.ToLower() == "head")
            {
                return new HttpResponse(request.ProtocolVersion, HttpStatusCode.OK, string.Empty);
            }

            if (request.Method.ToLower() == "options")
            {
                var routes =
                    Assembly.GetEntryAssembly()
                            .GetTypes()
                            .Where(x => x.Name.EndsWith("Controller") && typeof(Controller).IsAssignableFrom(x))
                            .Select(
                                x =>
                                    new
                                    {
                                        x.Name,
                                        Methods = x.GetMethods().Where(m => m.ReturnType == typeof(IActionResult))
                                    })
                            .SelectMany(
                                x => x.Methods.Select(
                                    m => string.Format(
                                        "/{0}/{1}/{{parameter}}",
                                        x.Name.Replace("Controller", string.Empty),
                                        m.Name)))
                            .ToList();

                return new HttpResponse(request.ProtocolVersion, HttpStatusCode.OK, string.Join(Environment.NewLine, routes));
            }

            if (new StaticFileHandler().CanHandle(request))
            {
                return new StaticFileHandler().Handle(request);
            }

            if (request.ProtocolVersion.Major <= 3)
            {
                HttpResponse response;
                try
                {
                    var controller = this.CreateController(request);
                    var actionInvoker = new ActionInvoker();
                    var actionResult = actionInvoker.InvokeAction(controller, request.Action);
                    response = actionResult.GetResponse();
                }
                catch (HttpNotFoundException exception)
                {
                    response = new HttpResponse(request.ProtocolVersion, HttpStatusCode.NotFound, exception.Message);
                }
                catch (Exception exception)
                {
                    response = new HttpResponse(request.ProtocolVersion, HttpStatusCode.InternalServerError, exception.Message);
                }

                return response;
            }

            return new HttpResponse(request.ProtocolVersion, HttpStatusCode.NotImplemented, "Request cannot be handled.");
        }
Esempio n. 18
0
        public override void Execute()
        {
            String actionName = ControllerContext.RouteData.GetRequiredString("Action");

            ActionInvoker.InvokeAction(ControllerContext, actionName);
        }
Esempio n. 19
0
 /// <inheritDoc/>
 protected override void HandleUnknownAction(string actionName)
 {
     ActionInvoker.InvokeAction(ControllerContext, "Index");
 }
Esempio n. 20
0
 protected override void ExecuteCore(string action)
 {
     ActionInvoker.InvokeAction(Type, action);
 }