Esempio n. 1
0
        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);

                    string returnValue = controllerClass.Run(component, "Run", context) as string;

                    if (returnValue != null)
                        return returnValue;

                    return TemplateUtil.ExtractBody(component.View.Render());
                }
                catch
                {
                    component.SkipTearDown = true;

                    throw;
                }
            }
        }
Esempio n. 2
0
        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);

                    string returnValue = controllerClass.Run(component, "Run", context) as string;

                    if (returnValue != null)
                    {
                        return(returnValue);
                    }

                    return(TemplateUtil.ExtractBody(component.View.Render()));
                }
                catch
                {
                    component.SkipTearDown = true;

                    throw;
                }
            }
        }
Esempio n. 3
0
        internal static ControllerAction GetControllerAction(string url)
        {
            RouteResult routeResult = WebAppConfig.Router.Resolve(url);

            if (routeResult == null)
            {
                return(null);
            }

            ControllerClass controllerClass = routeResult.CreateControllerClass();

            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);
        }
Esempio n. 4
0
        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, token.TokenPosition));
            }

            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);
            }
        }
Esempio n. 5
0
        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;
            }
        }
Esempio n. 6
0
        internal static ActionResult RunControllerAction(ControllerAction controllerAction)
        {
            WebAppContext.AddControllerParameters(controllerAction.Parameters);

            ControllerClass controllerClass = controllerAction.ControllerClass;

            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);

                    var actionResult = returnValue as ActionResult;

                    if (actionResult != null)
                    {
                        if (actionResult.Final)
                        {
                            controller.SkipTearDown = true;
                        }

                        return(actionResult);
                    }

                    return(new RenderViewActionResult(controller.View));
                }
                catch
                {
                    controller.SkipTearDown = true;

                    throw;
                }
            }
        }
Esempio n. 7
0
        internal static ActionResult RunControllerAction(ControllerAction controllerAction)
        {
            WebAppContext.AddControllerParameters(controllerAction.Parameters);

            ControllerClass controllerClass = controllerAction.ControllerClass;

            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);

                    var actionResult = returnValue as ActionResult;

                    if (actionResult != null)
                    {
                        if (actionResult.Final)
                            controller.SkipTearDown = true;

                        return actionResult;
                    }

                    return new RenderViewActionResult(controller.View);
                }
                catch
                {
                    controller.SkipTearDown = true;

                    throw;
                }
            }
        }
Esempio n. 8
0
        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");
            }
        }
Esempio n. 9
0
 internal MvcPageHandler(ControllerAction controllerAction)
 {
     _controllerAction = controllerAction;
 }
Esempio n. 10
0
        internal static ControllerAction GetControllerAction(string url)
        {
            RouteResult routeResult = WebAppConfig.Router.Resolve(url);

            if (routeResult == null)
                return null;

            ControllerClass controllerClass = routeResult.CreateControllerClass();

            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;
        }
Esempio n. 11
0
 internal MvcPageHandler(ControllerAction controllerAction)
 {
     _controllerAction = controllerAction;
 }