public object GetContentItemValue(string columnName) { if (row == null) { if (string.IsNullOrEmpty(LanguageCode)) { LanguageCode = AgilityContext.LanguageCode; } AgilityContent content = BaseCache.GetContent(ContentReferenceName, LanguageCode, AgilityContext.WebsiteName); row = content.GetItemByContentID(ContentID); } if (row != null && row.Table.Columns.Contains(columnName)) { return(row[columnName]); } return(null); }
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); }