コード例 #1
0
        protected virtual SiteMapNode CreateNodeFromElement(XElement element, int currentLevel, Dictionary<string, SiteMapNode> nodeDictionary)
        {
            var attributes = new NameValueCollection();
            foreach (var a in element.Attributes())
            {
                attributes.Add(a.Name.ToString(), a.Value);
            }

            string uri;
            try
            {
                if (element.Attribute("uri") != null)
                    uri = element.Attribute("uri").Value;
                else if (element.Attribute("pageId") != null)
                    uri = element.Attribute("pageId").Value;
                else
                    uri = "";
            }
            catch
            {
                LoggerService.Debug("exception while retrieving uri", LoggingCategory.General);
                uri = "";
            }

            NavigationNode childNode =
                new NavigationNode(this,
                    element.Attribute("id").Value, //key
                    uri,
                    element.Attribute("url") != null ? element.Attribute("url").Value : element.Attribute("id").Value, //url
                    element.Attribute("title").Value, //title
                    element.Attribute("description").Value, //description
                    null, //roles
                    attributes, //attributes
                    null, //explicitresourceKeys
                    null) { Level = currentLevel }; // implicitresourceKey

            if (element.Element("NumberOfItemsInGroup") != null)
                childNode.NumberOfItemsInGroup = Convert.ToInt32(element.Element("NumberOfItemsInGroup").Value);
            else
                childNode.NumberOfItemsInGroup = MaxItemsInGroup;

            if (element.Element("NumberOfItemsPerColumn") != null)
                childNode.NumberOfItemsInColumn = Convert.ToInt32(element.Element("NumberOfItemsPerColumn").Value);

            nodeDictionary.Add(childNode.Key, childNode);

            return childNode;
        }