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; } } }
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); }
internal static void LoadControllerClasses() // only used in unit testing { _controllerTypesByName = new Dictionary <string, ControllerClass>(StringComparer.OrdinalIgnoreCase); _viewComponentsByName = new Dictionary <string, ControllerClass>(StringComparer.OrdinalIgnoreCase); _controllerTypesByType = new Dictionary <Type, ControllerClass>(); List <Type> controllerTypes = new List <Type>(); foreach (Assembly assembly in _registeredAssemblies) { controllerTypes.AddRange(TypeHelper.FindCompatibleTypes(assembly, typeof(Controller))); } foreach (Type type in controllerTypes) { ControllerClass controllerClass = new ControllerClass(type); if (controllerClass.IsViewComponent) { _viewComponentsByName.Add(controllerClass.Name, controllerClass); } else { _controllerTypesByName.Add(controllerClass.Name, controllerClass); _controllerTypesByType.Add(type, controllerClass); foreach (Route route in controllerClass.Routes) { Router.InsertRoute(route); } } } }
internal static ControllerAction GetViewComponent(string name) { ControllerClass controllerClass = WebAppConfig.GetViewComponentClass(name); if (controllerClass == null) { return(null); } return(new ControllerAction(controllerClass)); }
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; } } }
internal static void LoadControllerClasses() // only used in unit testing { _controllerTypesByName = new Dictionary<string, ControllerClass>(StringComparer.OrdinalIgnoreCase); _viewComponentsByName = new Dictionary<string, ControllerClass>(StringComparer.OrdinalIgnoreCase); _controllerTypesByType = new Dictionary<Type, ControllerClass>(); List<Type> controllerTypes = new List<Type>(); foreach (Assembly assembly in _registeredAssemblies) { controllerTypes.AddRange(TypeHelper.FindCompatibleTypes(assembly, typeof (Controller))); } foreach (Type type in controllerTypes) { ControllerClass controllerClass = new ControllerClass(type); if (controllerClass.IsViewComponent) { _viewComponentsByName.Add(controllerClass.Name, controllerClass); } else { _controllerTypesByName.Add(controllerClass.Name, controllerClass); _controllerTypesByType.Add(type, controllerClass); foreach (Route route in controllerClass.Routes) Router.InsertRoute(route); } } }
public ControllerAction(ControllerClass controllerClass, string actionMethod) : this() { ControllerClass = controllerClass; ActionMethod = actionMethod; }
public ControllerAction(ControllerClass controllerClass) : this(controllerClass, "Run") { }