Пример #1
0
        // Helper method to return the nodes.
        private SiteMapNodeCollection GetNodes()
        {
            SiteMapNode node = null;
            int         startingNodeOffset = StartingNodeOffset;

            if (!String.IsNullOrEmpty(StartingNodeUrl) && StartFromCurrentNode)
            {
                throw new InvalidOperationException(SR.GetString(SR.SiteMapDataSource_StartingNodeUrlAndStartFromcurrentNode_Defined));
            }

            if (StartFromCurrentNode)
            {
                node = Provider.CurrentNode;
            }
            else if (!String.IsNullOrEmpty(StartingNodeUrl))
            {
                node = Provider.FindSiteMapNode(MakeUrlAbsolute(StartingNodeUrl));
                if (node == null)
                {
                    throw new ArgumentException(SR.GetString(SR.SiteMapPath_CannotFindUrl, StartingNodeUrl));
                }
            }
            else
            {
                node = Provider.RootNode;
            }

            if (node == null)
            {
                return(null);
            }

            if (startingNodeOffset <= 0)
            {
                if (startingNodeOffset != 0)
                {
                    // Hind neighborhood nodes based on startingNodeOffset
                    Provider.HintNeighborhoodNodes(node, Math.Abs(startingNodeOffset), 0);

                    SiteMapNode parentNode = node.ParentNode;
                    while (startingNodeOffset < 0 && parentNode != null)
                    {
                        node       = node.ParentNode;
                        parentNode = node.ParentNode;
                        startingNodeOffset++;
                    }
                }

                return(GetNodes(node));
            }

            // else if (startingNodeOffset > 0)
            SiteMapNode currentNode = Provider.GetCurrentNodeAndHintAncestorNodes(-1);

            // If the current node is not in StartingNode's subtree, return null.
            if (currentNode == null || !currentNode.IsDescendantOf(node) || currentNode.Equals(node))
            {
                return(null);
            }

            SiteMapNode leadingNode = currentNode;

            // Create a gap of n levels between the following and the leading nodes.
            for (int i = 0; i < startingNodeOffset; i++)
            {
                leadingNode = leadingNode.ParentNode;

                // If the current node is within n levels below the starting node,
                // use the current node.
                if (leadingNode == null || leadingNode.Equals(node))
                {
                    return(GetNodes(currentNode));
                }
            }

            SiteMapNode followingNode = currentNode;

            while (leadingNode != null && !leadingNode.Equals(node))
            {
                followingNode = followingNode.ParentNode;
                leadingNode   = leadingNode.ParentNode;
            }

            return(GetNodes(followingNode));
        }
Пример #2
0
    /// <summary>
    /// Replicates the logic in the SiteMapDataSource that gets the root node for the
    /// currently displayed site map.
    /// </summary>
    /// <returns>The root node used in the control site map.</returns>
    private SiteMapNode GetStartingNode()
    {
        SiteMapNode currentNode = null;

        if (!string.IsNullOrEmpty(this.StartingNodeUrl) && this.StartFromCurrentNode)
        {
            throw new InvalidOperationException("StartingNodeUrl and StartFromCurrentNode are both defined.");
        }
        if (this.StartFromCurrentNode)
        {
            currentNode = SiteMap.CurrentNode;
        }
        else if (!string.IsNullOrEmpty(this.StartingNodeUrl))
        {
            string resolvedUrl = Telerik.Web.UrlPath.ResolveUrl(this.StartingNodeUrl);
            currentNode = SiteMap.Provider.FindSiteMapNode(resolvedUrl);
            if (currentNode == null)
            {
                throw new ArgumentException("Cannot find url", "StartingNodeUrl");
            }
        }
        else
        {
            currentNode = SiteMap.RootNode;
        }
        if (currentNode == null)
        {
            return(SiteMap.RootNode);
        }

        int startingNodeOffset = this.StartingNodeOffset;

        if (startingNodeOffset <= 0)
        {
            if (startingNodeOffset != 0)
            {
                SiteMap.Provider.HintNeighborhoodNodes(currentNode, Math.Abs(startingNodeOffset), 0);
                SiteMapNode parentNode = currentNode.ParentNode;
                while ((startingNodeOffset < 0) && (parentNode != null))
                {
                    currentNode = currentNode.ParentNode;
                    parentNode  = currentNode.ParentNode;
                    startingNodeOffset++;
                }
            }
            return(currentNode);
        }
        else
        {
            SiteMapNode startingNode = currentNode;
            currentNode = SiteMap.Provider.GetCurrentNodeAndHintAncestorNodes(-1);
            if (((currentNode == null) || !currentNode.IsDescendantOf(startingNode)) || currentNode.Equals(startingNode))
            {
                return(startingNode);
            }
            SiteMapNode offsetNode = currentNode;
            for (int i = 0; i < startingNodeOffset; i++)
            {
                offsetNode = offsetNode.ParentNode;
                if ((offsetNode == null) || offsetNode.Equals(startingNode))
                {
                    return(currentNode);
                }
            }
            SiteMapNode node = currentNode;
            while ((offsetNode != null) && !offsetNode.Equals(startingNode))
            {
                node       = node.ParentNode;
                offsetNode = offsetNode.ParentNode;
            }
            return(node);
        }
    }
