/// <summary> /// Returns the full view path without the extension /// </summary> /// <param name="macro"></param> /// <param name="routableRequestContext"></param> /// <returns></returns> protected string GetFullViewPath(MacroDefinition macro, IRoutableRequestContext routableRequestContext) { var macroParts = macro.SelectedItem.Split('-'); var areaName = macroParts.Length > 1 ? macroParts[0] : ""; if (areaName.IsNullOrWhiteSpace()) { //TODO: this will obviously not support VB, the only way to do that is to change the macro's SelectedItem to store the extension return("~/Views/MacroPartials/" + string.Join("", macroParts) + ".cshtml"); } else { //create the full path to the macro in it's package folder return("~/App_Plugins/Packages/" + areaName + "/Views/MacroPartials/" + macroParts[1] + ".cshtml"); } }
/// <summary> /// Returns the full view path without the extension /// </summary> /// <param name="macro"></param> /// <param name="routableRequestContext"></param> /// <returns></returns> protected string GetFullViewPath(MacroDefinition macro, IRoutableRequestContext routableRequestContext) { var macroParts = macro.SelectedItem.Split('-'); var areaName = macroParts.Length > 1 ? macroParts[0] : ""; if (areaName.IsNullOrWhiteSpace()) { //TODO: this will obviously not support VB, the only way to do that is to change the macro's SelectedItem to store the extension return "~/Views/MacroPartials/" + string.Join("", macroParts) + ".cshtml"; } else { //create the full path to the macro in it's package folder return "~/App_Plugins/Packages/" + areaName + "/Views/MacroPartials/" + macroParts[1] + ".cshtml"; } }
/// <summary> /// Retreives the string result from a SurfaceController's ChildAction and returns a ContentResult for it. /// </summary> /// <param name="currentNode"></param> /// <param name="macroParams"></param> /// <param name="macro"></param> /// <param name="currentControllerContext"></param> /// <param name="routableRequestContext"></param> /// <returns></returns> public override ActionResult Execute( Content currentNode, IDictionary <string, string> macroParams, MacroDefinition macro, ControllerContext currentControllerContext, IRoutableRequestContext routableRequestContext) { MethodInfo childAction; var surfaceController = macro.GetSurfaceMacroChildAction(routableRequestContext.RegisteredComponents, out childAction); //we check the return type here, which is cached so it will be fast, but in theory when we execute the controller, it will //also ensure this check, though i think it does a different type of check so have left it here at least to display a nicer warning. if (!TypeFinder.IsTypeAssignableFrom <PartialViewResult>(childAction.ReturnType) && !TypeFinder.IsTypeAssignableFrom <ContentResult>(childAction.ReturnType)) { throw new InvalidOperationException("ChildAction macros should have a return type of " + typeof(PartialViewResult).Name + " or " + typeof(ContentResult).Name); } var controllerName = ControllerExtensions.GetControllerName(surfaceController.Metadata.ComponentType); //need to get the macroParams to put into an array var p = macroParams.ToDictionary <KeyValuePair <string, string>, string, object>(i => i.Key, i => i.Value); //proxy the request to the controller var result = currentControllerContext.Controller.ProxyRequestToController( controllerName, childAction.Name, surfaceController.Metadata, routableRequestContext.Application.Settings.RebelPaths.BackOfficePath, "surfaceId", p); ////write the results to a ContentResult return(new ContentResult() { Content = result.RenderedOutput }); }
public override IEnumerable <MacroParameter> GetMacroParameters( IBackOfficeRequestContext backOfficeRequestContext, MacroDefinition macroDefinition) { MethodInfo childAction; var surfaceController = macroDefinition.GetSurfaceMacroChildAction(backOfficeRequestContext.RegisteredComponents, out childAction); //now we need to get all of the parameters from the method info object var parameters = childAction.GetParameters(); if (parameters.Any(x => x.IsOut || x.IsRetval || x.IsLcid)) { //localize this exception since it wil be displayed in the UI throw new InvalidOperationException("Macro.ParamsFailedSurfaceAction.Message".Localize()); } return(childAction.GetParameters() .OrderBy(x => x.Position) .Select(x => new MacroParameter() { ParameterName = x.Name //TODO: Figure out how to automatically select which macro parameter editor to use })); }
public override ActionResult Execute(Content currentNode, IDictionary<string, string> macroParams, MacroDefinition macro, ControllerContext currentControllerContext, IRoutableRequestContext routableRequestContext) { //If this partial view is part of a package it will be prefixed with the package (area) name. //if so, then we need to ensure that the view is rendered in the context of the area so the view is found //properly. var macroParts = macro.SelectedItem.Split('-'); var areaName = macroParts.Length > 1 ? macroParts[0] : ""; var model = new PartialViewMacroModel(currentNode, new BendyObject(macroParams)); var partialViewResult = new PartialViewResult() { //if someone has put '-' in the view name, then we need to include those too, we just delimit the area name and view name by the 'first' '-' //ViewName = macroParts.Length > 1 // ? string.Join("", macroParts.Where((x, i) => i != 0)) // : string.Join("", macroParts), ViewName = GetFullViewPath(macro, routableRequestContext), ViewData = new ViewDataDictionary(model), TempData = new TempDataDictionary(), }; var partialViewControllerContext = currentControllerContext; if (!areaName.IsNullOrWhiteSpace()) { //need create a new controller context with the area info var areaRouteData = currentControllerContext.RouteData.Clone(); areaRouteData.DataTokens["area"] = areaName; partialViewControllerContext = new ControllerContext(currentControllerContext.HttpContext, areaRouteData, currentControllerContext.Controller); } //wire up the view object/data partialViewControllerContext.EnsureViewObjectDataOnResult(partialViewResult); return partialViewResult; }
/// <summary> /// Gets a list of Macro parameters for the definition /// </summary> /// <param name="backOfficeRequestContext"></param> /// <param name="macroDefinition"></param> /// <returns></returns> public abstract IEnumerable <MacroParameter> GetMacroParameters(IBackOfficeRequestContext backOfficeRequestContext, MacroDefinition macroDefinition);
/// <summary> /// Executes the macro engine to render the macro /// </summary> /// <returns></returns> public abstract ActionResult Execute(Content currentNode, IDictionary <string, string> macroParams, MacroDefinition macro, ControllerContext currentControllerContext, IRoutableRequestContext routableRequestContext);
public JsonResult PopulateMacroParameters(MacroDefinition macroDefinition) { var engine = this.BackOfficeRequestContext.RegisteredComponents.MacroEngines.SingleOrDefault(x => x.Metadata.EngineName.InvariantEquals(macroDefinition.MacroEngineName)); if (engine == null) { throw new InvalidOperationException("Could not find a MacroEngine registered with the name: " + macroDefinition.MacroEngineName); } try { //get the parameters from the engine's response var macroParams = engine.Value.GetMacroParameters(this.BackOfficeRequestContext, macroDefinition); return JsonParametersSuccess(macroParams); } catch (Exception ex) { return JsonParametersException(ex); } }
public override ActionResult Execute(Content currentNode, IDictionary <string, string> macroParams, MacroDefinition macro, ControllerContext currentControllerContext, IRoutableRequestContext routableRequestContext) { //If this partial view is part of a package it will be prefixed with the package (area) name. //if so, then we need to ensure that the view is rendered in the context of the area so the view is found //properly. var macroParts = macro.SelectedItem.Split('-'); var areaName = macroParts.Length > 1 ? macroParts[0] : ""; var model = new PartialViewMacroModel(currentNode, new BendyObject(macroParams)); var partialViewResult = new PartialViewResult() { //if someone has put '-' in the view name, then we need to include those too, we just delimit the area name and view name by the 'first' '-' //ViewName = macroParts.Length > 1 // ? string.Join("", macroParts.Where((x, i) => i != 0)) // : string.Join("", macroParts), ViewName = GetFullViewPath(macro, routableRequestContext), ViewData = new ViewDataDictionary(model), TempData = new TempDataDictionary(), }; var partialViewControllerContext = currentControllerContext; if (!areaName.IsNullOrWhiteSpace()) { //need create a new controller context with the area info var areaRouteData = currentControllerContext.RouteData.Clone(); areaRouteData.DataTokens["area"] = areaName; partialViewControllerContext = new ControllerContext(currentControllerContext.HttpContext, areaRouteData, currentControllerContext.Controller); } //wire up the view object/data partialViewControllerContext.EnsureViewObjectDataOnResult(partialViewResult); return(partialViewResult); }
/// <summary> /// Returns the PartialView Macro parameters /// </summary> /// <param name="backOfficeRequestContext"></param> /// <param name="macroDefinition"></param> /// <returns></returns> /// <remarks> /// Partial view macro parameters are determined by getting an instance of the partial view and looking for it's publicly declared /// properties which are done by declaring a region in Razor like so: /// @functions { /// public int Age {get;set;} /// } /// </remarks> public override IEnumerable <MacroParameter> GetMacroParameters(IBackOfficeRequestContext backOfficeRequestContext, MacroDefinition macroDefinition) { using (var uow = backOfficeRequestContext.Application.Hive.OpenReader <IFileStore>(new Uri("storage://templates"))) { var partialView = uow.Repositories.Get <File>(new HiveId("MacroPartials/" + macroDefinition.SelectedItem)); if (partialView == null) { //localize this exception since it wil be displayed in the UI throw new InvalidOperationException("Macro.ParamsFailedPartialView.Message".Localize()); } var partialMacro = BuildManager.CreateInstanceFromVirtualPath(partialView.RootRelativePath, typeof(PartialViewMacroPage)); return(partialMacro.GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) .Select(x => new MacroParameter { ParameterName = x.Name //TODO: Implement way of detecting which macro param editor to use })); } }
/// <summary> /// Gets a list of Macro parameters for the definition /// </summary> /// <param name="backOfficeRequestContext"></param> /// <param name="macroDefinition"></param> /// <returns></returns> public abstract IEnumerable<MacroParameter> GetMacroParameters(IBackOfficeRequestContext backOfficeRequestContext, MacroDefinition macroDefinition);
/// <summary> /// Executes the macro engine to render the macro /// </summary> /// <returns></returns> public abstract ActionResult Execute(Content currentNode, IDictionary<string, string> macroParams, MacroDefinition macro, ControllerContext currentControllerContext, IRoutableRequestContext routableRequestContext);
/// <summary> /// Returns the PartialView Macro parameters /// </summary> /// <param name="backOfficeRequestContext"></param> /// <param name="macroDefinition"></param> /// <returns></returns> /// <remarks> /// Partial view macro parameters are determined by getting an instance of the partial view and looking for it's publicly declared /// properties which are done by declaring a region in Razor like so: /// @functions { /// public int Age {get;set;} /// } /// </remarks> public override IEnumerable<MacroParameter> GetMacroParameters(IBackOfficeRequestContext backOfficeRequestContext, MacroDefinition macroDefinition) { using (var uow = backOfficeRequestContext.Application.Hive.OpenReader<IFileStore>(new Uri("storage://templates"))) { var partialView = uow.Repositories.Get<File>(new HiveId("MacroPartials/" + macroDefinition.SelectedItem)); if (partialView == null) { //localize this exception since it wil be displayed in the UI throw new InvalidOperationException("Macro.ParamsFailedPartialView.Message".Localize()); } var partialMacro = BuildManager.CreateInstanceFromVirtualPath(partialView.RootRelativePath, typeof(PartialViewMacroPage)); return partialMacro.GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) .Select(x => new MacroParameter { ParameterName = x.Name //TODO: Implement way of detecting which macro param editor to use }); } }