public bool InvokeAction(ControllerContext controllerContext, string actionName)
        {
            var submittedAction = controllerContext.HttpContext.Request.Form.AllKeys.FirstOrDefault(key => key != null && key.StartsWith(SubmitActionNameConsts.SubmittedActionNamePrefix));

            if (submittedAction != null)
            {
                var submittedActionName = submittedAction.Substring(SubmitActionNameConsts.SubmittedActionNamePrefix.Length).ToLower();
                controllerContext.RouteData.Values["action"] = submittedActionName;
                return(_actionInvoker.InvokeAction(controllerContext, submittedActionName));
            }

            return(_actionInvoker.InvokeAction(controllerContext, actionName));
        }
        private async Task <string> ExecuteModuleControllerAsString(ActionContext actionContext, ModuleContext moduleContext, ModuleAction moduleAction)
        {
            if (actionContext == null)
            {
                return(null);
            }

            ActionContext moduleActionContext = GetModuleActionContext(actionContext, moduleContext, moduleAction);

            //var invoker = _moduleInvokerProvider.CreateInvoker(moduleActionContext);
            //var result = await invoker.InvokeAction() as ViewResult;
            var result = await _actionInvoker.InvokeAction(actionContext.HttpContext, moduleAction, moduleActionContext) as ViewResult;

            string strResult = result.ExecuteResultToString(moduleActionContext);

            return(strResult);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Enables processing of the result of an action method by a custom type that inherits from <see cref="T:System.Web.Mvc.ActionResult"/>.
        /// </summary>
        /// <param name="context"/>
        public override void ExecuteResult(ControllerContext context)
        {
            SetupN2ForNewPageRequest();

            context = BuildPageControllerContext(context);

            _actionInvoker.InvokeAction(context, "Index");
        }
Exemplo n.º 4
0
 public void Execute(RequestContext requestContext)
 {
     ControllerContext.HttpContext    = requestContext.HttpContext;
     ControllerContext.RequestContext = requestContext;
     ControllerContext.RouteData      = requestContext.RouteData;
     _functionInvoker.InvokeAction(ControllerContext, requestContext.RouteData.Values["action"].ToString());
     // string info = string.Format("The Controller by Name {0} has been requested to call an Action called {1}", requestContext.RouteData.Values["controller"], requestContext.RouteData.Values["action"]);
     //requestContext.HttpContext.Response.Write(info);
 }
Exemplo n.º 5
0
        /// <summary>
        /// The job of this method is invoke an action and ultimately populate the
        /// </summary>
        /// <param name="application">The current application</param>
        /// <param name="context">A context which stores the request and response contexts.</param>
        public async Task Execute(MvcApplication application, NavigationContext context)
        {
            Initialize(application, context);
            var action       = RouteData.Action;
            var actionResult = await ActionInvoker.InvokeAction(ControllerContext, action);

            var view = ((ViewResult)actionResult).View;

            view.Initialize(application.CreateViewContext(this));
            context.Response.View = view;
        }
Exemplo n.º 6
0
        protected virtual IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
        {
            // If code in this method needs to be updated, please also check the ExecuteCore() method
            // of Controller to see if that code also must be updated.
            PossiblyLoadTempData();
            try
            {
                string              actionName   = RouteData.GetRequiredString("action");
                IActionInvoker      invoker      = ActionInvoker;
                IAsyncActionInvoker asyncInvoker = invoker as IAsyncActionInvoker;
                if (asyncInvoker != null)
                {
                    // asynchronous invocation
                    // Ensure delegates continue to use the C# Compiler static delegate caching optimization.
                    BeginInvokeDelegate <ExecuteCoreState> beginDelegate = delegate(AsyncCallback asyncCallback, object asyncState, ExecuteCoreState innerState)
                    {
                        return(innerState.AsyncInvoker.BeginInvokeAction(innerState.Controller.ControllerContext, innerState.ActionName, asyncCallback, asyncState));
                    };

                    EndInvokeVoidDelegate <ExecuteCoreState> endDelegate = delegate(IAsyncResult asyncResult, ExecuteCoreState innerState)
                    {
                        if (!innerState.AsyncInvoker.EndInvokeAction(asyncResult))
                        {
                            innerState.Controller.HandleUnknownAction(innerState.ActionName);
                        }
                    };
                    ExecuteCoreState executeState = new ExecuteCoreState()
                    {
                        Controller = this, AsyncInvoker = asyncInvoker, ActionName = actionName
                    };

                    return(AsyncResultWrapper.Begin(callback, state, beginDelegate, endDelegate, executeState, _executeCoreTag));
                }
                else
                {
                    // synchronous invocation
                    Action action = () =>
                    {
                        if (!invoker.InvokeAction(ControllerContext, actionName))
                        {
                            HandleUnknownAction(actionName);
                        }
                    };
                    return(AsyncResultWrapper.BeginSynchronous(callback, state, action, _executeCoreTag));
                }
            }
            catch
            {
                PossiblySaveTempData();
                throw;
            }
        }
Exemplo n.º 7
0
 bool InvokeActionWith404Catch(ControllerContext controllerContext, string actionName)
 {
     try {
         return(actionInvoker.InvokeAction(controllerContext, actionName));
     } catch (HttpException ex) {
         if (ex.GetHttpCode() == 404)
         {
             var skipNotFoundAttributes = controllerContext.Controller.GetType().GetCustomAttributes(typeof(NoMvcNotFoundAttribute), false);
             return(skipNotFoundAttributes.Any());
         }
         throw;
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// The job of this method is invoke an action and ultimately populate the
        /// </summary>
        /// <param name="application">The current application</param>
        /// <param name="context">A context which stores the request and response contexts.</param>
        /// <param name="continuation">This method is asynchronous -- to take some action after the execution
        /// completes, you must pass the continuation argument.</param>
        public Task Execute(MvcApplication application, NavigationContext context)
        {
            Initialize(application, context);
            var action = RouteData.Action;
            var task   = ActionInvoker.InvokeAction(ControllerContext, action);

            return(task.ContinueWith(x =>
            {
                var actionResult = x.Result;
                var view = ((ViewResult)actionResult).View;
                view.Initialize(application.CreateViewContext(this));
                context.Response.View = view;
            }));
        }
Exemplo n.º 9
0
    public bool InvokeAction(ControllerContext controllerContext, string actionName)
    {
        if (actionInvoker.InvokeAction(controllerContext, actionName))
        {
            return(true);
        }

        // No action method was found.
        var controller = new NotFoundController();

        controller.ExecuteNotFound(controllerContext.RequestContext);

        return(true);
    }
Exemplo n.º 10
0
        public override bool InvokeAction(ControllerContext controllerContext, string actionName)
        {
            var httpContext             = controllerContext.HttpContext;
            var controllerActionInvoker = _invoker as ControllerActionInvoker;

            if (controllerActionInvoker != null)
            {
                var detailer = new ControllerDetailer();
                httpContext.Response.Write(detailer.GetControllerDetails(GetControllerDescriptor(controllerContext), controllerContext.RequestContext));
                return(true);
            }

            return(_invoker.InvokeAction(controllerContext, actionName));
        }
Exemplo n.º 11
0
 private bool InvokeActionWithNotFoundCatch(ControllerContext controllerContext, string actionName)
 {
     try
     {
         return(mActionInvoker.InvokeAction(controllerContext, actionName));
     }
     catch (HttpException exception)
     {
         if (exception.GetHttpCode() == 404)
         {
             return(false);
         }
         throw;
     }
 }
Exemplo n.º 12
0
 bool InvokeActionWith404Catch(ControllerContext controllerContext, string actionName)
 {
     try
     {
         return(actionInvoker.InvokeAction(controllerContext, actionName));
     }
     catch (HttpException ex)
     {
         if (ex.GetHttpCode() == 404)
         {
             return(false);
         }
         throw;
     }
 }
 /// <summary>
 /// Enables processing of the result of an action method by a custom type that inherits from <see cref="T:System.Web.Mvc.ActionResult"/>.
 /// </summary>
 /// <param name="context"/>
 public override void ExecuteResult(ControllerContext context)
 {
     try
     {
         context = BuildPageControllerContext(context);
         actionInvoker.InvokeAction(context, "Index");
     }
     finally
     {
         if (context.Controller != null)
         {
             controllerFactory.ReleaseController(context.Controller);
         }
     }
 }
        protected virtual IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
        {
            // If code in this method needs to be updated, please also check the ExecuteCore() method
            // of Controller to see if that code also must be updated.

            PossiblyLoadTempData();
            try
            {
                string              actionName   = RouteData.GetRequiredString("action");
                IActionInvoker      invoker      = ActionInvoker;
                IAsyncActionInvoker asyncInvoker = invoker as IAsyncActionInvoker;
                if (asyncInvoker != null)
                {
                    // asynchronous invocation
                    BeginInvokeDelegate beginDelegate = delegate(AsyncCallback asyncCallback, object asyncState)
                    {
                        return(asyncInvoker.BeginInvokeAction(ControllerContext, actionName, asyncCallback, asyncState));
                    };

                    EndInvokeDelegate endDelegate = delegate(IAsyncResult asyncResult)
                    {
                        if (!asyncInvoker.EndInvokeAction(asyncResult))
                        {
                            HandleUnknownAction(actionName);
                        }
                    };

                    return(AsyncResultWrapper.Begin(callback, state, beginDelegate, endDelegate, _executeCoreTag));
                }
                else
                {
                    // synchronous invocation
                    Action action = () =>
                    {
                        if (!invoker.InvokeAction(ControllerContext, actionName))
                        {
                            HandleUnknownAction(actionName);
                        }
                    };
                    return(AsyncResultWrapper.BeginSynchronous(callback, state, action, _executeCoreTag));
                }
            }
            catch
            {
                PossiblySaveTempData();
                throw;
            }
        }
Exemplo n.º 15
0
 public bool InvokeAction(ControllerContext controllerContext, string actionName)
 {
     using (databaseContext){
         return(actionInvoker.InvokeAction(controllerContext, actionName));
     }
 }
Exemplo n.º 16
0
        protected internal virtual IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
        {
            TempData.Load(ControllerContext, TempDataProvider);

            string              actionName   = RouteData.GetRequiredString("action");
            IActionInvoker      invoker      = ActionInvoker;
            IAsyncActionInvoker asyncInvoker = invoker as IAsyncActionInvoker;

            BeginInvokeActionDelegate beginDelegate;
            EndInvokeActionDelegate   endDelegate;

            if (asyncInvoker != null)
            {
                beginDelegate = asyncInvoker.BeginInvokeAction;
                endDelegate   = asyncInvoker.EndInvokeAction;
            }
            else
            {
                // execute synchronous method asynchronously
                InvokeActionDelegate invokeDelegate = (cc, an) => AsyncManager.SynchronizationContext.Sync(() => invoker.InvokeAction(cc, an));
                beginDelegate = invokeDelegate.BeginInvoke;
                endDelegate   = invokeDelegate.EndInvoke;
            }

            return(AsyncResultWrapper.Wrap(callback, state,
                                           (innerCallback, innerState) => {
                try {
                    return beginDelegate(ControllerContext, actionName, innerCallback, innerState);
                }
                catch {
                    TempData.Save(ControllerContext, TempDataProvider);
                    throw;
                }
            },
                                           ar => {
                try {
                    bool wasActionExecuted = endDelegate(ar);
                    if (!wasActionExecuted)
                    {
                        HandleUnknownAction(actionName);
                    }
                }
                finally {
                    TempData.Save(ControllerContext, TempDataProvider);
                }
            },
                                           _executeCoreTag));
        }