private static string EvalComponentExpression(ExpressionParser parser, TemplateToken token, TemplateParserContext context) { TemplateToken.ParameterizedExpression pExpr = token.ExtractParameters(); string componentName = pExpr.MainExpression; if (pExpr.MainExpression.StartsWith("(") && pExpr.MainExpression.EndsWith(")")) { componentName = parser.Evaluate <string>(pExpr.MainExpression, context, token.TokenPosition); } TemplateParserContext newContext = (TemplateParserContext)context.CreateLocal(); foreach (string varName in pExpr.Parameters.Keys) { newContext.SetLocal(varName, parser.Evaluate(pExpr.Parameters[varName], context)); } ControllerAction viewComponent = WebAppHelper.GetViewComponent(componentName); if (viewComponent == null) { throw new TemplateRenderingException("View component " + componentName + " not found", token.TokenPosition); } try { return(WebAppHelper.RunViewComponent(viewComponent, newContext)); } catch (Exception e) { throw new TemplateRenderingException("Error rendering view component " + componentName, e, token.TokenPosition); } }
internal static string RunViewComponent(ControllerAction controllerAction, TemplateParserContext context) { ControllerClass controllerClass = controllerAction.ControllerClass; if (!controllerClass.IsActionMethod(controllerAction.ActionMethod)) { return(null); } using (ViewComponent component = controllerClass.CreateViewComponent(context)) { try { controllerClass.SetupController(component, context); object returnValue = controllerClass.Run(component, "Run", context); if (returnValue is string) { return((string)returnValue); } return(TemplateUtil.ExtractBody(component.View.Render())); } catch { component.SkipTearDown = true; throw; } } }
internal static ControllerAction GetControllerAction(string url) { RouteResult routeResult = WebAppConfig.Router.Resolve(url); if (routeResult == null) { return(null); } ControllerClass controllerClass = WebAppConfig.GetControllerClass(routeResult.Controller); if (controllerClass != null) { ControllerAction controllerAction = new ControllerAction(controllerClass, routeResult.Action); foreach (KeyValuePair <string, string> param in routeResult.Parameters) { controllerAction.Parameters.Add(param.Key, param.Value); } return(controllerAction); } return(null); }
internal static string RunViewComponent(ControllerAction controllerAction, TemplateParserContext context) { ControllerClass controllerClass = controllerAction.ControllerClass; if (!controllerClass.IsActionMethod(controllerAction.ActionMethod)) return null; using (ViewComponent component = controllerClass.CreateViewComponent(context)) { try { controllerClass.SetupController(component, context); object returnValue = controllerClass.Run(component, "Run", context); if (returnValue is string) return (string) returnValue; return TemplateUtil.ExtractBody(component.View.Render()); } catch { component.SkipTearDown = true; throw; } } }
private string RunPage(string url, bool post) { for (; ;) { _redirectedPage = null; _currentPage = url; try { HttpContextBase.CreateContext(this, post ? "POST" : "GET", url, post ? _postData : null); if (ContextCreated != null) { ContextCreated(this, new ContextCreatedEventArgs(this, WebAppContext.HttpContext)); } IHttpRequest httpRequest = WebAppContext.Request; string path = UrlHelper.GetUrlPath(httpRequest.AppRelativeCurrentExecutionFilePath, httpRequest.PathInfo); ControllerAction controllerAction = WebAppHelper.GetControllerAction(path); MvcPageHandler pageHandler = new MvcPageHandler(controllerAction); pageHandler.ProcessRequest(WebAppContext.HttpContext); _isNewSession = false; _view = WebAppContext.HttpContext.Response.RenderedView; } catch (TargetInvocationException ex) { Exception ex2 = ExceptionHelper.ResolveTargetInvocationException(ex); if (!(ex2 is EndResponseException)) { throw ex2; } } catch (EndResponseException) { } _redirectedPage = ((OfflineHttpResponse)WebAppContext.HttpContext.Response).RedirectedUrl; PostData.Clear(); if (!_followRedirects || _redirectedPage == null) { return(WebAppContext.Response.Output); } post = false; url = _redirectedPage; } }
internal static ActionResult RunControllerAction(ControllerAction controllerAction) { WebAppContext.AddControllerParameters(controllerAction.Parameters); ControllerClass controllerClass = controllerAction.ControllerClass; if (!controllerClass.AllowCaching) { WebAppContext.Response.DisableCaching(); } if (!controllerClass.IsActionMethod(controllerAction.ActionMethod)) { return(null); } using (Controller controller = controllerClass.CreateController()) // Dispose() will call [AfterAction] methods { try { WebAppContext.RootView = controller.View; controllerClass.SetupController(controller, null); object returnValue = controllerClass.Run(controller, controllerAction.ActionMethod, null); if (returnValue is ActionResult) { ActionResult actionResult = (ActionResult)returnValue; if (actionResult.Final) { controller.SkipTearDown = true; } return(actionResult); } return(new RenderViewActionResult(controller.View)); } catch { controller.SkipTearDown = true; throw; } } }
internal static ActionResult RunControllerAction(ControllerAction controllerAction) { WebAppContext.AddControllerParameters(controllerAction.Parameters); ControllerClass controllerClass = controllerAction.ControllerClass; if (!controllerClass.AllowCaching) WebAppContext.Response.DisableCaching(); if (!controllerClass.IsActionMethod(controllerAction.ActionMethod)) return null; using (Controller controller = controllerClass.CreateController()) // Dispose() will call [AfterAction] methods { try { WebAppContext.RootView = controller.View; controllerClass.SetupController(controller, null); object returnValue = controllerClass.Run(controller, controllerAction.ActionMethod, null); if (returnValue is ActionResult) { ActionResult actionResult = (ActionResult) returnValue; if (actionResult.Final) controller.SkipTearDown = true; return actionResult; } return new RenderViewActionResult(controller.View); } catch { controller.SkipTearDown = true; throw; } } }
private static void PostResolveRequestCache(object sender, EventArgs e) { WebAppConfig.Init(); HttpContext httpContext = ((HttpApplication)sender).Context; HttpRequest httpRequest = httpContext.Request; IHttpHandler httpHandler = null; string path = UrlHelper.GetUrlPath(httpRequest.AppRelativeCurrentExecutionFilePath, httpRequest.PathInfo); if (path.StartsWith("_$ajax$_.axd/")) { httpHandler = new AjaxPageHandler(path); } else if (path.StartsWith("_$res$_.axd")) { httpHandler = new ResourceHttpHandler(path); } else { ControllerAction controllerAction = WebAppHelper.GetControllerAction(path); if (controllerAction != null) { httpHandler = new PageHandler(new MvcPageHandler(controllerAction)); } } if (httpHandler != null) { httpContext.Items[_contextItemKey] = new RequestData(httpContext.Request.RawUrl, httpHandler); httpContext.RewritePath("~/ProMesh.axd"); } }
internal MvcPageHandler(ControllerAction controllerAction) { _controllerAction = controllerAction; }
internal static ControllerAction GetControllerAction(string url) { RouteResult routeResult = WebAppConfig.Router.Resolve(url); if (routeResult == null) return null; ControllerClass controllerClass = WebAppConfig.GetControllerClass(routeResult.Controller); if (controllerClass != null) { ControllerAction controllerAction = new ControllerAction(controllerClass, routeResult.Action); foreach (KeyValuePair<string, string> param in routeResult.Parameters) controllerAction.Parameters.Add(param.Key, param.Value); return controllerAction; } return null; }