예제 #1
0
        private IEnumerable<MvcSiteMapNode> CopyAndSetState(IEnumerable<MvcSiteMapNode> nodes, String area, String controller, String action)
        {
            List<MvcSiteMapNode> copies = new List<MvcSiteMapNode>();
            foreach (MvcSiteMapNode node in nodes)
            {
                MvcSiteMapNode copy = new MvcSiteMapNode();
                copy.IconClass = node.IconClass;
                copy.IsMenu = node.IsMenu;

                copy.Controller = node.Controller;
                copy.Action = node.Action;
                copy.Area = node.Area;

                copy.Children = CopyAndSetState(node.Children, area, controller, action);
                copy.HasActiveChildren = copy.Children.Any(child => child.IsActive || child.HasActiveChildren);
                copy.IsActive =
                    copy.Children.Any(childNode => childNode.IsActive && !childNode.IsMenu) ||
                    (
                        String.Equals(node.Area, area, StringComparison.OrdinalIgnoreCase) &&
                        String.Equals(node.Action, action, StringComparison.OrdinalIgnoreCase) &&
                        String.Equals(node.Controller, controller, StringComparison.OrdinalIgnoreCase
                    ));

                copies.Add(copy);
            }

            return copies;
        }
        public IEnumerable <MvcSiteMapNode> GetBreadcrumb(ViewContext context)
        {
            String area       = context.RouteData.Values["area"] as String;
            String action     = context.RouteData.Values["action"] as String;
            String controller = context.RouteData.Values["controller"] as String;

            MvcSiteMapNode currentNode = NodeList.SingleOrDefault(node =>
                                                                  String.Equals(node.Area, area, StringComparison.OrdinalIgnoreCase) &&
                                                                  String.Equals(node.Action, action, StringComparison.OrdinalIgnoreCase) &&
                                                                  String.Equals(node.Controller, controller, StringComparison.OrdinalIgnoreCase));

            List <MvcSiteMapNode> breadcrumb = new List <MvcSiteMapNode>();

            while (currentNode != null)
            {
                breadcrumb.Insert(0, new MvcSiteMapNode
                {
                    IconClass = currentNode.IconClass,

                    Controller = currentNode.Controller,
                    Action     = currentNode.Action,
                    Area       = currentNode.Area
                });

                currentNode = currentNode.Parent;
            }

            return(breadcrumb);
        }
        private IEnumerable <MvcSiteMapNode> CopyAndSetState(IEnumerable <MvcSiteMapNode> nodes, String area, String controller, String action)
        {
            List <MvcSiteMapNode> copies = new List <MvcSiteMapNode>();

            foreach (MvcSiteMapNode node in nodes)
            {
                MvcSiteMapNode copy = new MvcSiteMapNode();
                copy.IconClass = node.IconClass;
                copy.IsMenu    = node.IsMenu;

                copy.Controller = node.Controller;
                copy.Action     = node.Action;
                copy.Area       = node.Area;

                copy.Children          = CopyAndSetState(node.Children, area, controller, action);
                copy.HasActiveChildren = copy.Children.Any(child => child.IsActive || child.HasActiveChildren);
                copy.IsActive          =
                    copy.Children.Any(childNode => childNode.IsActive && !childNode.IsMenu) ||
                    (
                        String.Equals(node.Area, area, StringComparison.OrdinalIgnoreCase) &&
                        String.Equals(node.Action, action, StringComparison.OrdinalIgnoreCase) &&
                        String.Equals(node.Controller, controller, StringComparison.OrdinalIgnoreCase
                                      ));

                copies.Add(copy);
            }

            return(copies);
        }
예제 #4
0
        private IEnumerable <MvcSiteMapNode> GetMenus(IEnumerable <MvcSiteMapNode> nodes, MvcSiteMapNode parent)
        {
            List <MvcSiteMapNode> menus = new List <MvcSiteMapNode>();

            foreach (MvcSiteMapNode node in nodes)
            {
                if (node.IsMenu)
                {
                    MvcSiteMapNode menuNode = new MvcSiteMapNode();
                    menuNode.Children   = GetMenus(node.Children, menuNode);
                    menuNode.Controller = node.Controller;
                    menuNode.Action     = node.Action;
                    menuNode.Area       = node.Area;

                    menuNode.IconClass = node.IconClass;
                    menuNode.IsMenu    = node.IsMenu;
                    menuNode.Parent    = parent;

                    menus.Add(menuNode);
                }
                else
                {
                    menus.AddRange(GetMenus(node.Children, parent));
                }
            }

            return(menus);
        }
        private Boolean IsAuthorizedToView(Int32?accountId, MvcSiteMapNode menu)
        {
            if (menu.Action == null)
            {
                return(true);
            }
            if (Authorization.Provider == null)
            {
                return(true);
            }

            return(Authorization.Provider.IsAuthorizedFor(accountId, menu.Area, menu.Controller, menu.Action));
        }
예제 #6
0
        private MvcSiteMapBreadcrumbNode CreateBreadcrumbNode(MvcSiteMapNode node)
        {
            MvcSiteMapBreadcrumbNode breadcrumbNode = new MvcSiteMapBreadcrumbNode();

            breadcrumbNode.Title     = ResourceProvider.GetSiteMapTitle(node.Area, node.Controller, node.Action);
            breadcrumbNode.IconClass = node.IconClass;

            breadcrumbNode.Controller = node.Controller;
            breadcrumbNode.Action     = node.Action;
            breadcrumbNode.Area       = node.Area;

            return(breadcrumbNode);
        }
