コード例 #1
0
        public async Task <ActionResult <ContentStatistic> > GetStoreContentStatsAsync(string storeId)
        {
            var contentStorageProvider = _blobContentStorageProviderFactory.CreateProvider("");
            var cacheKey   = CacheKey.With(GetType(), "pagesCount", $"content-{storeId}");
            var pagesCount = _platformMemoryCache.GetOrCreateExclusive(cacheKey, cacheEntry =>
            {
                cacheEntry.AddExpirationToken(ContentCacheRegion.CreateChangeToken($"content-{storeId}"));
                var result = CountContentItemsRecursive(GetContentBasePath("pages", storeId), contentStorageProvider, GetContentBasePath("blogs", storeId));
                return(result);
            });
            var themesTask = contentStorageProvider.SearchAsync(GetContentBasePath("themes", storeId), null);
            var blogsTask  = contentStorageProvider.SearchAsync(GetContentBasePath("blogs", storeId), null);

            await Task.WhenAll(themesTask, blogsTask);

            var themes = themesTask.Result;
            var blogs  = blogsTask.Result;

            var retVal = new ContentStatistic
            {
                ActiveThemeName = "default",
                ThemesCount     = themes.Results.OfType <BlobFolder>().Count(),
                BlogsCount      = blogs.Results.OfType <BlobFolder>().Count(),
                PagesCount      = pagesCount
            };

            return(Ok(retVal));
        }
コード例 #2
0
        public async Task <ActionResult <ContentStatistic> > GetStoreContentStats(string storeId)
        {
            var contentStorageProvider = _blobContentStorageProviderFactory.CreateProvider("");
            var cacheKey   = CacheKey.With(GetType(), "pagesCount", $"content-{storeId}");
            var pagesCount = _platformMemoryCache.GetOrCreateExclusive(cacheKey, cacheEntry =>
            {
                cacheEntry.AddExpirationToken(ContentCacheRegion.CreateChangeToken($"content-{storeId}"));
                var result = CountContentItemsRecursive(GetContentBasePath("pages", storeId), contentStorageProvider, _blogsFolderName);
                return(result);
            });

            var storeTask  = _storeService.GetByIdAsync(storeId, StoreResponseGroup.DynamicProperties.ToString());
            var themesTask = contentStorageProvider.SearchAsync(GetContentBasePath("themes", storeId), null);
            var blogsTask  = contentStorageProvider.SearchAsync(GetContentBasePath(_blogsFolderName, storeId), null);

            await Task.WhenAll(themesTask, blogsTask, storeTask);

            var store  = storeTask.Result;
            var themes = themesTask.Result;
            var blogs  = blogsTask.Result;

            var retVal = new ContentStatistic
            {
                ActiveThemeName = store.DynamicProperties.FirstOrDefault(x => x.Name == "DefaultThemeName")?.Values?.FirstOrDefault()?.Value.ToString() ?? "default",
                ThemesCount     = themes.Results.OfType <BlobFolder>().Count(),
                BlogsCount      = blogs.Results.OfType <BlobFolder>().Count(),
                PagesCount      = pagesCount
            };

            return(Ok(retVal));
        }