Esempio n. 1
0
        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);
        }
        /// <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);
            }
        }