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)); }
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)); }
public virtual async Task LoadSitemapItemRecordsAsync(Store store, Sitemap sitemap, string baseUrl, Action <ExportImportProgressInfo> progressCallback = null) { var progressInfo = new ExportImportProgressInfo(); var contentBasePath = $"Pages/{sitemap.StoreId}"; var storageProvider = _blobStorageProviderFactory.CreateProvider(contentBasePath); var options = new SitemapItemOptions(); var staticContentSitemapItems = sitemap.Items.Where(si => !string.IsNullOrEmpty(si.ObjectType) && (si.ObjectType.EqualsInvariant(SitemapItemTypes.ContentItem) || si.ObjectType.EqualsInvariant(SitemapItemTypes.Folder))) .ToList(); var totalCount = staticContentSitemapItems.Count; if (totalCount > 0) { var processedCount = 0; var acceptedFilenameExtensions = SettingsManager.GetValue(ModuleConstants.Settings.General.AcceptedFilenameExtensions.Name, ".md,.html") .Split(',') .Select(i => i.Trim()) .Where(i => !string.IsNullOrEmpty(i)) .ToList(); progressInfo.Description = $"Content: Starting records generation for {totalCount} pages"; progressCallback?.Invoke(progressInfo); foreach (var sitemapItem in staticContentSitemapItems) { var urls = new List <string>(); if (sitemapItem.ObjectType.EqualsInvariant(SitemapItemTypes.Folder)) { var searchResult = await storageProvider.SearchAsync(sitemapItem.UrlTemplate, null); var itemUrls = await GetItemUrls(storageProvider, searchResult); foreach (var itemUrl in itemUrls) { var itemExtension = Path.GetExtension(itemUrl); if (!acceptedFilenameExtensions.Any() || string.IsNullOrEmpty(itemExtension) || acceptedFilenameExtensions.Contains(itemExtension, StringComparer.OrdinalIgnoreCase)) { urls.Add(itemUrl); } } } else if (sitemapItem.ObjectType.EqualsInvariant(SitemapItemTypes.ContentItem)) { var item = await storageProvider.GetBlobInfoAsync(sitemapItem.UrlTemplate); if (item != null) { urls.Add(item.RelativeUrl); } } totalCount = urls.Count; foreach (var url in urls) { using (var stream = storageProvider.OpenRead(url)) { var content = stream.ReadToString(); var yamlHeader = ReadYamlHeader(content); yamlHeader.TryGetValue("permalink", out var permalinks); var frontMatterPermalink = new FrontMatterPermalink(url.Replace(".md", "")); if (permalinks != null) { frontMatterPermalink = new FrontMatterPermalink(permalinks.FirstOrDefault()); } sitemapItem.ItemsRecords.AddRange(GetSitemapItemRecords(store, options, frontMatterPermalink.ToUrl().TrimStart('/'), baseUrl)); processedCount++; progressInfo.Description = $"Content: Have been generated records for {processedCount} of {totalCount} pages"; progressCallback?.Invoke(progressInfo); } } } } }