Exemplo n.º 1
0
 /// <summary>
 /// Constructor initializes custom action invoker
 /// </summary>
 public UmbracoController()
 {
     //this could be done by IoC but we really don't want people to have to create
     //the custom constructor each time they want to create a controller that extends this one.
     ActionInvoker          = new UmbracoActionInvoker(RoutableRequestContext);
     RoutableRequestContext = DependencyResolver.Current.GetService <IRoutableRequestContext>();
 }
 public PugpigSurfaceController(IAbstractRequest abstractRequest, 
     IPugpigRepository pugpigRepository, IRoutableRequestContext routableRequest,IRenderModelFactory renderModelFactory)
 {
     m_pugpigRepository = pugpigRepository;
     m_routableRequest = routableRequest;
     m_renderModelFactory = renderModelFactory;
     m_abstractRequest = abstractRequest;
 }
Exemplo n.º 3
0
        public UmbracoHelper(ControllerContext controllerContext, IRoutableRequestContext requestContext, IRenderModelFactory modelFactory)
        {
            _requestContext = requestContext;
            _controllerContext = controllerContext;
            _modelFactory = modelFactory;

            _currentPage = _modelFactory.Create(_controllerContext.HttpContext, _controllerContext.HttpContext.Request.RawUrl).CurrentNode;

            _urlHelper = new UrlHelper(_controllerContext.RequestContext);
        }
Exemplo n.º 4
0
        public RebelHelper(ControllerContext controllerContext, IRoutableRequestContext requestContext, IRenderModelFactory modelFactory)
        {
            _requestContext    = requestContext;
            _controllerContext = controllerContext;
            _modelFactory      = modelFactory;

            _currentPage = _modelFactory.Create(_controllerContext.HttpContext, _controllerContext.HttpContext.Request.RawUrl).CurrentNode;

            _urlHelper = new UrlHelper(_controllerContext.RequestContext);
        }
Exemplo n.º 5
0
        /// <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/Umbraco/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/Umbraco/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";
            }
        }
Exemplo n.º 7
0
        protected PackageAction(IRoutableRequestContext applicationContext)
            : base(applicationContext)
        {
            //Locate the editor attribute
            var packageActionAttributes = GetType()
                                          .GetCustomAttributes(typeof(PackageActionAttribute), false)
                                          .OfType <PackageActionAttribute>();

            if (!packageActionAttributes.Any())
            {
                throw new InvalidOperationException("The PackageAction is missing the " + typeof(PackageActionAttribute).FullName + " attribute");
            }

            //assign the properties of this object to those of the metadata attribute
            var attr = packageActionAttributes.First();

            //set this objects properties
            Mapper.Map(attr, this);
        }
Exemplo n.º 8
0
        protected PackageAction(IRoutableRequestContext applicationContext)
            : base(applicationContext)
        {
            //Locate the editor attribute
            var packageActionAttributes = GetType()
                .GetCustomAttributes(typeof(PackageActionAttribute), false)
                .OfType<PackageActionAttribute>();

            if (!packageActionAttributes.Any())
            {
                throw new InvalidOperationException("The PackageAction is missing the " + typeof(PackageActionAttribute).FullName + " attribute");
            }

            //assign the properties of this object to those of the metadata attribute
            var attr = packageActionAttributes.First();

            //set this objects properties
            Mapper.Map(attr, this);
        }
        /// <summary>
        /// Checks the sources to return the current routable request context the quickest
        /// </summary>
        /// <param name="activator"></param>
        /// <param name="view"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static IRoutableRequestContext GetRoutableRequestContextFromSources(this IPostViewPageActivator activator, object view, ControllerContext context)
        {
            //check if the view is already IRequiresRoutableRequestContext and see if its set, if so use it, otherwise
            //check if the current controller is IRequiresRoutableRequest context as it will be a bit quicker
            //to get it from there than to use the resolver, otherwise use the resolver.
            IRoutableRequestContext routableRequestContext = null;

            if (view is IRequiresRoutableRequestContext && ((IRequiresRoutableRequestContext)view).RoutableRequestContext != null)
            {
                routableRequestContext = ((IRequiresRoutableRequestContext)view).RoutableRequestContext;
            }
            else if (context.Controller is IRequiresRoutableRequestContext)
            {
                routableRequestContext = ((IRequiresRoutableRequestContext)context.Controller).RoutableRequestContext;
            }
            else
            {
                routableRequestContext = DependencyResolver.Current.GetService <IRoutableRequestContext>();
            }
            return(routableRequestContext);
        }
