Example #1
0
        /// <summary>
        /// Finds a dynamic sitemap node.
        /// </summary>
        /// <param name="parentNode"></param>
        /// <param name="contentID"></param>
        /// <returns></returns>
        public AgilitySiteMapNode FindDynamicNodeByContentID(AgilitySiteMapNode parentNode, int contentID)
        {
            foreach (var childNode in parentNode.ChildNodes)
            {
                if (childNode is AgilityDynamicSiteMapNode dynNode && dynNode.ContentID == contentID)
                {
                    return(dynNode);
                }

                var testNode = FindDynamicNodeByContentID(childNode, contentID);
                if (testNode != null)
                {
                    return(testNode);
                }
            }
            return(null);
        }
Example #2
0
        /// <summary>
        /// Recursively add nodes to the SiteMap from the XML File
        /// </summary>
        /// <param name="parentNode"></param>
        /// <param name="elem"></param>
        private void AddChildNodes(AgilitySiteMapNode parentNode, XmlElement elem)
        {
            var childNodes = elem.SelectNodes("SiteNode");

            if (childNodes == null)
            {
                return;
            }

            foreach (XmlElement childElem in childNodes)
            {
                var childNode           = ConvertXmlElementToSiteMapNode(childElem, parentNode);
                var agilitySiteMapNodes = AddNode(childNode, parentNode);

                foreach (var agilitySiteMapNode in agilitySiteMapNodes)
                {
                    AddChildNodes(agilitySiteMapNode, childElem);
                }
            }
        }
Example #3
0
        protected virtual AgilitySiteMapNode FindAgilityNodeByUrl(AgilitySiteMapNode parentNode, string rawUrl)
        {
            rawUrl = rawUrl.ToLower();

            var appPath = "/";

            if (appPath != "/" && rawUrl.StartsWith(appPath))
            {
                rawUrl = rawUrl.Replace(appPath, "~");
            }
            else if (appPath == "/" && rawUrl.StartsWith("/"))
            {
                rawUrl = "~" + rawUrl;
            }

            if (rawUrl.EndsWith("/"))
            {
                rawUrl = rawUrl.TrimEnd('/');
            }

            if (rawUrl.EndsWith(".aspx", StringComparison.CurrentCultureIgnoreCase))
            {
                rawUrl = rawUrl.Substring(0, rawUrl.LastIndexOf(".aspx", StringComparison.CurrentCultureIgnoreCase));
            }

            foreach (var childNode in parentNode.ChildNodes)
            {
                if (childNode.Url.ToLower() == rawUrl)
                {
                    return(childNode);
                }

                var testNode = FindAgilityNodeByUrl(childNode, rawUrl);
                if (testNode != null)
                {
                    return(testNode);
                }
            }

            return(null);
        }
Example #4
0
        public List <AgilitySiteMapNode> GetChildNodes(AgilitySiteMapNode node)
        {
            AgilitySiteMapNode anode = node;


            if (anode == null)
            {
                return(new List <AgilitySiteMapNode>());
            }

            var col = new List <AgilitySiteMapNode>();

            foreach (var agilitySiteMapNode in anode.ChildNodes)
            {
                //check for dynamic pages...
                var childNode = agilitySiteMapNode;

                if (childNode == null)
                {
                    col.Add(agilitySiteMapNode);
                    continue;
                }

                var dynamicPageContentReferenceName = childNode.DynamicPageContentReferenceName;
                var dynamicPageParentFieldName      = childNode.DynamicPageParentFieldName;

                if (!string.IsNullOrEmpty(dynamicPageContentReferenceName) ||
                    !string.IsNullOrEmpty(dynamicPageParentFieldName))
                {
                    col = GetDynamicChildNodes(childNode, anode, col);
                }
                else
                {
                    col.Add(childNode);
                }
            }


            return(col);
        }
Example #5
0
        protected virtual AgilitySiteMapNode FindAgilityNodeByKey(AgilitySiteMapNode parentNode, string key)
        {
            if (parentNode.Key == key)
            {
                return(parentNode);
            }

            foreach (var node in parentNode.ChildNodes)
            {
                if (node.Key == key)
                {
                    return(node);
                }
                var foundNode = FindAgilityNodeByKey(node, key);
                if (foundNode != null)
                {
                    return(foundNode);
                }
            }

            return(null);
        }
