Пример #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);

                    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;
                }
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        internal static ControllerAction GetViewComponent(string name)
        {
            ControllerClass controllerClass = WebAppConfig.GetViewComponentClass(name);

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

            return(new ControllerAction(controllerClass));
        }
Пример #4
0
        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;
                }
            }
        }
Пример #5
0
 public ControllerAction(ControllerClass controllerClass, string actionMethod) : this()
 {
     ControllerClass = controllerClass;
     ActionMethod = actionMethod;
 }
Пример #6
0
 public ControllerAction(ControllerClass controllerClass) : this(controllerClass, "Run")
 {
 }
Пример #7
0
 public ControllerAction(ControllerClass controllerClass, string actionMethod) : this()
 {
     ControllerClass = controllerClass;
     ActionMethod    = actionMethod;
 }
Пример #8
0
 public ControllerAction(ControllerClass controllerClass) : this(controllerClass, "Run")
 {
 }