当前位置: 首页>>代码示例>>C#>>正文


C# ISiteMap.FindSiteMapNodeFromKey方法代码示例

本文整理汇总了C#中ISiteMap.FindSiteMapNodeFromKey方法的典型用法代码示例。如果您正苦于以下问题:C# ISiteMap.FindSiteMapNodeFromKey方法的具体用法?C# ISiteMap.FindSiteMapNodeFromKey怎么用?C# ISiteMap.FindSiteMapNodeFromKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISiteMap的用法示例。


在下文中一共展示了ISiteMap.FindSiteMapNodeFromKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildHierarchy

        public IEnumerable<ISiteMapNodeToParentRelation> BuildHierarchy(ISiteMap siteMap, IEnumerable<ISiteMapNodeToParentRelation> nodes)
        {
            var sourceNodesByParent = nodes.ToLookup(n => n.ParentKey);
            var sourceNodes = new List<ISiteMapNodeToParentRelation>(nodes);
            var nodesAddedThisIteration = 0;
            do
            {
                var nodesAlreadyAdded = new HashSet<string>();
                nodesAddedThisIteration = 0;
                foreach (var node in sourceNodes.OrderBy(x => x.Node.Order).ToArray())
                {
                    if (nodesAlreadyAdded.Contains(node.Node.Key))
                    {
                        continue;
                    }

                    var parentNode = siteMap.FindSiteMapNodeFromKey(node.ParentKey);
                    if (parentNode != null)
                    {
                        this.AddAndTrackNode(siteMap, node, parentNode, sourceNodes, nodesAlreadyAdded);
                        nodesAddedThisIteration += 1;

                        // Add the rest of the tree branch below the current node
                        this.AddDescendantNodes(siteMap, node.Node, sourceNodes, sourceNodesByParent, nodesAlreadyAdded);
                    }
                }
            }
            while (nodesAddedThisIteration > 0 && sourceNodes.Count > 0);

            return sourceNodes;
        }
开发者ID:Guymestef,项目名称:MvcSiteMapProvider,代码行数:31,代码来源:SiteMapHierarchyBuilder.cs

示例2: BuildDynamicNodesFor

        /// <summary>
        /// Adds the dynamic nodes for node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="parentNode">The parent node.</param>
        public IEnumerable<ISiteMapNode> BuildDynamicNodesFor(ISiteMap siteMap, ISiteMapNode node, ISiteMapNode parentNode)
        {
            // List of dynamic nodes that have been created
            var createdDynamicNodes = new List<ISiteMapNode>();

            if (!node.HasDynamicNodeProvider)
            {
                return createdDynamicNodes;
            }

            // Build dynamic nodes
            foreach (var dynamicNode in node.GetDynamicNodeCollection())
            {
                string key = dynamicNode.Key;
                if (string.IsNullOrEmpty(key))
                {
                    key = nodeKeyGenerator.GenerateKey(
                        parentNode == null ? "" : parentNode.Key, 
                        Guid.NewGuid().ToString(), 
                        node.Url, 
                        node.Title, 
                        node.Area, 
                        node.Controller, 
                        node.Action,
                        node.HttpMethod,
                        node.Clickable);
                }

                // Create a new node
                var newNode = siteMapNodeFactory.CreateDynamic(siteMap, key, node.ResourceKey);

                // Copy the values from the original node to the new one
                node.CopyTo(newNode);

                // Copy any values that were set in the dynamic node and overwrite the new node.
                dynamicNode.SafeCopyTo(newNode);

                // If the dynamic node has a parent key set, use that as the parent. Otherwise use the parentNode.
                if (!string.IsNullOrEmpty(dynamicNode.ParentKey))
                {
                    var parent = siteMap.FindSiteMapNodeFromKey(dynamicNode.ParentKey);
                    if (parent != null)
                    {
                        siteMap.AddNode(newNode, parent);
                        createdDynamicNodes.Add(newNode);
                    }
                }
                else
                {
                    siteMap.AddNode(newNode, parentNode);
                    createdDynamicNodes.Add(newNode);
                }
            }

            // Done!
            return createdDynamicNodes;
        }
开发者ID:Guymestef,项目名称:MvcSiteMapProvider,代码行数:62,代码来源:DynamicNodeBuilder.cs

示例3: BuildSiteMap

        public ISiteMapNode BuildSiteMap(ISiteMap siteMap, ISiteMapNode rootNode)
        {
            var provider = siteMapProvider.GetProvider();

            rootNode = GetRootNode(siteMap, provider);
            // Fixes #192 root node not added to sitemap
            if (siteMap.FindSiteMapNodeFromKey(rootNode.Key) == null)
            {
                // Add the root node to the sitemap
                siteMap.AddNode(rootNode);
            }

            ProcessNodes(siteMap, rootNode, provider.RootNode);

            return rootNode;
        }
开发者ID:agrynco,项目名称:MvcSiteMapProvider,代码行数:16,代码来源:AspNetSiteMapBuilder.cs