Example #6
0
        protected virtual AgilitySiteMapNode FindAgilityNodeByPageID(AgilitySiteMapNode parentNode, int pageID)
        {
            if (parentNode.PageItemID == pageID)
            {
                return(parentNode);
            }

            foreach (var node in parentNode.ChildNodes)
            {
                if (node.PageItemID == pageID)
                {
                    return(node);
                }
                var foundNode = FindAgilityNodeByPageID(node, pageID);
                if (foundNode != null)
                {
                    return(foundNode);
                }
            }

            return(null);
        }
Example #7
0
        protected List <AgilitySiteMapNode> AddNode(AgilitySiteMapNode node, AgilitySiteMapNode parentNode)
        {
            if (node == null)
            {
                return(new List <AgilitySiteMapNode>());
            }

            var pnode = parentNode;

            if (pnode == null)
            {
                return(new List <AgilitySiteMapNode>());
            }

            node.ParentNode = pnode;

            var dynamicPageContentReferenceName = node.DynamicPageContentReferenceName;
            var dynamicPageParentFieldName      = node.DynamicPageParentFieldName;

            if (!string.IsNullOrEmpty(dynamicPageContentReferenceName) ||
                !string.IsNullOrEmpty(dynamicPageParentFieldName))
            {
                //if this node is a dynamic page, expand it
                var col = new List <AgilitySiteMapNode>();
                col = GetDynamicChildNodes(node, parentNode, col);
                //take the static page of the node out of the sitemap
                node.ParentNode = null;
                pnode.ChildNodes.AddRange(col);
                return(col);
            }

            //it's a regular one...
            pnode.ChildNodes.Add(node);
            return(new List <AgilitySiteMapNode> {
                node
            });
        }
Example #8
0
        private AgilitySiteMapNode ConvertXmlElementToSiteMapNode(XmlElement elem, AgilitySiteMapNode parentNode)
        {
            //check the release/pull date first
            if (AgilityContext.CurrentMode == Mode.Live)
            {
                var dtViewingDate = DateTime.Now;
                if (AgilityContext.IsPreview && AgilityContext.PreviewDateTime != DateTime.MinValue)
                {
                    dtViewingDate = AgilityContext.PreviewDateTime;
                }

                //filter on release/pull date
                var releaseDateStr = elem.GetAttribute("releaseDate");
                var pullDateStr    = elem.GetAttribute("pullDate");

                if (DateTime.TryParse(releaseDateStr, out var releaseDate) && releaseDate != DateTime.MinValue)
                {
                    if (releaseDate != DateTime.MinValue && releaseDate > dtViewingDate)
                    {
                        //don't return the object until it is released
                        return(null);
                    }
                }

                if (DateTime.TryParse(pullDateStr, out var pullDate) && pullDate != DateTime.MinValue)
                {
                    if (pullDate <= dtViewingDate)
                    {
                        //don't return the page object if it is pulled
                        return(null);
                    }
                }
            }


            //do the conversion
            var url = elem.GetAttribute("NavigateURL");

            if (url == string.Empty)
            {
                url = "javascript:;";
            }
            else if (parentNode != null && parentNode.Url != "javascript:;")
            {
                var partialUrl = url.Substring(url.LastIndexOf('/'));
                url = parentNode.Url + partialUrl;
            }

            var id = elem.GetAttribute("picID").ToLower();

            int.TryParse(id, out var picID);

            var node = new AgilitySiteMapNode(id, url, elem.GetAttribute("Text"))
            {
                PageItemID = picID
            };

            foreach (XmlAttribute att in elem.Attributes)
            {
                var attributeName = att.Name.ToLowerInvariant();
                switch (attributeName)
                {
                case "pagepath":
                    node.PagePath = att.Value;
                    break;

                case "target":
                    node.Target = att.Value;
                    break;

                case "menuvisible":
                    if (bool.TryParse(att.Value, out var bv))
                    {
                        node.MenuVisible = bv;
                    }
                    break;

                case "sitemapvisible":
                    if (bool.TryParse(att.Value, out var sv))
                    {
                        node.SitemapVisible = sv;
                    }
                    break;

                case "dynamicpagecontentreferencename":
                    node.DynamicPageContentReferenceName = att.Value;
                    break;

                case "dynamicpageparentfieldname":
                    node.DynamicPageParentFieldName = att.Value;
                    break;
                }
            }

            if (string.IsNullOrEmpty(node.PagePath))
            {
                node.PagePath = elem.GetAttribute("FolderPath");
            }

            return(node);
        }
