private IAsyncResult BeginInvokeSynchronousActionMethod(ControllerContext context, ActionDescriptor action, IDictionary <string, object> parameters, AsyncCallback callback, object state) { return(AsyncResultWrapper.BeginSynchronous(callback, state, () => InvokeSynchronousActionMethod(context, action, parameters), _invokeMethodTag)); }
protected virtual IAsyncResult BeginProcessRequest( HttpContextBase context, AsyncCallback callback, object state) { AppendVersionHeader(context); string controllerName = Context.RouteData.GetRequiredValue <string>("controller"); IControllerFactory factory = Builder.GetControllerFactory(); IController controller = factory.CreateController(Context, controllerName); if (controller == null) { throw Error.CouldNotCreateController(controllerName); } IAsyncController asyncController = (controller as IAsyncController); if (asyncController == null) // synchronous controller { Action action = delegate { try { controller.Execute(Context); } finally { factory.ReleaseController(controller); } }; return(AsyncResultWrapper.BeginSynchronous(callback, state, action, _tag)); } // asynchronous controller BeginInvokeDelegate beginDelegate = delegate(AsyncCallback asyncCallback, object asyncState) { try { return(asyncController.BeginExecute(Context, asyncCallback, asyncState)); } finally { factory.ReleaseController(asyncController); } }; EndInvokeDelegate endDelegate = delegate(IAsyncResult asyncResult) { try { asyncController.EndExecute(asyncResult); } finally { factory.ReleaseController(asyncController); } }; return(AsyncResultWrapper.Begin(AsyncTask.WrapCallbackForSynchronizedExecution(callback, SynchronizationContextExtensions.GetSynchronizationContext()), state, beginDelegate, endDelegate, _tag)); }
protected virtual IAsyncResult OnBeginExecute(AsyncCallback callback, object state) { LoadTempData(); try { string actionName = RouteData.GetRequiredValue <string>("action"); IActionExecutor executor = ActionExecutor; IAsyncActionExecutor asyncExecutor = (executor as IAsyncActionExecutor); if (asyncExecutor != null) { BeginInvokeDelegate beginDelegate = delegate(AsyncCallback asyncCallback, object asyncState) { return(asyncExecutor.BeginInvokeAction(Context, actionName, asyncCallback, asyncState, new ValueDictionary())); }; EndInvokeDelegate endDelegate = delegate(IAsyncResult asyncResult) { if (!asyncExecutor.EndInvokeAction(asyncResult)) { HandleUnknownAction(actionName); } }; return(AsyncResultWrapper.Begin(callback, state, beginDelegate, endDelegate, _tag)); } else { Action action = () => { if (!executor.InvokeAction(Context, actionName, null)) { HandleUnknownAction(actionName); } }; return(AsyncResultWrapper.BeginSynchronous(callback, state, action, _tag)); } } catch { SaveTempData(); throw; } }
protected virtual IAsyncResult BeginProcessRequest( HttpContextBase context, AsyncCallback callback, object state) { IHttpHandler handler = GetHttpHandler(context); IHttpAsyncHandler asyncHandler = (handler as IHttpAsyncHandler); if (asyncHandler == null) { Action action = delegate { handler.ProcessRequest(context.Unwrap()); }; return(AsyncResultWrapper.BeginSynchronous(callback, state, action, _tag)); } BeginInvokeDelegate beginDelegate = delegate(AsyncCallback asyncCallback, object asyncState) { return(asyncHandler.BeginProcessRequest(context.Unwrap(), asyncCallback, asyncState)); }; EndInvokeDelegate endDelegate = delegate(IAsyncResult asyncResult) { asyncHandler.EndProcessRequest(asyncResult); }; return(AsyncResultWrapper.Begin(callback, state, beginDelegate, endDelegate, _tag)); }