Ejemplo n.º 1
0
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            SitemapScope SitemapScope;
            Expression   filter;

            if (parameters.TryGetParameter <SitemapScope>("SitemapScope", out SitemapScope) == false)
            {
                SitemapScope = SitemapScope.Current;
            }

            switch (SitemapScope)
            {
            case SitemapScope.Current:
                Guid currentPageId = PageRenderer.CurrentPageId;
                filter = Expression.Equal(_foreignKeyPropertyExpression, Expression.Constant(currentPageId));
                break;

            case SitemapScope.All:
                filter = Expression.Constant(true);
                break;

            default:
                Guid pageId = PageRenderer.CurrentPageId;

                IEnumerable <Guid> pageIds = new FilterWrapper(
                    pageId,
                    SitemapScope, TableVersion.Get(typeof(IPageStructure)),
                    PageStructureInfo.GetAssociatedPageIds(pageId, SitemapScope));

                Expression <Func <Guid, bool> > containsExpression = f => pageIds.Contains(f);
                filter = Expression.Invoke(containsExpression, _foreignKeyPropertyExpression);
                break;
            }

            return(Expression.Lambda <Func <T, bool> >(filter, new ParameterExpression[] { _parameterExpression }));
        }