Exemplo n.º 10
0
        /// <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
            });
        }
Exemplo n.º 11
0
        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);

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

            using (var controller = surfaceController.Value)
            {
                if (controller == null)
                {
                    throw new TypeLoadException("Could not create controller: " + UmbracoController.GetControllerName(surfaceController.Metadata.ComponentType));
                }

                //need to get the macroParams to put into an array
                var actionParams = macroParams.Select(i => i.Value).ToArray();

                var area = routableRequestContext.Application.Settings.UmbracoPaths.BackOfficePath;
                if (surfaceController.Metadata.PluginDefinition.HasRoutablePackageArea())
                {
                    area = surfaceController.Metadata.PluginDefinition.PackageName;
                }

                //proxy the request to the controller
                var result = currentControllerContext.Controller.ProxyRequestToController(controller, childAction, area, actionParams);

                return(result);
            }
        }
        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);

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

            using (var controller = surfaceController.Value)
            {
                if (controller == null)
                    throw new TypeLoadException("Could not create controller: " + UmbracoController.GetControllerName(surfaceController.Metadata.ComponentType));

                //need to get the macroParams to put into an array
                var actionParams = macroParams.Select(i => i.Value).ToArray();

                var area = routableRequestContext.Application.Settings.UmbracoPaths.BackOfficePath;
                if (surfaceController.Metadata.PluginDefinition.HasRoutablePackageArea())
                {
                    area = surfaceController.Metadata.PluginDefinition.PackageName;    
                }

                //proxy the request to the controller        
                var result = currentControllerContext.Controller.ProxyRequestToController(controller, childAction, area, actionParams);

                return result;
            }
        }
        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;
        }
Exemplo n.º 14
0
        /// <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.UmbracoPaths.BackOfficePath,
                "surfaceId",
                p);

            ////write the results to a ContentResult
            return new ContentResult() { Content = result.RenderedOutput };
        }
Exemplo n.º 15
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="routableRequestContext"></param>
 protected SurfaceController(IRoutableRequestContext routableRequestContext)
 {
     RoutableRequestContext = routableRequestContext;
 }
Exemplo n.º 16
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="routableRequestContext"></param>
 protected SurfaceController(IRoutableRequestContext routableRequestContext)
 {
     RoutableRequestContext = routableRequestContext;            
 }
Exemplo n.º 17
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="routableRequestContext"></param>
 protected SurfaceController(IRoutableRequestContext routableRequestContext)
 {
     RoutableRequestContext = routableRequestContext;
     InstanceId             = Guid.NewGuid();
 }
Exemplo n.º 18
0
 /// <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 TreePickerController(IRoutableRequestContext requestContext)
 {
     _requestContext = requestContext;
 }
Exemplo n.º 20
0
 public MacroController(IRoutableRequestContext requestContext, IRenderModelFactory renderModelFactory)
 {
     RoutableRequestContext = requestContext;
     _renderModelFactory = renderModelFactory;
     _macroRenderer = new MacroRenderer(RoutableRequestContext.RegisteredComponents, RoutableRequestContext);
 }
Exemplo n.º 21
0
 /// <summary>
 /// Creates a new instance of the MacroRender class that provides utility methods for compiling and rendering macros.
 /// </summary>
 public MacroRenderer(ComponentRegistrations componentRegistrations, IRoutableRequestContext routableRequestContext)
 {
     _componentRegistrations = componentRegistrations;
     _routableRequestContext = routableRequestContext;
     _applicationContext     = routableRequestContext.Application;
 }
Exemplo n.º 22
0
 /// <summary>
 /// Constructor initializes custom action invoker
 /// </summary>
 public RebelController(IRoutableRequestContext routableRequestContext)
 {
     ActionInvoker          = new RebelActionInvoker(RoutableRequestContext);
     RoutableRequestContext = routableRequestContext;
 }
