public FilterWrapper(Guid pageId, SitemapScope associationScope, int tableVersion, IEnumerable <Guid> innerEnumerator) { _pageId = pageId; _associationScope = associationScope; _tableVersion = tableVersion; _innerEnumerator = innerEnumerator; }
/// <summary> /// Returns portions of the sitemap in acordance with the specified scope. Sitemap elements are hierarchically /// ordered and are marked with 'isopen' and 'iscurrent' attributes when open/selected relative to the supplied pageId. /// </summary> /// <param name="associationScope">The scope of pages to return. This is relative to the specified pageId.</param> /// <param name="pageId">The C1 Page ID to use when defining the scope. This must be a valid page id.</param> /// <returns></returns> public static IEnumerable<XElement> GetSitemapByScope(SitemapScope associationScope, Guid pageId) { List<XElement> pageElements = GetSitemapByScopeUnannotated(associationScope, pageId).ToList(); AnnotatePagesWithOpenAndCurrent(pageId, pageElements); return pageElements; }
public override object Execute(ParameterList parameters, FunctionContextContainer context) { SitemapScope SitemapScope; if (parameters.TryGetParameter <SitemapScope>("SitemapScope", out SitemapScope) == false) { SitemapScope = SitemapScope.Current; } Guid pageId = Guid.Empty; switch (SitemapScope) { case SitemapScope.Current: pageId = PageRenderer.CurrentPageId; break; case SitemapScope.Parent: case SitemapScope.Level1: case SitemapScope.Level2: case SitemapScope.Level3: case SitemapScope.Level4: IEnumerable <Guid> pageIds = PageStructureInfo.GetAssociatedPageIds(PageRenderer.CurrentPageId, SitemapScope); pageId = pageIds.FirstOrDefault(); break; default: throw new NotImplementedException("Unhandled SitemapScope type: " + SitemapScope.ToString()); } return(pageId); }
/// <summary> /// Return the Page Id's that is with the <see cref="SitemapScope"/> of this page- /// </summary> /// <param name="scope">The scope.</param> /// <returns></returns> public IEnumerable <Guid> GetPageIds(SitemapScope scope) { if (scope < SitemapScope.Current || scope > SitemapScope.SiblingsAndSelf) { throw new ArgumentOutOfRangeException("scope"); } return(PageStructureInfo.GetAssociatedPageIds(_page.Id, scope)); }
/// <exclude /> public static IEnumerable <Guid> GetAssociatedPageIds(Guid pageId, SitemapScope associationScope, IEnumerable <XElement> sitemaps) { switch (associationScope) { case SitemapScope.Current: yield return(pageId); break; case SitemapScope.All: #pragma warning disable 618 foreach (Guid id in GetIdToUrlLookup().Keys) #pragma warning restore 618 { yield return(id); } break; case SitemapScope.Descendants: case SitemapScope.DescendantsAndCurrent: case SitemapScope.Children: case SitemapScope.Siblings: case SitemapScope.Ancestors: case SitemapScope.AncestorsAndCurrent: case SitemapScope.Parent: case SitemapScope.Level1: case SitemapScope.Level2: case SitemapScope.Level3: case SitemapScope.Level4: case SitemapScope.Level1AndDescendants: case SitemapScope.Level2AndDescendants: case SitemapScope.Level3AndDescendants: case SitemapScope.Level4AndDescendants: case SitemapScope.Level1AndSiblings: case SitemapScope.Level2AndSiblings: case SitemapScope.Level3AndSiblings: case SitemapScope.Level4AndSiblings: string pageIdString = pageId.ToString(); XAttribute idMatchAttrib = sitemaps.DescendantsAndSelf().Attributes(AttributeNames.Id).FirstOrDefault(id => id.Value == pageIdString); if (idMatchAttrib != null) { XElement currentPageElement = idMatchAttrib.Parent; IEnumerable <XElement> scopeElements = GetPageElementsByScope(associationScope, currentPageElement); foreach (XElement pageElement in scopeElements) { yield return(new Guid(pageElement.Attribute(AttributeNames.Id).Value)); } } break; default: throw new NotImplementedException("Unhandled SitemapScope type: " + associationScope); } }
internal static IEnumerable GetParameters(string parameters) { Match match = Regex.Match(parameters, $"{Constants.PageIdParamName}:\"(.+?)\";{Constants.TypeNameParamName}:\"(.+?)\";{Constants.SitemapScopeIdParamName}:\"([0-9]+)\""); if (!match.Success) { throw new ArgumentException(string.Format(Resources.default_text.FilteredSelectorWidgetProcManEx1, parameters)); } Type type = TypeManager.GetType(match.Groups[2].Value); Guid pageId = new Guid(match.Groups[1].Value.ToString()); SitemapScope sitemapScope = (SitemapScope)Enum.Parse(typeof(SitemapScope), match.Groups[3].Value.ToString()); return(GetOptionsForDefault(type, pageId, sitemapScope).Select(x => new { x.Key, Label = x.Value })); }
/// <summary> /// Returns <see cref="PageNode"/> elements that is with the <see cref="SitemapScope"/> of this page- /// </summary> /// <param name="scope">The scope.</param> /// <returns></returns> public IEnumerable <PageNode> GetPageNodes(SitemapScope scope) { if (scope < SitemapScope.Current || scope > SitemapScope.SiblingsAndSelf) { throw new ArgumentOutOfRangeException("scope"); } foreach (Guid pageId in GetPageIds(scope)) { var page = PageManager.GetPageById(pageId); if (page != null) { yield return(new PageNode(page, _sitemapNavigator)); } } }
public override object Execute(ParameterList parameters, FunctionContextContainer context) { SitemapScope SitemapScope = parameters.GetParameter <SitemapScope>("SitemapScope"); DataReference <IPage> pageReference = parameters.GetParameter <DataReference <IPage> >("SourcePage"); Guid pageId; if (pageReference != null && pageReference.IsSet) { pageId = (Guid)pageReference.KeyValue; } else { pageId = PageRenderer.CurrentPageId; } return(PageStructureInfo.GetSitemapByScope(SitemapScope, pageId)); }
private static string BuildCacheKey(ParameterList parameters) { string cacheKey = parameters.GetParameter <string>("ObjectCacheId"); bool languageSpecific = parameters.GetParameter <bool>("LanguageSpecific"); if (languageSpecific) { cacheKey = $"{cacheKey}:{Thread.CurrentThread.CurrentCulture}"; } SitemapScope SitemapScope = parameters.GetParameter <SitemapScope>("SitemapScope"); if (SitemapScope != SitemapScope.All) { Guid associatedPageId = PageStructureInfo.GetAssociatedPageIds(PageRenderer.CurrentPageId, SitemapScope).FirstOrDefault(); associatedPageId = (associatedPageId == Guid.Empty ? PageRenderer.CurrentPageId : associatedPageId); cacheKey = $"{cacheKey}:{associatedPageId}"; } return(cacheKey); }
/// <exclude /> public static IEnumerable<Guid> GetAssociatedPageIds(Guid pageId, SitemapScope associationScope) { switch (associationScope) { case SitemapScope.Current: return new[] {pageId}; case SitemapScope.All: return DataFacade.GetData<IPage>().Select(p => p.Id).ToList(); case SitemapScope.Descendants: return GetDescendants(pageId); case SitemapScope.DescendantsAndCurrent: return GetDescendantsAndSelf(pageId); case SitemapScope.Children: return PageManager.GetChildrenIDs(pageId); case SitemapScope.Siblings: Guid parentId = PageManager.GetParentId(pageId); return PageManager.GetChildrenIDs(parentId).Where(i => i != pageId); case SitemapScope.SiblingsAndSelf: parentId = PageManager.GetParentId(pageId); return PageManager.GetChildrenIDs(parentId); case SitemapScope.Ancestors: return GetAncestors(pageId, false); case SitemapScope.AncestorsAndCurrent: return GetAncestors(pageId, true); case SitemapScope.Parent: parentId = PageManager.GetParentId(pageId); return parentId != Guid.Empty ? new[] {parentId} : new Guid[0]; case SitemapScope.Level1: case SitemapScope.Level2: case SitemapScope.Level3: case SitemapScope.Level4: case SitemapScope.Level1AndDescendants: case SitemapScope.Level2AndDescendants: case SitemapScope.Level3AndDescendants: case SitemapScope.Level4AndDescendants: case SitemapScope.Level1AndSiblings: case SitemapScope.Level2AndSiblings: case SitemapScope.Level3AndSiblings: case SitemapScope.Level4AndSiblings: int level = int.Parse(associationScope.ToString().Substring(5, 1)); var ancestors = GetAncestors(pageId, true); ancestors.Reverse(); bool andSiblings = associationScope.ToString().EndsWith("AndSiblings"); if (andSiblings) { if (ancestors.Count < level - 1) { return new Guid[0]; } Guid parentPageId = level == 1 ? Guid.Empty : ancestors[level - 2]; return GetAssociatedPageIds(parentPageId, SitemapScope.Children); } if (ancestors.Count < level) { return new Guid[0]; } Guid levelPageId = ancestors[level - 1]; bool andDescendants = associationScope.ToString().EndsWith("AndDescendants"); if (andDescendants) { return GetDescendantsAndSelf(levelPageId); } return new[] {levelPageId}; default: throw new NotImplementedException("Unhandled SitemapScope type: " + associationScope); } }
/// <summary> /// Return the Page Id's that is with the <see cref="SitemapScope"/> of this page- /// </summary> /// <param name="scope">The scope.</param> /// <returns></returns> public IEnumerable<Guid> GetPageIds(SitemapScope scope) { if (scope < SitemapScope.Current || scope > SitemapScope.SiblingsAndSelf) throw new ArgumentOutOfRangeException("scope"); return PageStructureInfo.GetAssociatedPageIds(_page.Id, scope); }
/// <summary> /// Returns <see cref="PageNode"/> elements that is with the <see cref="SitemapScope"/> of this page- /// </summary> /// <param name="scope">The scope.</param> /// <returns></returns> public IEnumerable<PageNode> GetPageNodes(SitemapScope scope) { if (scope < SitemapScope.Current || scope > SitemapScope.SiblingsAndSelf) throw new ArgumentOutOfRangeException("scope"); foreach (Guid pageId in GetPageIds(scope)) { var page = PageManager.GetPageById(pageId); if (page != null) { yield return new PageNode(page, _sitemapNavigator); } } }
private static IEnumerable<XElement> GetSitemapByScopeUnannotated(SitemapScope associationScope, Guid pageId) { if (associationScope == SitemapScope.All) { foreach (XElement homepage in GetSiteMap()) { yield return new XElement(homepage); } yield break; } Verify.ArgumentCondition(pageId != Guid.Empty, "pageId", "The parameter is Guid.Empty"); XElement currentPageElement = PageStructureInfo.GetSiteMap().DescendantsAndSelf().FirstOrDefault(f => f.Attribute("Id").Value == pageId.ToString()); // finde dybden - hvis scope dybden == nuværende dybde + 1, så skift nuværende til first child if (currentPageElement == null) throw new ArgumentException("No page with the given ID could be located in the current data scope ('{0}').".FormatWith(pageId), "pageId"); XElement pageCopy = null; switch (associationScope) { case SitemapScope.Current: yield return new XElement(currentPageElement.Name, currentPageElement.Attributes()); break; case SitemapScope.Parent: if (currentPageElement.Parent != null && currentPageElement.Parent.Name == PageElementName) { yield return new XElement(currentPageElement.Parent.Name, currentPageElement.Parent.Attributes()); } break; case SitemapScope.Descendants: foreach (XElement child in currentPageElement.Elements(PageElementName)) { yield return new XElement(child); } break; case SitemapScope.DescendantsAndCurrent: yield return new XElement(currentPageElement); break; case SitemapScope.Children: foreach (XElement page in currentPageElement.Elements(PageElementName)) { yield return new XElement(page.Name, page.Attributes()); } break; case SitemapScope.Siblings: foreach (XElement page in currentPageElement.Parent.Elements(PageElementName)) { yield return new XElement(page.Name, page.Attributes()); } break; case SitemapScope.Ancestors: foreach (XElement page in currentPageElement.Ancestors(PageElementName)) { pageCopy = new XElement(page.Name, page.Attributes(), pageCopy); } yield return pageCopy; break; case SitemapScope.AncestorsAndCurrent: foreach (XElement page in currentPageElement.AncestorsAndSelf(PageElementName)) { pageCopy = new XElement(page.Name, page.Attributes(), pageCopy); } yield return pageCopy; break; case SitemapScope.Level1: pageCopy = GetPageCopyBySiteDepth(currentPageElement, 1, true); if (pageCopy != null) { yield return pageCopy; } break; case SitemapScope.Level2: pageCopy = GetPageCopyBySiteDepth(currentPageElement, 2, true); if (pageCopy != null) { yield return pageCopy; } break; case SitemapScope.Level3: pageCopy = GetPageCopyBySiteDepth(currentPageElement, 3, true); if (pageCopy != null) { yield return pageCopy; } break; case SitemapScope.Level4: pageCopy = GetPageCopyBySiteDepth(currentPageElement, 4, true); if (pageCopy != null) { yield return pageCopy; } break; case SitemapScope.Level1AndSiblings: foreach (XElement page in PageStructureInfo.GetSiteMap()) { yield return new XElement(page.Name, page.Attributes()); } break; case SitemapScope.Level2AndSiblings: foreach (XElement page in GetSiblingsCopyBySiteDepth(currentPageElement, 2)) { yield return page; } break; case SitemapScope.Level3AndSiblings: foreach (XElement page in GetSiblingsCopyBySiteDepth(currentPageElement, 3)) { yield return page; } break; case SitemapScope.Level4AndSiblings: foreach (XElement page in GetSiblingsCopyBySiteDepth(currentPageElement, 4)) { yield return page; } break; case SitemapScope.Level1AndDescendants: pageCopy = GetPageCopyBySiteDepth(currentPageElement, 1, false); if (pageCopy != null) { yield return pageCopy; } break; case SitemapScope.Level2AndDescendants: pageCopy = GetPageCopyBySiteDepth(currentPageElement, 2, false); if (pageCopy != null) { yield return pageCopy; } break; case SitemapScope.Level3AndDescendants: pageCopy = GetPageCopyBySiteDepth(currentPageElement, 3, false); if (pageCopy != null) { yield return pageCopy; } break; case SitemapScope.Level4AndDescendants: pageCopy = GetPageCopyBySiteDepth(currentPageElement, 4, false); if (pageCopy != null) { yield return pageCopy; } break; default: throw new NotImplementedException("Unhandled SitemapScope type: " + associationScope); } }
internal static IEnumerable<XElement> GetPageElementsByScope(SitemapScope associationScope, XElement currentPageElement) { IEnumerable<XElement> scopeElements = null; XElement matchPage; switch (associationScope) { case SitemapScope.Parent: if (currentPageElement.Parent != null && currentPageElement.Parent.Name == PageElementName) { yield return currentPageElement.Parent; } break; case SitemapScope.Descendants: scopeElements = currentPageElement.Descendants(PageElementName); break; case SitemapScope.DescendantsAndCurrent: scopeElements = currentPageElement.DescendantsAndSelf(PageElementName); break; case SitemapScope.Children: scopeElements = currentPageElement.Elements(PageElementName); break; case SitemapScope.Siblings: scopeElements = currentPageElement.Parent.Elements(PageElementName); break; case SitemapScope.Ancestors: scopeElements = currentPageElement.Ancestors(PageElementName); break; case SitemapScope.AncestorsAndCurrent: scopeElements = currentPageElement.AncestorsAndSelf(PageElementName); break; case SitemapScope.Level1: scopeElements = GetPageElementBySiteDepth(currentPageElement, 1); break; case SitemapScope.Level2: scopeElements = GetPageElementBySiteDepth(currentPageElement, 2); break; case SitemapScope.Level3: scopeElements = GetPageElementBySiteDepth(currentPageElement, 3); break; case SitemapScope.Level4: scopeElements = GetPageElementBySiteDepth(currentPageElement, 4); break; case SitemapScope.Level1AndDescendants: scopeElements = GetPageElementBySiteDepth(currentPageElement, 1).DescendantsAndSelf(); break; case SitemapScope.Level2AndDescendants: scopeElements = GetPageElementBySiteDepth(currentPageElement, 2).DescendantsAndSelf(); break; case SitemapScope.Level3AndDescendants: scopeElements = GetPageElementBySiteDepth(currentPageElement, 3).DescendantsAndSelf(); break; case SitemapScope.Level4AndDescendants: scopeElements = GetPageElementBySiteDepth(currentPageElement, 4).DescendantsAndSelf(); break; case SitemapScope.Level1AndSiblings: matchPage = GetPageElementBySiteDepth(currentPageElement, 1).FirstOrDefault(); if (matchPage != null && matchPage.Parent != null) { scopeElements = matchPage.Parent.Elements(PageElementName); } break; case SitemapScope.Level2AndSiblings: matchPage = GetPageElementBySiteDepth(currentPageElement, 1).FirstOrDefault(); if (matchPage != null) { scopeElements = matchPage.Elements(PageElementName); } break; case SitemapScope.Level3AndSiblings: matchPage = GetPageElementBySiteDepth(currentPageElement, 2).FirstOrDefault(); if (matchPage != null) { scopeElements = matchPage.Elements(PageElementName); } break; case SitemapScope.Level4AndSiblings: matchPage = GetPageElementBySiteDepth(currentPageElement, 3).FirstOrDefault(); if (matchPage != null) { scopeElements = matchPage.Elements(PageElementName); } break; default: throw new NotImplementedException("Unhandled SitemapScope type: " + associationScope); } if (scopeElements != null) { foreach (XElement scopeElement in scopeElements) { yield return scopeElement; } } }
/// <exclude /> public static IEnumerable<Guid> GetAssociatedPageIds(Guid pageId, SitemapScope associationScope, IEnumerable<XElement> sitemaps) { switch (associationScope) { case SitemapScope.Current: yield return pageId; break; case SitemapScope.All: #pragma warning disable 618 foreach (Guid id in GetIdToUrlLookup().Keys) #pragma warning restore 618 { yield return id; } break; case SitemapScope.Descendants: case SitemapScope.DescendantsAndCurrent: case SitemapScope.Children: case SitemapScope.Siblings: case SitemapScope.Ancestors: case SitemapScope.AncestorsAndCurrent: case SitemapScope.Parent: case SitemapScope.Level1: case SitemapScope.Level2: case SitemapScope.Level3: case SitemapScope.Level4: case SitemapScope.Level1AndDescendants: case SitemapScope.Level2AndDescendants: case SitemapScope.Level3AndDescendants: case SitemapScope.Level4AndDescendants: case SitemapScope.Level1AndSiblings: case SitemapScope.Level2AndSiblings: case SitemapScope.Level3AndSiblings: case SitemapScope.Level4AndSiblings: string pageIdString = pageId.ToString(); XAttribute idMatchAttrib = sitemaps.DescendantsAndSelf().Attributes(AttributeNames.Id).FirstOrDefault(id => id.Value == pageIdString); if (idMatchAttrib != null) { XElement currentPageElement = idMatchAttrib.Parent; IEnumerable<XElement> scopeElements = GetPageElementsByScope(associationScope, currentPageElement); foreach (XElement pageElement in scopeElements) { yield return new Guid(pageElement.Attribute(AttributeNames.Id).Value); } } break; default: throw new NotImplementedException("Unhandled SitemapScope type: " + associationScope); } }
public static IEnumerable <Guid> GetAssociatedPageIds(Guid pageId, SitemapScope sitemapScope) => PageStructureInfo.GetAssociatedPageIds(pageId, sitemapScope);
private static IEnumerable <KeyValuePair> GetOptionsForDefault(Type t, Guid pageId, SitemapScope sitemapScope) { IEnumerable <Guid> availablePageIds = GetAssociatedPageIds(pageId, sitemapScope).Distinct(); using (DataConnection con = new DataConnection()) { IEnumerable <KeyValuePair> result = new List <KeyValuePair>(); MethodInfo generic = typeof(DataConnection).GetMethod("Get").MakeGenericMethod(t); IEnumerable <IPageRelatedData> availableObjects = (IEnumerable <IPageRelatedData>)generic.Invoke(con, null); if (!availableObjects.Any()) { return(result); } PropertyInfo idProperty = availableObjects.First().GetKeyProperties().First(k => k.Name == "Id"); result = from a in availableObjects join b in availablePageIds on a.PageId equals b select new KeyValuePair(idProperty.GetValue(a).ToString(), a.GetLabel()); return(result); } }