protected override ActionResult InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary <string, object> parameters)
        {
            object returnValue;

            if (!controllerContext.IsChildAction)
            {
                if (!string.IsNullOrWhiteSpace(_goUrl))
                {
                    returnValue = new RedirectResult(_goUrl);
                }
                else if (_error != null)
                {
                    if (_isAjaxReq)
                    {
                        controllerContext.HttpContext.Response.ContentType = "application/json";
                        returnValue = new CustomJsonResult(_error);
                    }
                    else
                    {
                        var v = new ViewResult();
                        v.ViewName         = "Error";
                        v.ViewBag.ErrorMsg = _error.Message;
                        returnValue        = v;
                    }
                }
                else
                {
                    returnValue = actionDescriptor.Execute(controllerContext, parameters);
                }
            }
            else
            {
                returnValue = actionDescriptor.Execute(controllerContext, parameters);
            }

            ActionResult result = CreateActionResult(controllerContext, actionDescriptor, returnValue);

            return(result);
        }
Esempio n. 2
0
        public ActionResult Yes(ConfirmationActionViewModel model)
        {
            if (!model.HttpPost)
            {
                return(Redirect(model.YesUrl));
            }

            ConfirmationData data = ConfirmationService.GetData(model.Id);

            RouteData route = RoutesHelper.GetRouteDataByUrl("/" + model.YesUrl);

            //var controllerDescriptor = new ReflectedControllerDescriptor(GetType());
            string controllerName = (String)route.Values["controller"];
            string actionName     = (String)route.Values["action"];
            //string values = RouteData.GetRequiredString("id");

            //IControllerActivator
            DefaultControllerFactory d = new DefaultControllerFactory();

            IController controller = d.CreateController(HttpContext.Request.RequestContext, controllerName);

            ControllerDescriptor controllerDescriptor = new ReflectedControllerDescriptor(controller.GetType());
            //d.ReleaseController(controller);

            ActionDescriptor actionDescriptor = controllerDescriptor.FindAction(ControllerContext, actionName);

            RequestContext requestContext = new RequestContext(new RoutesHelper.RewritedHttpContextBase("/" + model.YesUrl), route);

            requestContext.HttpContext.Request.Form.Add((NameValueCollection)data.PostData);

            ControllerContext            ctx         = new ControllerContext(requestContext, (ControllerBase)controller);
            IDictionary <string, object> parameters2 = GetParameterValues(ctx, actionDescriptor);
            IDictionary <string, object> parameters  = new Dictionary <string, object>();

            ControllerContext.HttpContext.Response.Clear();
            NameValueCollection nameValueCollection = data.PostData as NameValueCollection;

            //nameValueCollection.
            actionDescriptor.Execute(ControllerContext, (IDictionary <string, object>)data.PostData);

            //var viewResult = new ViewResult
            //{
            //    ViewName = "",
            //    MasterName = "",
            //    ViewData = new ViewDataDictionary(data.PostData),
            //    TempData = null
            //};

            //return viewResult;
            return(new EmptyResult());
        }
Esempio n. 3
0
        public void ExecuteMethodWrapsAsyncExecuteMethods()
        {
            // Arrange
            IAsyncResult                asyncResult       = new MockAsyncResult();
            object                      expectedValue     = new object();
            ControllerContext           controllerContext = new Mock <ControllerContext>().Object;
            Dictionary <string, object> parameters        = new Dictionary <string, object>();

            Mock <AsyncActionDescriptor> mockDescriptor = new Mock <AsyncActionDescriptor>()
            {
                CallBase = true
            };

            mockDescriptor.Expect(d => d.BeginExecute(controllerContext, parameters, null, null)).Returns(asyncResult);
            mockDescriptor.Expect(d => d.EndExecute(asyncResult)).Returns(expectedValue);
            ActionDescriptor descriptor = mockDescriptor.Object;

            // Act
            object returnedValue = descriptor.Execute(controllerContext, parameters);

            // Assert
            Assert.AreEqual(expectedValue, returnedValue);
        }
Esempio n. 4
0
        public static object InvokeAction(this Controller controller, string actionName)
        {
            IModelBinder                modelBinder          = new MyDefaultModelBinder();
            ControllerDescriptor        controllerDescriptor = new ReflectedControllerDescriptor(controller.GetType());
            ActionDescriptor            actionDescriptor     = controllerDescriptor.FindAction(controller.ControllerContext, actionName);
            Dictionary <string, object> arguments            = new Dictionary <string, object>();

            foreach (ParameterDescriptor parameterDescriptor in actionDescriptor.GetParameters())
            {
                string modelName = parameterDescriptor.BindingInfo.Prefix ?? parameterDescriptor.ParameterName;
                ModelBindingContext bindingContext = new ModelBindingContext
                {
                    FallbackToEmptyPrefix = parameterDescriptor.BindingInfo.Prefix == null,
                    ModelMetadata         = ModelMetadataProviders.Current.GetMetadataForType(null, parameterDescriptor.ParameterType),
                    ModelName             = modelName,
                    ModelState            = controller.ModelState,
                    ValueProvider         = controller.ValueProvider
                };
                object argument = modelBinder.BindModel(controller.ControllerContext, bindingContext);
                arguments.Add(parameterDescriptor.ParameterName, argument);
            }
            return(actionDescriptor.Execute(controller.ControllerContext, arguments));
        }
        public virtual ActionResult InvokeActionMethod(ControllerContext context,
            ActionDescriptor action, IDictionary<string, object> parameters)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
            Precondition.Require(action, () => Error.ArgumentNull("action"));
            Precondition.Require(parameters, () => Error.ArgumentNull("parameters"));

            object value = action.Execute(context, parameters);
            return CreateActionResult(context, action, value);
        }
 public override object Execute(ControllerContext controllerContext, IDictionary <string, object> parameters)
 {
     return(_internalDescriptor.Execute(controllerContext, parameters));
 }
Esempio n. 7
0
        protected internal virtual IAsyncResult BeginInvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary <string, object> parameters, AsyncCallback callback, object state)
        {
            BeginExecuteDelegate beginExecute;
            EndExecuteDelegate   endExecute;

            IAsyncActionDescriptor asyncDescriptor = actionDescriptor as IAsyncActionDescriptor;

            if (asyncDescriptor != null)
            {
                beginExecute = asyncDescriptor.BeginExecute;
                endExecute   = asyncDescriptor.EndExecute;
            }
            else
            {
                // execute synchronous descriptor asynchronously
                ExecuteDelegate execute = (cc, p) => SynchronizationContext.Sync(() => actionDescriptor.Execute(cc, p));
                beginExecute = execute.BeginInvoke;
                endExecute   = execute.EndInvoke;
            }

            return(AsyncResultWrapper.Wrap(callback, state,
                                           (innerCb, innerState) => beginExecute(controllerContext, parameters, innerCb, innerState),
                                           ar => {
                object returnValue = endExecute(ar);
                ActionResult result = CreateActionResult(controllerContext, actionDescriptor, returnValue);
                return result;
            }, _invokeActionMethodTag));
        }