Exemplo n.º 23
0
 public TestSurfaceController(IRoutableRequestContext routableRequestContext)
     : base(routableRequestContext)
 {
 }
 public MediaProxyController(IRoutableRequestContext routableRequestContext)
 {
     ActionInvoker          = new RoutableRequestActionInvoker(RoutableRequestContext);
     RoutableRequestContext = routableRequestContext;
 }
Exemplo n.º 25
0
 public MediaProxyController(IRoutableRequestContext routableRequestContext)
 {
     ActionInvoker = new RoutableRequestActionInvoker(RoutableRequestContext);
     RoutableRequestContext = routableRequestContext;
 }
 public PugpigRepository(IRoutableRequestContext context)
 {
     m_context = context;
 }
Exemplo n.º 27
0
 public MacroController(IRoutableRequestContext requestContext, IRenderModelFactory renderModelFactory)
 {
     RoutableRequestContext = requestContext;
     _renderModelFactory    = renderModelFactory;
     _macroRenderer         = new MacroRenderer(RoutableRequestContext.RegisteredComponents, RoutableRequestContext);
 }
Exemplo n.º 28
0
 public TreePickerController(IRoutableRequestContext requestContext)
 {
     _requestContext = requestContext;
 }
 /// <summary>
 /// Creates a new RedirectToUmbracoResult
 /// </summary>
 /// <param name="pageEntity"></param>
 /// <param name="routableRequestContext"></param>
 public RedirectToUmbracoPageResult(TypedEntity pageEntity, IRoutableRequestContext routableRequestContext)
 {            
     _pageEntity = pageEntity;
     _pageId = pageEntity.Id;
     _routableRequestContext = routableRequestContext;
 }
Exemplo n.º 30
0
 public UserRoleMatchRule(HttpContextBase http, IRoutableRequestContext routableRequestContext)
 {
     _http = http;
     _routableRequestContext = routableRequestContext;
 }
Exemplo n.º 31
0
        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);
        }
Exemplo n.º 32
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="routableRequestContext"></param>
 protected SurfaceController(IRoutableRequestContext routableRequestContext)
 {
     RoutableRequestContext = routableRequestContext;
     InstanceId = Guid.NewGuid();
 }
Exemplo n.º 33
0
 /// <summary>
 /// Creates a new RedirectToRebelResult
 /// </summary>
 /// <param name="pageId"></param>
 /// <param name="routableRequestContext"></param>
 public RedirectToRebelPageResult(HiveId pageId, IRoutableRequestContext routableRequestContext)
 {
     _pageId = pageId;
     _routableRequestContext = routableRequestContext;
 }
Exemplo n.º 34
0
 public RebelActionInvoker(IRoutableRequestContext routableRequestContext)
     : base(routableRequestContext)
 { }
Exemplo n.º 35
0
 public AuthSurfaceController(IRoutableRequestContext context)
 {
     _context = context;
 }
Exemplo n.º 36
0
 public UserRoleMatchRule(HttpContextBase http, IRoutableRequestContext routableRequestContext)
 {
     _http = http;
     _routableRequestContext = routableRequestContext;
 }
Exemplo n.º 37
0
 public TestSurfaceController(IRoutableRequestContext routableRequestContext)
     : base(routableRequestContext)
 {
 }
