Exemplo n.º 1
0
        private MenuItem CreateMenuItemByTemplate(string areaName, MenuItemTemplate template, ControllerContext controllerContext)
        {
            MenuItem item = new MenuItem()
            {
                Action = template.Action,
                Area = string.IsNullOrEmpty(template.Area) ? areaName : template.Area,
                Controller = template.Controller,
                HtmlAttributes = new RouteValueDictionary(template.HtmlAttributes),
                Localizable = template.Localizable,
                Name = template.Name,
                ReadOnlyProperties = template.ReadOnlyProperties,
                RouteValues = new RouteValueDictionary(template.RouteValues),
                Text = template.Text,
                Visible = template.Visible,
                Initializer = template.Initializer
            };

            List<MenuItem> items = new List<MenuItem>();
            if (template.ItemContainers != null)
            {
                foreach (var itemContainer in template.ItemContainers)
                {
                    items.AddRange(itemContainer.GetItems(areaName, controllerContext));
                }
            }

            item.Items = items;

            return item;
        }
Exemplo n.º 2
0
        private MenuItem CreateMenuItemByTemplate(string areaName, MenuItemTemplate template, ControllerContext controllerContext)
        {
            MenuItem item = new MenuItem()
            {
                Action             = template.Action,
                Area               = string.IsNullOrEmpty(template.Area) ? areaName : template.Area,
                Controller         = template.Controller,
                HtmlAttributes     = new RouteValueDictionary(template.HtmlAttributes),
                Localizable        = template.Localizable,
                Name               = template.Name,
                ReadOnlyProperties = template.ReadOnlyProperties,
                RouteValues        = new RouteValueDictionary(template.RouteValues),
                Text               = template.Text,
                Visible            = template.Visible,
                Initializer        = template.Initializer
            };

            List <MenuItem> items = new List <MenuItem>();

            if (template.ItemContainers != null)
            {
                foreach (var itemContainer in template.ItemContainers)
                {
                    items.AddRange(itemContainer.GetItems(areaName, controllerContext));
                }
            }

            item.Items = items;

            return(item);
        }
Exemplo n.º 3
0
        static IEnumerable <IMenuItemContainer> CreateItems(Configuration.MenuItemElementCollection itemElementCollection, List <IMenuItemContainer> itemContainers)
        {
            if (itemElementCollection != null)
            {
                if (!string.IsNullOrEmpty(itemElementCollection.Type))
                {
                    itemContainers.Add((IMenuItemContainer)Activator.CreateInstance(Type.GetType(itemElementCollection.Type)));
                }
                else
                {
                    foreach (Configuration.MenuItemElement element in itemElementCollection)
                    {
                        IMenuItemContainer itemContainer = null;
                        if (!string.IsNullOrEmpty(element.Type))
                        {
                            itemContainer = (IMenuItemContainer)Activator.CreateInstance(Type.GetType(element.Type));
                        }
                        else
                        {
                            itemContainer = new MenuItemTemplate();
                        }
                        itemContainers.Add(itemContainer);
                        if (itemContainer is MenuItemTemplate)
                        {
                            var itemTemplate = (MenuItemTemplate)itemContainer;

                            itemTemplate.Name               = element.Name;
                            itemTemplate.Text               = element.Text;
                            itemTemplate.Action             = element.Action;
                            itemTemplate.Controller         = element.Controller;
                            itemTemplate.Visible            = element.Visible;
                            itemTemplate.Area               = element.Area;
                            itemTemplate.RouteValues        = new System.Web.Routing.RouteValueDictionary(element.RouteValues.Attributes);
                            itemTemplate.HtmlAttributes     = new System.Web.Routing.RouteValueDictionary(element.HtmlAttributes.Attributes);
                            itemTemplate.ReadOnlyProperties = element.UnrecognizedProperties;

                            if (!string.IsNullOrEmpty(element.Initializer))
                            {
                                Type type = Type.GetType(element.Initializer);
                                itemTemplate.Initializer = (IMenuItemInitializer)Activator.CreateInstance(type);
                            }

                            List <IMenuItemContainer> subItems = new List <IMenuItemContainer>();
                            if (element.Items != null)
                            {
                                itemTemplate.ItemContainers = CreateItems(element.Items, subItems);
                            }
                        }
                    }
                }
            }
            return(itemContainers);
        }
Exemplo n.º 4
0
 private void FetchPermissions(string moduleName, MenuItemTemplate menuItemTemplate, List<Permission> permissions)
 {
     if (menuItemTemplate.ReadOnlyProperties != null)
     {
         var permissionGroup = menuItemTemplate.ReadOnlyProperties["permissionGroup"];
         var permissionName = menuItemTemplate.ReadOnlyProperties["PermissionName"];
         if (!string.IsNullOrEmpty(permissionName))
         {
             permissions.Add(new Permission() { AreaName = moduleName, Group = permissionGroup, Name = permissionName, DisplayName = permissionName });
         }
     }
     foreach (var item in menuItemTemplate.ItemContainers)
     {
         if (item is MenuItemTemplate)
         {
             FetchPermissions(moduleName, (MenuItemTemplate)item, permissions);
         }
     }
 }
Exemplo n.º 5
0
Arquivo: Menu.cs Projeto: Godoy/CMS
        static IEnumerable<IMenuItemContainer> CreateItems(Configuration.MenuItemElementCollection itemElementCollection, List<IMenuItemContainer> itemContainers)
        {
            if (itemElementCollection != null)
            {
                if (!string.IsNullOrEmpty(itemElementCollection.Type))
                {
                    itemContainers.Add((IMenuItemContainer)Activator.CreateInstance(Type.GetType(itemElementCollection.Type)));
                }
                else
                {
                    foreach (Configuration.MenuItemElement element in itemElementCollection)
                    {
                        IMenuItemContainer itemContainer = null;
                        if (!string.IsNullOrEmpty(element.Type))
                        {
                            itemContainer = (IMenuItemContainer)Activator.CreateInstance(Type.GetType(element.Type));
                        }
                        else
                        {
                            itemContainer = new MenuItemTemplate();
                        }
                        itemContainers.Add(itemContainer);
                        if (itemContainer is MenuItemTemplate)
                        {
                            var itemTemplate = (MenuItemTemplate)itemContainer;

                            itemTemplate.Name = element.Name;
                            itemTemplate.Text = element.Text;
                            itemTemplate.Action = element.Action;
                            itemTemplate.Controller = element.Controller;
                            itemTemplate.Visible = element.Visible;
                            itemTemplate.Area = element.Area;
                            itemTemplate.RouteValues = new System.Web.Routing.RouteValueDictionary(element.RouteValues.Attributes);
                            itemTemplate.HtmlAttributes = new System.Web.Routing.RouteValueDictionary(element.HtmlAttributes.Attributes);
                            itemTemplate.ReadOnlyProperties = element.UnrecognizedProperties;

                            if (!string.IsNullOrEmpty(element.Initializer))
                            {
                                Type type = Type.GetType(element.Initializer);
                                itemTemplate.Initializer = (IMenuItemInitializer)Activator.CreateInstance(type);
                            }

                            List<IMenuItemContainer> subItems = new List<IMenuItemContainer>();
                            if (element.Items != null)
                            {
                                itemTemplate.ItemContainers = CreateItems(element.Items, subItems);
                            }
                        }
                    }
                }
            }
            return itemContainers;
        }