protected internal virtual IAsyncResult BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, object state) { return(SecurityUtil.ProcessInApplicationTrust(() => { IController controller; IControllerFactory factory; ProcessRequestInit(httpContext, out controller, out factory); IAsyncController asyncController = controller as IAsyncController; if (asyncController != null) { // asynchronous controller BeginInvokeDelegate beginDelegate = delegate(AsyncCallback asyncCallback, object asyncState) { try { return asyncController.BeginExecute(RequestContext, asyncCallback, asyncState); } catch { factory.ReleaseController(asyncController); throw; } }; EndInvokeDelegate endDelegate = delegate(IAsyncResult asyncResult) { try { asyncController.EndExecute(asyncResult); } finally { factory.ReleaseController(asyncController); } }; SynchronizationContext syncContext = SynchronizationContextUtil.GetSynchronizationContext(); AsyncCallback newCallback = AsyncUtil.WrapCallbackForSynchronizedExecution(callback, syncContext); return AsyncResultWrapper.Begin(newCallback, state, beginDelegate, endDelegate, _processRequestTag); } else { // synchronous controller Action action = delegate { try { controller.Execute(RequestContext); } finally { factory.ReleaseController(controller); } }; return AsyncResultWrapper.BeginSynchronous(callback, state, action, _processRequestTag); } })); }
public void HandleError(RequestContext context, int code, HttpException exception) { if (ShouldLogException(code)) { HandleExceptionWithElmah(exception); } Entities.Documents.Web.Webpage webpage = _getErrorPage.GetPage(code); if (webpage != null) { HttpContextBase httpContext = context.HttpContext; httpContext.ClearError(); httpContext.Response.Clear(); httpContext.Response.StatusCode = code; httpContext.Response.TrySkipIisCustomErrors = true; CurrentRequestData.CurrentPage = webpage; System.Web.Mvc.Controller controller = _controllerManager.GetController(context, webpage, httpContext.Request.HttpMethod); IAsyncController asyncController = (controller as IAsyncController); asyncController.BeginExecute(new RequestContext(httpContext, controller.RouteData), asyncController.EndExecute, null); } else { throw exception; } }
public void ExecuteCallsInitialize() { // Arrange RequestContext requestContext = new RequestContext(new Mock <HttpContextBase>().Object, new RouteData()); MockAsyncResult asyncResult = new MockAsyncResult(); Mock <AsyncController> mockController = new Mock <AsyncController>() { CallBase = true }; mockController.Expect(c => c.BeginExecuteCore(It.IsAny <AsyncCallback>(), It.IsAny <object>())).Returns(asyncResult).Verifiable(); mockController.Expect(c => c.EndExecuteCore(asyncResult)).Verifiable(); AsyncController controller = mockController.Object; IAsyncController iController = controller; // Act IAsyncResult returnedAsyncResult = iController.BeginExecute(requestContext, null, null); iController.EndExecute(returnedAsyncResult); // Assert Assert.AreEqual(requestContext, controller.ControllerContext.RequestContext); mockController.Verify(); }
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)); }
public bool Handle(RequestContext context) { ArticleList articleList = GetArticleList(context.HttpContext.Request.Url.AbsolutePath); if (articleList != null) { IControllerFactory controllerFactory = _controllerManager.ControllerFactory; Controller controller = controllerFactory.CreateController(context, "ArticleRSS") as Controller; controller.ControllerContext = new ControllerContext(context, controller); RouteValueDictionary routeValueDictionary = new RouteValueDictionary(); routeValueDictionary["controller"] = "ArticleRSS"; routeValueDictionary["action"] = "Show"; routeValueDictionary["page"] = articleList; controller.RouteData.Values.Merge(routeValueDictionary); controller.RouteData.DataTokens["app"] = MrCMSApp.AppWebpages[articleList.GetType()]; IAsyncController asyncController = (controller as IAsyncController); asyncController.BeginExecute(context, asyncController.EndExecute, null); return(true); } return(false); }
public void Handle(RequestContext context, Webpage webpage, Action <MrCMSUIController> beforeExecute) { System.Web.Mvc.Controller controller = _controllerManager.GetController(context, webpage, context.HttpContext.Request.HttpMethod); _controllerManager.SetFormData(webpage, controller, context.HttpContext.Request.Form); if (beforeExecute != null) { MrCMSUIController uiController = controller as MrCMSUIController; if (uiController != null) { beforeExecute(uiController); } } if (_seoSettings.EnableHtmlMinification) { context.HttpContext.Response.Filter = new WhitespaceFilter(context.HttpContext.Response.Filter); } IAsyncController asyncController = (controller as IAsyncController); asyncController.BeginExecute(context, asyncController.EndExecute, null); }