示例4: LoadSiteMapFromXml

        protected virtual ISiteMapNode LoadSiteMapFromXml(ISiteMap siteMap, XDocument xml)
        {
            xmlNameProvider.FixXmlNamespaces(xml);

            // Get the root mvcSiteMapNode element, and map this to an MvcSiteMapNode
            var rootElement = GetRootElement(xml);
            var root = GetRootNode(siteMap, xml, rootElement);

            // Fixes #192 root node not added to sitemap
            if (siteMap.FindSiteMapNodeFromKey(root.Key) == null)
            {
                // Add the root node to the sitemap
                siteMap.AddNode(root);
            }

            // Process our XML, passing in the main root sitemap node and XML element.
            ProcessXmlNodes(siteMap, root, rootElement);

            // Done!
            return root;
        }
开发者ID:agrynco,项目名称:MvcSiteMapProvider,代码行数:21,代码来源:XmlSiteMapBuilder.cs

示例5: CreateNodesFromMvcSiteMapNodeAttributeDefinitions

        /// <summary>
        /// Creates the nodes from MVC site map node attribute definitions.
        /// </summary>
        /// <param name="definitions">The definitions.</param>
        protected virtual ISiteMapNode CreateNodesFromMvcSiteMapNodeAttributeDefinitions(ISiteMap siteMap, ISiteMapNode parentNode, IEnumerable<IMvcSiteMapNodeAttributeDefinition> definitions)
        {
            // A dictionary of nodes to process later (node, parentKey)
            var nodesToProcessLater = new Dictionary<ISiteMapNode, string>();
            var emptyParentKeyCount = definitions.Where(t => string.IsNullOrEmpty(t.SiteMapNodeAttribute.ParentKey)).Count();

            // Throw a sensible exception if the configuration has more than 1 empty parent key (#179).
            if (emptyParentKeyCount > 1)
            {
                throw new MvcSiteMapException(Resources.Messages.ReflectionSiteMapBuilderRootKeyAmbiguous);
            }

            // Find root node
            if (parentNode == null)
            {
                if (emptyParentKeyCount == 1)
                {
                    ISiteMapNode attributedRootNode = null;

                    var item = definitions.Where(t => string.IsNullOrEmpty(t.SiteMapNodeAttribute.ParentKey)).Single();

                    var actionNode = item as MvcSiteMapNodeAttributeDefinitionForAction;
                    if (actionNode != null)
                    {
                        // Create node for action
                        attributedRootNode = GetSiteMapNodeFromMvcSiteMapNodeAttribute(
                            siteMap, actionNode.SiteMapNodeAttribute, actionNode.ControllerType, actionNode.ActionMethodInfo);
                    }
                    else
                    {
                        var controllerNode = item as MvcSiteMapNodeAttributeDefinitionForController;
                        if (controllerNode != null)
                        {
                            // Create node for controller
                            attributedRootNode = GetSiteMapNodeFromMvcSiteMapNodeAttribute(
                                siteMap, controllerNode.SiteMapNodeAttribute, controllerNode.ControllerType, null);
                        }
                    }

                    if (attributedRootNode.Attributes.ContainsKey("parentKey"))
                    {
                        attributedRootNode.Attributes.Remove("parentKey");
                    }
                    parentNode = attributedRootNode;
                }
            }

            // Fixes #192 root node not added to sitemap
            if (siteMap.FindSiteMapNodeFromKey(parentNode.Key) == null)
            {
                // Add the root node to the sitemap
                siteMap.AddNode(parentNode);
            }

            // Create nodes
            foreach (var assemblyNode in definitions.Where(t => !string.IsNullOrEmpty(t.SiteMapNodeAttribute.ParentKey)))
            {
                ISiteMapNode nodeToAdd = null;

                // Create node
                var actionNode = assemblyNode as MvcSiteMapNodeAttributeDefinitionForAction;
                if (actionNode != null)
                {
                    // Create node for action
                    nodeToAdd = GetSiteMapNodeFromMvcSiteMapNodeAttribute(
                        siteMap, actionNode.SiteMapNodeAttribute, actionNode.ControllerType, actionNode.ActionMethodInfo);
                }
                else
                {
                    var controllerNode = assemblyNode as MvcSiteMapNodeAttributeDefinitionForController;
                    if (controllerNode != null)
                    {
                        // Create node for controller
                        nodeToAdd = GetSiteMapNodeFromMvcSiteMapNodeAttribute(
                            siteMap, controllerNode.SiteMapNodeAttribute, controllerNode.ControllerType, null);
                    }
                }

                // Add node
                if (nodeToAdd != null)
                {
                    if (string.IsNullOrEmpty(assemblyNode.SiteMapNodeAttribute.ParentKey))
                    {
                        throw new MvcSiteMapException(string.Format(Resources.Messages.NoParentKeyDefined, nodeToAdd.Controller, nodeToAdd.Action));
                    }

                    var parentForNode = parentNode != null ? siteMap.FindSiteMapNodeFromKey(assemblyNode.SiteMapNodeAttribute.ParentKey) : null;

                    if (parentForNode != null)
                    {
                        if (nodeToAdd.HasDynamicNodeProvider)
                        {
                            var dynamicNodesForChildNode = dynamicNodeBuilder.BuildDynamicNodesFor(siteMap, nodeToAdd, parentForNode);
                            foreach (var dynamicNode in dynamicNodesForChildNode)
                            {
                                // Verify parent/child relation
//.........这里部分代码省略.........
开发者ID:agrynco,项目名称:MvcSiteMapProvider,代码行数:101,代码来源:ReflectionSiteMapBuilder.cs


注:本文中的ISiteMap.FindSiteMapNodeFromKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。