Пример #3
0
        private SiteMapNodeCollection GetNodes()
        {
            SiteMapNode currentNode        = null;
            int         startingNodeOffset = this.StartingNodeOffset;

            if (!string.IsNullOrEmpty(this.StartingNodeUrl) && this.StartFromCurrentNode)
            {
                throw new InvalidOperationException(System.Web.SR.GetString("SiteMapDataSource_StartingNodeUrlAndStartFromcurrentNode_Defined"));
            }
            if (this.StartFromCurrentNode)
            {
                currentNode = this.Provider.CurrentNode;
            }
            else if (!string.IsNullOrEmpty(this.StartingNodeUrl))
            {
                currentNode = this.Provider.FindSiteMapNode(this.MakeUrlAbsolute(this.StartingNodeUrl));
                if (currentNode == null)
                {
                    throw new ArgumentException(System.Web.SR.GetString("SiteMapPath_CannotFindUrl", new object[] { this.StartingNodeUrl }));
                }
            }
            else
            {
                currentNode = this.Provider.RootNode;
            }
            if (currentNode == null)
            {
                return(null);
            }
            if (startingNodeOffset <= 0)
            {
                if (startingNodeOffset != 0)
                {
                    this.Provider.HintNeighborhoodNodes(currentNode, Math.Abs(startingNodeOffset), 0);
                    SiteMapNode parentNode = currentNode.ParentNode;
                    while ((startingNodeOffset < 0) && (parentNode != null))
                    {
                        currentNode = currentNode.ParentNode;
                        parentNode  = currentNode.ParentNode;
                        startingNodeOffset++;
                    }
                }
                return(this.GetNodes(currentNode));
            }
            SiteMapNode currentNodeAndHintAncestorNodes = this.Provider.GetCurrentNodeAndHintAncestorNodes(-1);

            if (((currentNodeAndHintAncestorNodes == null) || !currentNodeAndHintAncestorNodes.IsDescendantOf(currentNode)) || currentNodeAndHintAncestorNodes.Equals(currentNode))
            {
                return(null);
            }
            SiteMapNode node4 = currentNodeAndHintAncestorNodes;

            for (int i = 0; i < startingNodeOffset; i++)
            {
                node4 = node4.ParentNode;
                if ((node4 == null) || node4.Equals(currentNode))
                {
                    return(this.GetNodes(currentNodeAndHintAncestorNodes));
                }
            }
            SiteMapNode node5 = currentNodeAndHintAncestorNodes;

            while ((node4 != null) && !node4.Equals(currentNode))
            {
                node5 = node5.ParentNode;
                node4 = node4.ParentNode;
            }
            return(this.GetNodes(node5));
        }