Exemplo n.º 1
0
        public IAsyncResult BeginInvokeAction(ControllerContext controllerContext, string actionName, AsyncCallback callback, object state)
        {
            if (asyncInvoker != null)
            {
                return(asyncInvoker.BeginInvokeAction(controllerContext, actionName, callback, controllerContext));
            }

            // Just try to invoke the action using the regular action invoker, let the framework throw the right exception for
            // invoking an async function with a non-async invoker.
            InvokeActionWith404Catch(controllerContext, actionName);
            return(null);
        }
        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.º 3
0
        /// <summary>
        /// Invokes the specified action.
        /// </summary>
        /// <param name="controllerContext">The controller context.</param>
        /// <param name="actionName">The name of the asynchronous action.</param>
        /// <param name="callback">The callback method.</param>
        /// <param name="state">The state.</param>
        /// <returns>The status of the asynchronous result.</returns>
        public IAsyncResult BeginInvokeAction(ControllerContext controllerContext, string actionName, AsyncCallback callback, object state)
        {
            var innerAsyncResult = mActionInvoker.BeginInvokeAction(controllerContext, actionName, callback, state);

            return(new AsyncResultWrapper(innerAsyncResult, controllerContext));
        }