Example #9
0
        public AgilitySiteMapNode GetParentNode(AgilitySiteMapNode node)
        {
            var anode = node;

            return(anode?.ParentNode);
        }
Example #10
0
        private List <AgilitySiteMapNode> GetDynamicChildNodes(AgilitySiteMapNode anode, AgilitySiteMapNode parentNode, List <AgilitySiteMapNode> collection)
        {
            string dynamicPageContentReferenceName = anode.DynamicPageContentReferenceName;
            string dynamicPageParentFieldName      = anode.DynamicPageParentFieldName;

            if (string.IsNullOrEmpty(dynamicPageContentReferenceName) && string.IsNullOrEmpty(dynamicPageParentFieldName))
            {
                return(collection);
            }


            //the child pages are dynamic pages...
            AgilityPage page            = anode.AgilityPage;
            int         parentContentID = 0;

            if (page != null)
            {
                string contentReferenceName = dynamicPageContentReferenceName;

                if (string.IsNullOrEmpty(contentReferenceName))
                {
                    AgilityDynamicSiteMapNode dpNode = anode.ParentNode as AgilityDynamicSiteMapNode;

                    if (dpNode == null)
                    {
                        AgilitySiteMapNode pnode = parentNode;

                        while (pnode != null)
                        {
                            dpNode = pnode.ParentNode as AgilityDynamicSiteMapNode;
                            if (dpNode != null)
                            {
                                break;
                            }
                            pnode = pnode.ParentNode;
                        }
                    }

                    if (!string.IsNullOrEmpty(dynamicPageParentFieldName) && dpNode != null && !string.IsNullOrEmpty(dpNode.ReferenceName))
                    {
                        //get the content reference name from the parent page...
                        AgilityContent parentContent = BaseCache.GetContent(dpNode.ReferenceName, AgilityContext.LanguageCode, AgilityContext.WebsiteName);
                        if (parentContent != null &&
                            parentContent.DataSet != null &&
                            parentContent.DataSet.Tables["ContentItems"] != null &&
                            parentContent.DataSet.Tables["ContentItems"].Columns.Contains(dynamicPageParentFieldName))
                        {
                            DataRow row = parentContent.GetItemByContentID(dpNode.ContentID);

                            if (row != null)
                            {
                                //the contentReferenceName is stored in the field value...
                                contentReferenceName = row[dynamicPageParentFieldName] as string;
                            }
                        }
                    }
                }
                else if (!string.IsNullOrEmpty(dynamicPageParentFieldName))
                {
                    //filter the dynamic page list by the parent field...
                    AgilityDynamicSiteMapNode dpNode = anode.ParentNode as AgilityDynamicSiteMapNode;

                    if (dpNode == null)
                    {
                        AgilitySiteMapNode pnode = parentNode;

                        while (pnode != null)
                        {
                            dpNode = pnode.ParentNode as AgilityDynamicSiteMapNode;
                            if (dpNode != null)
                            {
                                break;
                            }
                            pnode = pnode.ParentNode;
                        }
                    }

                    parentContentID = -1;
                    if (!string.IsNullOrEmpty(dynamicPageParentFieldName) && dpNode != null && !string.IsNullOrEmpty(dpNode.ReferenceName))
                    {
                        parentContentID = dpNode.ContentID;
                    }
                }


                if (!string.IsNullOrEmpty(contentReferenceName))
                {
                    //add this page and reference name to the page/dynamic content index
                    BaseCache.UpdateDynamicPageIndex(page.ID, contentReferenceName);

                    //get the content first
                    DataView dv = Data.GetContentView(contentReferenceName);

                    //get the dynamic page formula index
                    Dictionary <string, DynamicPageFormulaItem> dpIndex = BaseCache.GetDynamicPageFormulaIndex(page.ID, contentReferenceName, AgilityContext.LanguageCode, page.ServerPage, true);

                    if (dpIndex != null && dv != null)
                    {
                        //make an ID based index
                        Dictionary <int, DynamicPageFormulaItem> idIndex = new Dictionary <int, DynamicPageFormulaItem>();


                        foreach (var item in dpIndex.Values)
                        {
                            idIndex[item.ContentID] = item;
                        }


                        //loop all of the dynamic pages....
                        foreach (DataRowView dvr in dv)
                        {
                            DynamicPageFormulaItem item = null;

                            int contentID = -1;
                            if (!int.TryParse($"{dvr["ContentID"]}", out contentID))
                            {
                                contentID = -1;
                            }

                            if (!idIndex.TryGetValue(contentID, out item))
                            {
                                continue;
                            }

                            if (parentContentID != 0)
                            {
                                //do a lookup to ensure the parent id condition is met if necessary

                                object testParentContentIDObj = item.GetContentItemValue(dynamicPageParentFieldName);
                                if (testParentContentIDObj != null)
                                {
                                    int    testParentContentID    = -1;
                                    string testParentContentIDStr = string.Format("{0}", testParentContentIDObj);

                                    if (int.TryParse(testParentContentIDStr, out testParentContentID))
                                    {
                                        //if the value is an int, test for equality...
                                        if (parentContentID != testParentContentID)
                                        {
                                            continue;
                                        }
                                    }
                                    else
                                    {
                                        //value is NOT an int, test for "in" '[id],' or ',[id],' or ',[id]'
                                        if (!testParentContentIDStr.StartsWith(string.Format("{0},", parentContentID)) &&
                                            !testParentContentIDStr.EndsWith(string.Format(",{0}", parentContentID)) &&
                                            !testParentContentIDStr.Contains(string.Format(",{0},", parentContentID)))
                                        {
                                            continue;
                                        }
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            AgilityDynamicSiteMapNode thisDNode = AgilityDynamicSiteMapNode.GetDynamicNode(anode, item, page);

                            collection.Add(thisDNode);
                        }
                    }
                }
            }

            return(collection);
        }
Example #11
0
        protected virtual AgilitySiteMapNode GenerateAgilitySitemap()
        {
            // Since the SiteMap class is static, make sure that it is
            // not modified while the site map is built.

            AgilitySiteMapNode rootNode = null;

            WebTrace.WriteInfoLine(
                $"Building Sitemap: {AgilityContext.CurrentMode}, {AgilityContext.LanguageCode}, {AgilityContext.WebsiteName}, {AgilityContext.CurrentChannel.ReferenceName}");

            // Start with a clean slate
            _tmpAddedNodes.Clear();

            if (menuXml != null)
            {
                //THE ROOT NODE
                rootNode = new AgilitySiteMapNode(string.Empty, string.Empty, string.Empty)
                {
                    ParentNode = null
                };
            }
            else
            {
                return(null);
            }

            if (menuXml.DocumentElement == null)
            {
                return(null);
            }

            //get the xml element that represents this channel

            var channelElem = (menuXml.DocumentElement.SelectSingleNode(
                                   $"//ChannelNode[@channelID='{AgilityContext.CurrentChannel.ID}']")
                               ?? menuXml.DocumentElement.SelectSingleNode("ChannelNode"))
                              ?? menuXml.DocumentElement;


            var childNodes = channelElem.SelectNodes("SiteNode");

            if (childNodes == null)
            {
                return(rootNode);
            }

            foreach (XmlElement elem in childNodes)
            {
                var childNode = ConvertXmlElementToSiteMapNode(elem, null);
                if (childNode == null)
                {
                    continue;
                }

                //if the child node wasn't excluded via timed release
                var agilitySiteMapNodes = AddNode(childNode, rootNode);

                foreach (var agilitySiteMapNode in agilitySiteMapNodes)
                {
                    //add it's children
                    AddChildNodes(agilitySiteMapNode, elem);
                }
            }

            return(rootNode);
        }