Beispiel #1
0
        /// <summary>
        ///     Filters content which should not be visible to the user.
        /// </summary>
        /// <typeparam name="T">Type of content (IContent).</typeparam>
        /// <param name="content">Enumeration of content instances to filter.</param>
        /// <param name="requirePageTemplate">Mark if should include only content with template.</param>
        /// <param name="requireVisibleInMenu">Mark if should include only pages with mark VisibleInMenu = true.</param>
        /// <returns>Returns enumeration of filtered content.</returns>
        public static IEnumerable <T> FilterForDisplay <T>(this IEnumerable <T> content, bool requirePageTemplate = false, bool requireVisibleInMenu = false)
            where T : IContent
        {
            if (content == null)
            {
                return(Enumerable.Empty <T>());
            }

            var publishedFilter = new FilterPublished();
            var accessFilter    = new FilterAccess();

            content = content.Where(x => !publishedFilter.ShouldFilter(x) && !accessFilter.ShouldFilter(x));

            if (requirePageTemplate)
            {
                var templateFilter = ServiceLocator.Current.GetInstance <FilterTemplate>();
                templateFilter.TemplateTypeCategories = TemplateTypeCategories.Page;
                content = content.Where(x => !templateFilter.ShouldFilter(x));
            }

            if (requireVisibleInMenu)
            {
                content = content.Where(x => VisibleInMenu(x));
            }

            return(content);
        }
Beispiel #2
0
        public static bool ShouldIndexPage(this IContent content)
        {
            var filterPublished = new FilterPublished();
            var filterTemplate  = new FilterTemplate();
            var hasTemplate     = !filterTemplate.ShouldFilter(content);
            var isPublished     = !filterPublished.ShouldFilter(content);

            return(hasTemplate && isPublished);
        }
Beispiel #3
0
        public static IEnumerable <T> FilterForDisplay <T>(
            this IEnumerable <T> contents,
            bool requirePageTemplate  = false,
            bool requireVisibleInMenu = false) where T : IContent
        {
            var accessFilter    = new FilterAccess();
            var publishedFilter = new FilterPublished();

            contents = contents.Where(x =>
                                      !publishedFilter.ShouldFilter(x) &&
                                      !accessFilter.ShouldFilter(x));

            if (requireVisibleInMenu)
            {
                contents = contents.Where(x => VisibleInMenu(x));
            }

            return(contents);
        }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PredictionEngineService" /> class.
 /// </summary>
 /// <param name="associationRepository">The association repository.</param>
 /// <param name="recommendationRepository">The recommendation repository.</param>
 /// <param name="referenceConverter">The reference converter.</param>
 /// <param name="orderRepository">The order repository.</param>
 /// <param name="currentMarket">The current market.</param>
 /// <param name="filterPublished">The filter published.</param>
 /// <param name="contentLoader">The content loader.</param>
 /// <param name="languageResolver">The language resolver.</param>
 /// <param name="synchronizedObjectInstanceCache">The synchronized object instance cache.</param>
 public PredictionEngineService(
     IAssociationRepository associationRepository,
     IRecommendationRepository recommendationRepository,
     ReferenceConverter referenceConverter,
     IOrderRepository orderRepository,
     ICurrentMarket currentMarket,
     FilterPublished filterPublished,
     IContentLoader contentLoader,
     LanguageResolver languageResolver,
     ISynchronizedObjectInstanceCache synchronizedObjectInstanceCache)
 {
     this.associationRepository           = associationRepository;
     this.recommendationRepository        = recommendationRepository;
     this.referenceConverter              = referenceConverter;
     this.orderRepository                 = orderRepository;
     this.currentMarket                   = currentMarket;
     this.filterPublished                 = filterPublished;
     this.contentLoader                   = contentLoader;
     this.languageResolver                = languageResolver;
     this.synchronizedObjectInstanceCache = synchronizedObjectInstanceCache;
 }
 public CatalogEntryViewModelFactory(
     IPromotionService promotionService,
     IContentLoader contentLoader,
     IPriceService priceService,
     ICurrentMarket currentMarket,
     CurrencyService currencyservice,
     IRelationRepository relationRepository,
     UrlResolver urlResolver,
     FilterPublished filterPublished,
     LanguageResolver languageResolver)
 {
     _promotionService   = promotionService;
     _contentLoader      = contentLoader;
     _priceService       = priceService;
     _currentMarket      = currentMarket;
     _currencyservice    = currencyservice;
     _relationRepository = relationRepository;
     _urlResolver        = urlResolver;
     _filterPublished    = filterPublished;
     _languageResolver   = languageResolver;
 }