Exemplo n.º 38
0
        public IHtmlString RenderField(IRoutableRequestContext routableRequestContext, ControllerContext controllerContext, Content item,
                                       string fieldAlias = "", string valueAlias         = "", string altFieldAlias        = "", string altValueAlias = "", string altText = "", string insertBefore = "", string insertAfter = "",
                                       bool recursive    = false, bool convertLineBreaks = false, bool removeParagraphTags = false,
                                       UmbracoRenderItemCaseType casing       = UmbracoRenderItemCaseType.Unchanged,
                                       UmbracoRenderItemEncodingType encoding = UmbracoRenderItemEncodingType.Unchanged)
        {
            var sb = new StringBuilder();

            // Handle hard coded "friendly" system keys
            if (fieldAlias == "Name" || fieldAlias == "UrlName")
            {
                valueAlias = fieldAlias;
                fieldAlias = NodeNameAttributeDefinition.AliasValue;
            }

            if (fieldAlias == "CurrentTemplateId")
            {
                fieldAlias = SelectedTemplateAttributeDefinition.AliasValue;
                valueAlias = "TemplateId";
            }

            if (altFieldAlias == "Name" || altFieldAlias == "UrlName")
            {
                altValueAlias = altFieldAlias;
                altFieldAlias = NodeNameAttributeDefinition.AliasValue;
            }

            if (altFieldAlias == "CurrentTemplateId")
            {
                altFieldAlias = SelectedTemplateAttributeDefinition.AliasValue;
                altValueAlias = "TemplateId";
            }

            var val = item.Field <string>(fieldAlias, valueAlias, recursive);

            if (val.IsNullOrWhiteSpace() && !altFieldAlias.IsNullOrWhiteSpace())
            {
                val = item.Field <string>(altFieldAlias, altValueAlias, recursive);
            }

            if (val.IsNullOrWhiteSpace() && !altText.IsNullOrWhiteSpace())
            {
                val = altText;
            }

            if (!val.IsNullOrWhiteSpace())
            {
                switch (casing)
                {
                case UmbracoRenderItemCaseType.Upper:
                    val = val.ToUpper();
                    break;

                case UmbracoRenderItemCaseType.Lower:
                    val = val.ToLower();
                    break;

                case UmbracoRenderItemCaseType.Title:
                    val = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(val);
                    break;

                default:
                    break;
                }

                switch (encoding)
                {
                case UmbracoRenderItemEncodingType.Url:
                    val = HttpUtility.UrlEncode(val);
                    break;

                case UmbracoRenderItemEncodingType.Html:
                    val = HttpUtility.HtmlEncode(val);
                    break;

                default:
                    break;
                }

                if (convertLineBreaks)
                {
                    val = val.Replace(Environment.NewLine, "<br />");
                }

                if (removeParagraphTags)
                {
                    val = val.Trim().Trim("<p>").Trim("</p>");
                }

                sb.Append(HttpUtility.HtmlDecode(insertBefore));
                sb.Append(val);
                sb.Append(HttpUtility.HtmlDecode(insertAfter));
            }

            //now we need to parse the macro syntax out and replace it with the rendered macro content

            var macroRenderer = new MacroRenderer(routableRequestContext.RegisteredComponents, routableRequestContext);
            var macroParser   = new MacroSyntaxParser();
            IEnumerable <MacroParserResult> parseResults;
            var parsed = macroParser.Parse(sb.ToString(),
                                           (macroAlias, macroParams)
                                           => macroRenderer.RenderMacroAsString(macroAlias,
                                                                                macroParams,
                                                                                controllerContext, false,
                                                                                () => item), out parseResults);

            //now we need to parse any internal links and replace with actual URLs
            var linkParse = new LinkSyntaxParser();

            parsed = linkParse.Parse(parsed, x => routableRequestContext.RoutingEngine.GetUrl(x));

            return(new MvcHtmlString(parsed));
        }
