コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AsyncActionInvokerWrapper"/> class that wraps the specified asynchronous action invoker.
        /// </summary>
        /// <param name="actionInvoker">The asynchronous action invoker to wrap.</param>
        /// <exception cref="ArgumentNullException"><paramref name="actionInvoker"/> is <c>null</c>.</exception>
        public AsyncActionInvokerWrapper(IAsyncActionInvoker actionInvoker) : base(actionInvoker)
        {
            if (actionInvoker == null)
            {
                throw new ArgumentNullException("actionInvoker");
            }

            this.mActionInvoker = actionInvoker;
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AsyncActionInvokerWrapper"/> class that wraps the specified asynchronous action invoker.
        /// </summary>
        /// <param name="actionInvoker">The asynchronous action invoker to wrap.</param>
        /// <exception cref="ArgumentNullException"><paramref name="actionInvoker"/> is <c>null</c>.</exception>
        public AsyncActionInvokerWrapper(IAsyncActionInvoker actionInvoker) : base(actionInvoker)
        {
            if (actionInvoker == null)
            {
                throw new ArgumentNullException("actionInvoker");
            }

            this.mActionInvoker = actionInvoker;
        }
コード例 #3
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;
            }
        }
コード例 #4
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
                    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;
            }
        }
コード例 #5
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));
        }
コード例 #6
0
 public ActionInvokerWrapper(IActionInvoker actionInvoker)
 {
     this.actionInvoker = actionInvoker;
     asyncInvoker       = actionInvoker as IAsyncActionInvoker;
 }
コード例 #7
0
 public AtlasAsyncActionInvoker(IAsyncActionInvoker actionInvoker)
 {
     this.actionInvoker = actionInvoker;
 }