コード例 #1
0
ファイル: WebAppHelper.cs プロジェクト: TheMouster/mvc
        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;
                }
            }
        }
コード例 #2
0
ファイル: WebAppHelper.cs プロジェクト: viciproject/mvc
        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;
                }
            }
        }
コード例 #3
0
ファイル: WebAppHelper.cs プロジェクト: viciproject/mvc
        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);
        }
コード例 #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);
            }
        }
コード例 #5
0
ファイル: OfflineWebSession.cs プロジェクト: viciproject/mvc
        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;
            }
        }
コード例 #6
0
ファイル: WebAppHelper.cs プロジェクト: viciproject/mvc
        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;
                }
            }
        }
コード例 #7
0
ファイル: WebAppHelper.cs プロジェクト: TheMouster/mvc
        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;
                }
            }
        }
コード例 #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");
            }
        }
コード例 #9
0
ファイル: MvcPageHandler.cs プロジェクト: Niels-R/mvc
 internal MvcPageHandler(ControllerAction controllerAction)
 {
     _controllerAction = controllerAction;
 }
コード例 #10
0
ファイル: WebAppHelper.cs プロジェクト: TheMouster/mvc
        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;
        }
コード例 #11
0
ファイル: MvcPageHandler.cs プロジェクト: viciproject/mvc
 internal MvcPageHandler(ControllerAction controllerAction)
 {
     _controllerAction = controllerAction;
 }