Exemplo n.º 39
0
        public IHtmlString RenderField(IRoutableRequestContext routableRequestContext, ControllerContext controllerContext, Content item,
                                       string fieldAlias = "", string valueAlias         = "", string altFieldAlias        = "", string altValueAlias = "", string altText = "", string insertBefore = "", string insertAfter = "",
                                       bool recursive    = false, bool convertLineBreaks = false, bool removeParagraphTags = false,
                                       RebelRenderItemCaseType casing       = RebelRenderItemCaseType.Unchanged,
                                       RebelRenderItemEncodingType encoding = RebelRenderItemEncodingType.Unchanged,
                                       string formatString = "")
        {
            var sb = new StringBuilder();

            var valObj = GetFieldValue(item, fieldAlias, valueAlias, recursive);

            if ((valObj == null || valObj.ToString().IsNullOrWhiteSpace()) && !altFieldAlias.IsNullOrWhiteSpace())
            {
                valObj = GetFieldValue(item, altFieldAlias, altValueAlias, recursive);
            }

            if ((valObj == null || valObj.ToString().IsNullOrWhiteSpace()) && !altText.IsNullOrWhiteSpace())
            {
                valObj = altText;
            }

            if (!formatString.IsNullOrWhiteSpace())
            {
                formatString = "{0:" + formatString.Replace("\\", "\\\\").Replace("\"", "\\\"") + "}";
            }
            else
            {
                formatString = "{0}";
            }

            var val = string.Format(formatString, valObj);

            if (!val.IsNullOrWhiteSpace())
            {
                switch (casing)
                {
                case RebelRenderItemCaseType.Upper:
                    val = val.ToUpper();
                    break;

                case RebelRenderItemCaseType.Lower:
                    val = val.ToLower();
                    break;

                case RebelRenderItemCaseType.Title:
                    val = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(val);
                    break;

                default:
                    break;
                }

                switch (encoding)
                {
                case RebelRenderItemEncodingType.Url:
                    val = HttpUtility.UrlEncode(val);
                    break;

                case RebelRenderItemEncodingType.Html:
                    val = HttpUtility.HtmlEncode(val);
                    break;

                default:
                    break;
                }

                if (convertLineBreaks)
                {
                    val = val.Replace(Environment.NewLine, "<br />");
                }

                if (removeParagraphTags)
                {
                    val = val.Trim().Trim("<p>").Trim("</p>");
                }

                sb.Append(HttpUtility.HtmlDecode(insertBefore));
                sb.Append(val);
                sb.Append(HttpUtility.HtmlDecode(insertAfter));
            }

            //now we need to parse the macro syntax out and replace it with the rendered macro content

            var macroRenderer = new MacroRenderer(routableRequestContext.RegisteredComponents, routableRequestContext);
            var macroParser   = new MacroSyntaxParser();
            IEnumerable <MacroParserResult> parseResults;
            var parsed = macroParser.Parse(sb.ToString(),
                                           (macroAlias, macroParams)
                                           => macroRenderer.RenderMacroAsString(macroAlias,
                                                                                macroParams,
                                                                                controllerContext, false,
                                                                                () => item), out parseResults);

            //now we need to parse any internal links and replace with actual URLs
            var linkParse = new LinkSyntaxParser();

            parsed = linkParse.Parse(parsed, x => routableRequestContext.RoutingEngine.GetUrl(x));

            return(new MvcHtmlString(parsed));
        }
Exemplo n.º 40
0
 public RebelActionInvoker(IRoutableRequestContext routableRequestContext)
     : base(routableRequestContext)
 {
 }
Exemplo n.º 41
0
 /// <summary>
 /// Empty constructor, uses DependencyResolver to resolve the IRoutableRequestContext
 /// </summary>
 protected SurfaceController()
 {
     RoutableRequestContext = DependencyResolver.Current.GetService<IRoutableRequestContext>();
 }
 public RoutableRequestActionInvoker(IRoutableRequestContext routableRequestContext)
 {
     RoutableRequestContext = routableRequestContext;
 }
Exemplo n.º 43
0
 /// <summary>
 /// Constructor initializes custom action invoker
 /// </summary>
 public UmbracoController(IRoutableRequestContext routableRequestContext)
 {
     ActionInvoker          = new UmbracoActionInvoker(RoutableRequestContext);
     RoutableRequestContext = routableRequestContext;
 }
Exemplo n.º 44
0
 public MacroRenderer(ComponentRegistrations componentRegistrations, IRoutableRequestContext routableRequestContext)
 {
     _componentRegistrations = componentRegistrations;
     _routableRequestContext = routableRequestContext;
     _applicationContext = routableRequestContext.Application;
 }
Exemplo n.º 45
0
 /// <summary>
 /// Empty constructor, uses DependencyResolver to resolve the IRoutableRequestContext
 /// </summary>
 protected SurfaceController()
 {
     RoutableRequestContext = DependencyResolver.Current.GetService <IRoutableRequestContext>();
 }
 public UmbracoActionInvoker(IRoutableRequestContext routableRequestContext)
     : base(routableRequestContext)
 {
 }
 /// <summary>
 /// Creates a new RedirectToUmbracoResult
 /// </summary>
 /// <param name="pageId"></param>
 /// <param name="routableRequestContext"></param>
 public RedirectToUmbracoPageResult(HiveId pageId, IRoutableRequestContext routableRequestContext)
 {
     _pageId = pageId;
     _routableRequestContext = routableRequestContext;
 }
