public void Node_Null_Roles_equals()
        {
            SiteMapNode node  = new SiteMapNode(new DummyProvider(), "", "", "", null, null, null, null, null);
            SiteMapNode node1 = new SiteMapNode(new DummyProvider(), "", "", "", null, null, null, null, null);
            SiteMapNode node2 = new SiteMapNode(new DummyProvider(), "", "", "", null, new int[] { }, null, null, null);

            Assert.IsTrue(node.Equals(node1));
            Assert.IsTrue(node.Equals(node2));
        }
        public void Node_equals()
        {
            SiteMapNode node  = new SiteMapNode(new DummyProvider(), "Node", "1", "", null, null, null, null, null);
            SiteMapNode node1 = new SiteMapNode(new DummyProvider(), "Node", "1", "", null, null, null, null, null);
            SiteMapNode node2 = new SiteMapNode(new DummyProvider(), "Node", "2", "", null, null, new NameValueCollection(), null, null);

            Assert.IsTrue(node.Equals(node1), "both nodes have attrib=null");
            Assert.IsFalse(node.Equals(node2), "one node has attrib=null");
        }
        public void Node_Null_Attrib_equals()
        {
            // Note: dot.net implementation dosn't compare attributes
            SiteMapNode node  = new SiteMapNode(new DummyProvider(), "", "", "", null, null, null, null, null);
            SiteMapNode node1 = new SiteMapNode(new DummyProvider(), "", "", "", null, null, null, null, null);
            SiteMapNode node2 = new SiteMapNode(new DummyProvider(), "", "", "", null, null, new NameValueCollection(), null, null);

            Assert.IsTrue(node.Equals(node1), "both nodes have attrib=null");
            Assert.IsTrue(node.Equals(node2), "one node has attrib=null");
        }
Example #4
0
    protected void rptMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            SiteMapNode nodeInRepeater = e.Item.DataItem as SiteMapNode;

            if (currentNode != null && nodeInRepeater != null)
            {
                bool selectNode = false;

                if (currentNode.Equals(nodeInRepeater))
                {
                    selectNode = true;
                }
                else if (currentNode.ParentNode != null && currentNode.ParentNode.Equals(nodeInRepeater))
                {
                    selectNode = true;
                }

                if (selectNode)
                {
                    HtmlGenericControl li = e.Item.FindControl("liNode") as HtmlGenericControl;
                    if (li != null)
                    {
                        li.Attributes["class"] = "highlight";
                    }
                }
            }
        }
    }
Example #5
0
        private static void AddMenuItem(HtmlHelper helper, StringBuilder menuList, SiteMapNode rootNode, SiteMapNode node)
        {
            if (SiteMap.CurrentNode != null)
            {
                if (SiteMap.CurrentNode.Equals(node))
                {
                    menuList.Append("<li class=\"current\">");
                }
                else if (SiteMap.CurrentNode.IsDescendantOf(node) && !node.Equals(rootNode))
                {
                    menuList.Append("<li class=\"current\">");
                }
                else
                {
                    menuList.Append("<li>");
                }
            }
            else
            {
                menuList.Append("<li>");
            }


            string title = node.Title;

            //When printing second level menu, use the description for an alternative label (if provided)
            if (!SiteMap.RootNode.Equals(rootNode) && node.Description != "")
            {
                title = node.Description;
            }

            menuList.AppendFormat("<a href=\"{0}\">{1}</a>", node.Url, helper.Encode(title));
            menuList.AppendLine("</li>");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SiteMapNodeModel"/> class.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="sourceMetadata">The source metadata provided by the HtmlHelper.</param>
        /// <param name="maxDepth">The max depth.</param>
        /// <param name="drillDownToCurrent">Should the model exceed the maxDepth to reach the current node</param>
        /// <param name="startingNodeInChildLevel">Renders startingNode in child level if set to <c>true</c>.</param>
        public SiteMapNodeModel(SiteMap siteMap, SiteMapNode node, IDictionary <string, object> sourceMetadata, int maxDepth, bool drillDownToCurrent, bool startingNodeInChildLevel, bool visibilityAffectsDescendants)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }
            if (sourceMetadata == null)
            {
                throw new ArgumentNullException(nameof(sourceMetadata));
            }
            if (maxDepth < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxDepth));
            }

            this.siteMap  = siteMap;
            this.node     = node;
            this.maxDepth = maxDepth;
            this.startingNodeInChildLevel = startingNodeInChildLevel;
            this.drillDownToCurrent       = drillDownToCurrent;
            this.SourceMetadata           = sourceMetadata;

            Key         = node.Key;
            Area        = node.Area;
            Controller  = node.Controller;
            Action      = node.Action;
            Title       = node.Title;
            Description = node.Description;
            TargetFrame = node.TargetFrame;
            ImageUrl    = node.ImageUrl;
            Url         = node.Url;
            //CanonicalUrl = node.CanonicalUrl;
            //MetaRobotsContent = node.GetMetaRobotsContentString();
            IsCurrentNode = (node.Equals(siteMap.CurrentNode));
            //IsInCurrentPath = node.IsInCurrentPath();
            IsRootNode  = (node.Equals(siteMap.RootNode));
            IsClickable = node.Clickable;
            VisibilityAffectsDescendants = visibilityAffectsDescendants;
            //RouteValues = node.RouteValues;
            Attributes = node.Attributes;
            Order      = node.Order;
        }
 /// <summary>
 /// Test if the maximal node level has not been reached
 /// </summary>
 /// <param name="maxDepth">The normal max depth.</param>
 /// <param name="node">The starting node</param>
 /// <param name="drillDownToCurrent">Should the model exceed the maxDepth to reach the current node</param>
 /// <returns></returns>
 private bool ReachedMaximalNodelevel(int maxDepth, SiteMapNode node, bool drillDownToCurrent)
 {
     if (maxDepth > 0)
     {
         return(true);
     }
     if (!drillDownToCurrent)
     {
         return(false);
     }
     //if (node.IsInCurrentPath())
     //    return true;
     if (node.Equals(siteMap.RootNode))
     {
         return(true);
     }
     //foreach (SiteMapNode sibling in node.ParentNode.ChildNodes)
     //{
     //    if (sibling.IsInCurrentPath())
     //        return true;
     //}
     return(false);
 }
Example #8
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);
        }
    }
Example #9
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));
        }
Example #10
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));
        }