Beispiel #6
0
        /// <summary>
        /// Finds all blocks of a block type below <paramref name="reference"/>, and runs it through FilterForVisitor.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="reference">ContentReference to search below</param>
        /// <param name="recursive">Whether to search recursively</param>
        /// <returns>A list containing items of type <typeparam name="T">T</typeparam>, or null</returns>
        public IEnumerable <T> FindFilteredBlocksOfType <T>(ContentReference reference, bool recursive) where T : BlockData
        {
            if (reference == null || reference.ID == 0)
            {
                return(new List <T>());
            }

            var subPages = FindBlocksOfType <T>(reference, recursive).Cast <BlockData>();

            var filterAcces     = new FilterAccess(AccessLevel.Read);
            var publishedFilter = new FilterPublished();

            var filteredBlocks = subPages
                                 .Where(b => !filterAcces.ShouldFilter((IContent)b))
                                 .Where(b => !publishedFilter.ShouldFilter((IContent)b));

            // FilterForVisitor.Filter doesn't work for some reason.
            //It returns null, even if the exact code it uses (tested through reflection) does return the correct list of items.
            //var filteredSubPages = FilterForVisitor.Filter(subPages);

            return(filteredBlocks.Cast <T>());
        }
Beispiel #7
0
        /// <summary>
        /// Finds all pages of a page type below <paramref name="pageLink"/>, and runs it through FilterForVisitor.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pageLink">PageReference to search below</param>
        /// <param name="recursive">Whether to search recursively</param>
        /// <param name="culture"></param>
        /// <returns>A list containing items of type <typeparam name="T">T</typeparam> or an empty list</returns>
        public IEnumerable <T> FindFilteredPagesOfType <T>(ContentReference pageLink, bool recursive, CultureInfo culture) where T : IContent
        {
            if (pageLink == null || pageLink.ID == 0)
            {
                return(new List <T>());
            }

            var subPages = FindPagesOfType <T>(pageLink, recursive, culture).Cast <IContent>();

            var filterAcces     = new FilterAccess(AccessLevel.Read);
            var publishedFilter = new FilterPublished();

            var filteredSubPages = subPages
                                   .Where(p => !filterAcces.ShouldFilter(p))
                                   .Where(p => !publishedFilter.ShouldFilter(p));

            // FilterForVisitor.Filter doesn't work for some reason.
            //It returns null, even if the exact code it uses (tested through reflection) does return the correct list of items.
            //var filteredSubPages = FilterForVisitor.Filter(subPages);

            return(filteredSubPages.Cast <T>());
        }
        public void Setup()
        {
            _defaultCurrency = Currency.USD;
            _preferredCulture = CultureInfo.GetCultureInfo("en");

            _mockUrlResolver = new Mock<UrlResolver>();
            _mockContentLoader = new Mock<IContentLoader>();
            _mockCookieService = new Mock<CookieService>();
            _mockPriceService = new Mock<IPriceService>();
            _mockRelationRepository = new Mock<IRelationRepository>();
            _mockPromotionService = new Mock<IPromotionService>();

            var mockPublishedStateAssessor = new Mock<IPublishedStateAssessor>();
            mockPublishedStateAssessor.Setup(x => x.IsPublished(It.IsAny<IContent>(), It.IsAny<PublishedStateCondition>()))
                .Returns((IContent content, PublishedStateCondition condition) =>
                    {
                        var contentVersionable = content as IVersionable;
                        if (contentVersionable != null)
                        {
                            if (contentVersionable.Status == VersionStatus.Published &&
                                contentVersionable.StartPublish < DateTime.UtcNow &&
                                contentVersionable.StopPublish > DateTime.UtcNow)
                            {
                                return true;
                            }
                        }
                        return false;
                    }
                );

            _filterPublished = new FilterPublished(mockPublishedStateAssessor.Object);

            _mockMarket = new Mock<IMarket>();
            _mockMarket.Setup(x => x.DefaultCurrency).Returns(_defaultCurrency);
            _mockMarket.Setup(x => x.MarketId).Returns(new MarketId("Default"));
            _mockMarket.Setup(x => x.MarketName).Returns("Default");
            _mockMarket.Setup(x => x.IsEnabled).Returns(true);
            _mockMarket.Setup(x => x.DefaultLanguage).Returns(new CultureInfo("en"));

            _mockCurrentMarket = new Mock<ICurrentMarket>();
            _mockCurrentMarket.Setup(x => x.GetCurrentMarket()).Returns(_mockMarket.Object);

            _mockCurrencyservice = new Mock<CurrencyService>(_mockCurrentMarket.Object, _mockCookieService.Object);
            _mockCurrencyservice.Setup(x => x.GetCurrentCurrency()).Returns(_defaultCurrency);

            _appContextFacade = new Mock<AppContextFacade>();
            _appContextFacade.Setup(x => x.ApplicationId).Returns(Guid.NewGuid);

            var request = new Mock<HttpRequestBase>();
            request.SetupGet(x => x.Headers).Returns(
                new System.Net.WebHeaderCollection {
                {"X-Requested-With", "XMLHttpRequest"}
            });

            _mockHttpContextBase = new Mock<HttpContextBase>();
            _mockHttpContextBase.SetupGet(x => x.Request).Returns(request.Object);

            SetGetItems(Enumerable.Empty<ContentReference>(), Enumerable.Empty<IContent>());
            SetDefaultCurrency(null);
        }