Exemplo n.º 48
0
 /// <summary>
 /// Creates a new RedirectToRebelResult
 /// </summary>
 /// <param name="pageEntity"></param>
 /// <param name="routableRequestContext"></param>
 public RedirectToRebelPageResult(TypedEntity pageEntity, IRoutableRequestContext routableRequestContext)
 {
     _pageEntity             = pageEntity;
     _pageId                 = pageEntity.Id;
     _routableRequestContext = routableRequestContext;
 }
 public RoutableRequestActionInvoker(IRoutableRequestContext routableRequestContext)
 {
     RoutableRequestContext = routableRequestContext;
 }
 public UmbracoActionInvoker(IRoutableRequestContext routableRequestContext)
     : base(routableRequestContext)
 { }
Exemplo n.º 51
0
        public IHtmlString RenderField(IRoutableRequestContext routableRequestContext, ControllerContext controllerContext, Content item,
            string fieldAlias = "", string valueAlias = "", string altFieldAlias = "", string altValueAlias = "", string altText = "", string insertBefore = "", string insertAfter = "",
            bool recursive = false, bool convertLineBreaks = false, bool removeParagraphTags = false,
            RebelRenderItemCaseType casing = RebelRenderItemCaseType.Unchanged,
            RebelRenderItemEncodingType encoding = RebelRenderItemEncodingType.Unchanged,
            string formatString = "")
        {
            var sb = new StringBuilder();

            var valObj = GetFieldValue(item, fieldAlias, valueAlias, recursive);

            if ((valObj == null || valObj.ToString().IsNullOrWhiteSpace()) && !altFieldAlias.IsNullOrWhiteSpace())
            {
                valObj = GetFieldValue(item, altFieldAlias, altValueAlias, recursive);
            }

            if ((valObj == null || valObj.ToString().IsNullOrWhiteSpace()) && !altText.IsNullOrWhiteSpace())
            {
                valObj = altText;
            }

            if(!formatString.IsNullOrWhiteSpace())
                formatString = "{0:" + formatString.Replace("\\", "\\\\").Replace("\"", "\\\"") + "}";
            else
                formatString = "{0}";

            var val = string.Format(formatString, valObj);

            if(!val.IsNullOrWhiteSpace())
            {
                switch (casing)
                {
                    case RebelRenderItemCaseType.Upper:
                        val = val.ToUpper();
                        break;
                    case RebelRenderItemCaseType.Lower:
                        val = val.ToLower();
                        break;
                    case RebelRenderItemCaseType.Title:
                        val = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(val);
                        break;
                    default:
                        break;
                }

                switch (encoding)
                {
                    case RebelRenderItemEncodingType.Url:
                        val = HttpUtility.UrlEncode(val);
                        break;
                    case RebelRenderItemEncodingType.Html:
                        val = HttpUtility.HtmlEncode(val);
                        break;
                    default:
                        break;
                }

                if (convertLineBreaks)
                {
                    val = val.Replace(Environment.NewLine, "<br />");
                }

                if (removeParagraphTags)
                {
                    val = val.Trim().Trim("<p>").Trim("</p>");
                }

                sb.Append(HttpUtility.HtmlDecode(insertBefore));
                sb.Append(val);
                sb.Append(HttpUtility.HtmlDecode(insertAfter));
            }

            //now we need to parse the macro syntax out and replace it with the rendered macro content

            var macroRenderer = new MacroRenderer(routableRequestContext.RegisteredComponents, routableRequestContext);
            var macroParser = new MacroSyntaxParser();
            IEnumerable<MacroParserResult> parseResults;
            var parsed = macroParser.Parse(sb.ToString(),
                                           (macroAlias, macroParams)
                                           => macroRenderer.RenderMacroAsString(macroAlias,
                                                                                macroParams,
                                                                                controllerContext, false,
                                                                                () => item), out parseResults);

            //now we need to parse any internal links and replace with actual URLs
            var linkParse = new LinkSyntaxParser();
            parsed = linkParse.Parse(parsed, x => routableRequestContext.RoutingEngine.GetUrl(x));

            return new MvcHtmlString(parsed);
        }
