/// <summary>
        /// Gets the dynamic nodes for node.
        /// </summary>
        /// <param name="node">The SiteMap node.</param>
        /// <param name="defaultParentKey">The key of the parent node.</param>
        public virtual IEnumerable <ISiteMapNodeToParentRelation> BuildDynamicNodes(ISiteMapNode node, string defaultParentKey)
        {
            var result = new List <ISiteMapNodeToParentRelation>();

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

            // Get the dynamic nodes using the request's culture context.
            // NOTE: In version 5, we need to use the invariant context and pass a reference to it
            // into the dynamic node provider. This would be a breaking change, so for now we are
            // swapping the context back to the state of the current request. This way, the end user
            // still can opt to change to invariant culture, but in the reverse situation there would
            // be no way to identify the culture of the current request without a reference to the
            // cultureContext object.
            IEnumerable <DynamicNode> dynamicNodes;

            using (var originalCultureContext = this.cultureContextFactory.Create(this.cultureContext.OriginalCulture, this.cultureContext.OriginalUICulture))
            {
                dynamicNodes = node.GetDynamicNodeCollection();
            }

            // Build dynamic nodes
            foreach (var dynamicNode in dynamicNodes)
            {
                // If the dynamic node has a parent key set, use that as the parent. Otherwise use the parentNode.
                var parentKey = !string.IsNullOrEmpty(dynamicNode.ParentKey) ? dynamicNode.ParentKey : defaultParentKey;
                var key       = dynamicNode.Key;

                if (string.IsNullOrEmpty(key))
                {
                    key = this.siteMapNodeCreator.GenerateSiteMapNodeKey(
                        parentKey,
                        Guid.NewGuid().ToString(),
                        node.Url,
                        node.Title,
                        node.Area,
                        node.Controller,
                        node.Action,
                        node.HttpMethod,
                        node.Clickable);
                }

                // Create a new node
                var nodeParentMap = this.siteMapNodeCreator.CreateDynamicSiteMapNode(key, parentKey, node.DynamicNodeProvider, node.ResourceKey);
                var newNode       = nodeParentMap.Node;

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

                result.Add(nodeParentMap);
            }
            return(result);
        }
        /// <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);
        }
        /// <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;
        }
        /// <summary>
        /// Gets the dynamic nodes for node.
        /// </summary>
        /// <param name="node">The SiteMap node.</param>
        /// <param name="defaultParentKey">The key of the parent node.</param>
        public virtual IEnumerable<ISiteMapNodeToParentRelation> BuildDynamicNodes(ISiteMapNode node, string defaultParentKey)
        {
            var result = new List<ISiteMapNodeToParentRelation>();

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

            // Get the dynamic nodes using the request's culture context.
            // NOTE: In version 5, we need to use the invariant context and pass a reference to it
            // into the dynamic node provider. This would be a breaking change, so for now we are 
            // swapping the context back to the state of the current request. This way, the end user
            // still can opt to change to invariant culture, but in the reverse situation there would 
            // be no way to identify the culture of the current request without a reference to the 
            // cultureContext object.
            IEnumerable<DynamicNode> dynamicNodes;
            using (var originalCultureContext = this.cultureContextFactory.Create(this.cultureContext.OriginalCulture, this.cultureContext.OriginalUICulture))
            {
                dynamicNodes = node.GetDynamicNodeCollection();
            }

            // Build dynamic nodes
            foreach (var dynamicNode in dynamicNodes)
            {
                // If the dynamic node has a parent key set, use that as the parent. Otherwise use the parentNode.
                var parentKey = !string.IsNullOrEmpty(dynamicNode.ParentKey) ? dynamicNode.ParentKey : defaultParentKey;
                var key = dynamicNode.Key;

                if (string.IsNullOrEmpty(key))
                {
                    key = this.siteMapNodeCreator.GenerateSiteMapNodeKey(
                        parentKey,
                        Guid.NewGuid().ToString(),
                        node.Url,
                        node.Title,
                        node.Area,
                        node.Controller,
                        node.Action,
                        node.HttpMethod,
                        node.Clickable);
                }

                // Create a new node
                var nodeParentMap = this.siteMapNodeCreator.CreateDynamicSiteMapNode(key, parentKey, node.DynamicNodeProvider, node.ResourceKey);
                var newNode = nodeParentMap.Node;

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

                result.Add(nodeParentMap);
            }
            return result;
        }
        /// <summary>
        /// Gets the dynamic nodes for node.
        /// </summary>
        /// <param name="siteMap">The site map.</param>
        /// <param name="node">The node.</param>
        /// <param name="parentKey">The key of the parent node.</param>
        public virtual IEnumerable<ISiteMapNodeToParentRelation> BuildDynamicNodes(ISiteMapNode node, string defaultParentKey)
        {
            var result = new List<ISiteMapNodeToParentRelation>();

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

            // Build dynamic nodes
            foreach (var dynamicNode in node.GetDynamicNodeCollection())
            {
                // If the dynamic node has a parent key set, use that as the parent. Otherwise use the parentNode.
                var parentKey = !String.IsNullOrEmpty(dynamicNode.ParentKey) ? dynamicNode.ParentKey : defaultParentKey;
                var key = dynamicNode.Key;

                if (string.IsNullOrEmpty(key))
                {
                    key = this.siteMapNodeCreator.GenerateSiteMapNodeKey(
                        parentKey,
                        Guid.NewGuid().ToString(),
                        node.Url,
                        node.Title,
                        node.Area,
                        node.Controller,
                        node.Action,
                        node.HttpMethod,
                        node.Clickable);
                }

                // Create a new node
                var nodeParentMap = this.siteMapNodeCreator.CreateDynamicSiteMapNode(key, parentKey, node.DynamicNodeProvider, node.ResourceKey);
                var newNode = nodeParentMap.Node;

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

                result.Add(nodeParentMap);
            }
            return result;
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the dynamic nodes for node.
        /// </summary>
        /// <param name="siteMap">The site map.</param>
        /// <param name="node">The node.</param>
        /// <param name="parentKey">The key of the parent node.</param>
        public virtual IEnumerable <ISiteMapNodeToParentRelation> BuildDynamicNodes(ISiteMapNode node, string defaultParentKey)
        {
            var result = new List <ISiteMapNodeToParentRelation>();

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

            // Build dynamic nodes
            foreach (var dynamicNode in node.GetDynamicNodeCollection())
            {
                // If the dynamic node has a parent key set, use that as the parent. Otherwise use the parentNode.
                var parentKey = !String.IsNullOrEmpty(dynamicNode.ParentKey) ? dynamicNode.ParentKey : defaultParentKey;
                var key       = dynamicNode.Key;

                if (string.IsNullOrEmpty(key))
                {
                    key = this.siteMapNodeCreator.GenerateSiteMapNodeKey(
                        parentKey,
                        Guid.NewGuid().ToString(),
                        node.Url,
                        node.Title,
                        node.Area,
                        node.Controller,
                        node.Action,
                        node.HttpMethod,
                        node.Clickable);
                }

                // Create a new node
                var nodeParentMap = this.siteMapNodeCreator.CreateDynamicSiteMapNode(key, parentKey, node.DynamicNodeProvider, node.ResourceKey);
                var newNode       = nodeParentMap.Node;

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

                result.Add(nodeParentMap);
            }
            return(result);
        }