예제 #7
0
        public MvcSiteMapBreadcrumb GetBreadcrumb()
        {
            MvcSiteMapBreadcrumb breadcrumb  = new MvcSiteMapBreadcrumb();
            MvcSiteMapNode       currentNode = allNodes.SingleOrDefault(node =>
                                                                        String.Compare(node.Controller, CurrentController, true) == 0 &&
                                                                        String.Compare(node.Action, CurrentAction, true) == 0 &&
                                                                        String.Compare(node.Area, CurrentArea, true) == 0);

            while (currentNode != null)
            {
                breadcrumb.Insert(0, CreateBreadcrumbNode(currentNode));
                currentNode = currentNode.Parent;
            }

            return(breadcrumb);
        }
예제 #8
0
        private MvcSiteMapMenuNode CreateAuthorizedMenu(MvcSiteMapNode menu)
        {
            MvcSiteMapMenuNode authorizedMenu = new MvcSiteMapMenuNode();

            authorizedMenu.Title     = ResourceProvider.GetSiteMapTitle(menu.Area, menu.Controller, menu.Action);
            authorizedMenu.IconClass = menu.IconClass;

            authorizedMenu.Controller = menu.Controller;
            authorizedMenu.Action     = menu.Action;
            authorizedMenu.Area       = menu.Area;

            authorizedMenu.Submenus         = GetAuthorizedMenus(menu.Children);
            authorizedMenu.IsActive         = String.Compare(menu.Area, CurrentArea, true) == 0 && String.Compare(menu.Controller, CurrentController, true) == 0;
            authorizedMenu.HasActiveSubMenu = authorizedMenu.Submenus.Any(submenu => submenu.IsActive || submenu.HasActiveSubMenu);

            return(authorizedMenu);
        }
예제 #9
0
        private IEnumerable<MvcSiteMapNode> GetNodes(XElement siteMap, MvcSiteMapNode parent)
        {
            List<MvcSiteMapNode> nodes = new List<MvcSiteMapNode>();
            foreach (XElement siteMapNode in siteMap.Elements("siteMapNode"))
            {
                MvcSiteMapNode node = new MvcSiteMapNode();

                node.IsMenu = (Boolean?)siteMapNode.Attribute("menu") == true;
                node.Controller = (String)siteMapNode.Attribute("controller");
                node.IconClass = (String)siteMapNode.Attribute("icon");
                node.Action = (String)siteMapNode.Attribute("action");
                node.Area = (String)siteMapNode.Attribute("area");
                node.Children = GetNodes(siteMapNode, node);
                node.Parent = parent;

                nodes.Add(node);
            }

            return nodes;
        }
예제 #10
0
        private IEnumerable <MvcSiteMapNode> GetNodes(XElement siteMap, MvcSiteMapNode parent)
        {
            List <MvcSiteMapNode> nodes = new List <MvcSiteMapNode>();

            foreach (XElement element in siteMap.Elements("siteMapNode"))
            {
                MvcSiteMapNode node = new MvcSiteMapNode();

                node.IsMenu     = (Boolean?)element.Attribute("menu") == true;
                node.Controller = (String)element.Attribute("controller");
                node.IconClass  = (String)element.Attribute("icon");
                node.Action     = (String)element.Attribute("action");
                node.Area       = (String)element.Attribute("area");
                node.Children   = GetNodes(element, node);
                node.Parent     = parent;

                nodes.Add(node);
            }

            return(nodes);
        }
예제 #11
0
        public IEnumerable <MvcSiteMapNode> GetBreadcrumb()
        {
            List <MvcSiteMapNode> breadcrumb  = new List <MvcSiteMapNode>();
            MvcSiteMapNode        currentNode = nodeList.SingleOrDefault(node =>
                                                                         String.Equals(node.Area, CurrentArea, StringComparison.OrdinalIgnoreCase) &&
                                                                         String.Equals(node.Action, CurrentAction, StringComparison.OrdinalIgnoreCase) &&
                                                                         String.Equals(node.Controller, CurrentController, StringComparison.OrdinalIgnoreCase));

            while (currentNode != null)
            {
                breadcrumb.Insert(0, new MvcSiteMapNode
                {
                    IconClass = currentNode.IconClass,

                    Controller = currentNode.Controller,
                    Action     = currentNode.Action,
                    Area       = currentNode.Area
                });

                currentNode = currentNode.Parent;
            }

            return(breadcrumb);
        }
예제 #12
0
 private Boolean IsEmpty(MvcSiteMapNode node)
 {
     return node.Action == null && !node.Children.Any();
 }
예제 #13
0
        private Boolean IsAuthorizedToView(String accountId, MvcSiteMapNode menu)
        {
            if (menu.Action == null) return true;
            if (Authorization.Provider == null) return true;

            return Authorization.Provider.IsAuthorizedFor(accountId, menu.Area, menu.Controller, menu.Action);
        }
예제 #14
0
 private Boolean IsEmpty(MvcSiteMapNode node)
 {
     return(node.Action == null && !node.Children.Any());
 }
예제 #15
0
 private Boolean IsEmpty(MvcSiteMapNode node)
 {
     return(node.Action == null && node.Children.Count() == 0);
 }