Exemplo n.º 52
0
 /// <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);
Exemplo n.º 53
0
        public IHtmlString RenderField(IRoutableRequestContext routableRequestContext, ControllerContext controllerContext, Content item,
            string fieldAlias = "", string valueAlias = "", string altFieldAlias = "", string altValueAlias = "", string altText = "", string insertBefore = "", string insertAfter = "",
            bool recursive = false, bool convertLineBreaks = false, bool removeParagraphTags = false,
            UmbracoRenderItemCaseType casing = UmbracoRenderItemCaseType.Unchanged,
            UmbracoRenderItemEncodingType encoding = UmbracoRenderItemEncodingType.Unchanged)
        {
            var sb = new StringBuilder();

            // Handle hard coded "friendly" system keys
            if (fieldAlias == "Name" || fieldAlias == "UrlName")
            {
                valueAlias = fieldAlias;
                fieldAlias = NodeNameAttributeDefinition.AliasValue;
            }

            if (fieldAlias == "CurrentTemplateId")
            {
                fieldAlias = SelectedTemplateAttributeDefinition.AliasValue;
                valueAlias = "TemplateId";
            }

            if (altFieldAlias == "Name" || altFieldAlias == "UrlName")
            {
                altValueAlias = altFieldAlias;
                altFieldAlias = NodeNameAttributeDefinition.AliasValue;
            }

            if (altFieldAlias == "CurrentTemplateId")
            {
                altFieldAlias = SelectedTemplateAttributeDefinition.AliasValue;
                altValueAlias = "TemplateId";
            }

            var val = item.Field<string>(fieldAlias, valueAlias, recursive);

            if (val.IsNullOrWhiteSpace() && !altFieldAlias.IsNullOrWhiteSpace())
            {
                val = item.Field<string>(altFieldAlias, altValueAlias, recursive);
            }

            if (val.IsNullOrWhiteSpace() && !altText.IsNullOrWhiteSpace())
            {
                val = altText;
            }

            if(!val.IsNullOrWhiteSpace())
            {
                switch (casing)
                {
                    case UmbracoRenderItemCaseType.Upper:
                        val = val.ToUpper();
                        break;
                    case UmbracoRenderItemCaseType.Lower:
                        val = val.ToLower();
                        break;
                    case UmbracoRenderItemCaseType.Title:
                        val = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(val);
                        break;
                    default:
                        break;
                }

                switch (encoding)
                {
                    case UmbracoRenderItemEncodingType.Url:
                        val = HttpUtility.UrlEncode(val);
                        break;
                    case UmbracoRenderItemEncodingType.Html:
                        val = HttpUtility.HtmlEncode(val);
                        break;
                    default:
                        break;
                }

                if (convertLineBreaks)
                {
                    val = val.Replace(Environment.NewLine, "<br />");
                }

                if (removeParagraphTags)
                {
                    val = val.Trim().Trim("<p>").Trim("</p>");
                }

                sb.Append(HttpUtility.HtmlDecode(insertBefore));
                sb.Append(val);
                sb.Append(HttpUtility.HtmlDecode(insertAfter));
            }

            //now we need to parse the macro syntax out and replace it with the rendered macro content

            var macroRenderer = new MacroRenderer(routableRequestContext.RegisteredComponents, routableRequestContext);
            var macroParser = new MacroSyntaxParser();
            IEnumerable<MacroParserResult> parseResults;
            var parsed = macroParser.Parse(sb.ToString(),
                                           (macroAlias, macroParams)
                                           => macroRenderer.RenderMacroAsString(macroAlias,
                                                                                macroParams,
                                                                                controllerContext, false,
                                                                                () => item), out parseResults);

            //now we need to parse any internal links and replace with actual URLs
            var linkParse = new LinkSyntaxParser();
            parsed = linkParse.Parse(parsed, x => routableRequestContext.RoutingEngine.GetUrl(x));

            return new MvcHtmlString(parsed);
        }
Exemplo n.º 54
0
 public AuthSurfaceController(IRoutableRequestContext context)
 {
     _context = context;
 }