public virtual async Task <ICollection <string> > GetSitemapUrlsAsync(string storeId) { if (string.IsNullOrEmpty(storeId)) { throw new ArgumentException(nameof(storeId)); } var sitemapUrls = new List <string>(); var store = await _storeService.GetByIdAsync(storeId); var sitemapSearchCriteria = new SitemapSearchCriteria { StoreId = store.Id, Skip = 0, Take = int.MaxValue }; var sitemaps = await LoadAllStoreSitemaps(store, ""); foreach (var sitemap in sitemaps) { sitemapUrls.AddRange(sitemap.PagedLocations); } return(sitemapUrls); }
public async Task TestDataExport() { // Arrange var sitemapSearchCriteria = new SitemapSearchCriteria { Skip = 0, Take = int.MaxValue }; var sitemapSearchResult = new GenericSearchResult <Sitemap> { TotalCount = TestSitemaps.Count, Results = TestSitemaps }; _sitemapService.Setup(service => service.SearchAsync(sitemapSearchCriteria)) .ReturnsAsync(sitemapSearchResult); var sitemapItemSearchCriteria = new SitemapItemSearchCriteria { Skip = 0, Take = int.MaxValue }; var sitemapItemsSearchResult = new GenericSearchResult <SitemapItem> { TotalCount = TestSitemapItems.Count, Results = TestSitemapItems }; _sitemapItemService.Setup(service => service.SearchAsync(sitemapItemSearchCriteria)) .ReturnsAsync(sitemapItemsSearchResult); string expectedJson; using (var resourceStream = ReadEmbeddedResource("Resources.SerializedSitemapsData.json")) using (var textReader = new StreamReader(resourceStream)) { expectedJson = await textReader.ReadToEndAsync(); } // Act string actualJson; using (var targetStream = new MemoryStream()) { await _sitemapExportImport.DoExportAsync(targetStream, IgnoreProgressInfo, _cancellationToken.Object); var targetStreamContents = targetStream.ToArray(); using (var copiedStream = new MemoryStream(targetStreamContents)) using (var textReader = new StreamReader(copiedStream)) { actualJson = textReader.ReadToEnd(); } } // Assert var expectedJObject = JsonConvert.DeserializeObject <JObject>(expectedJson); var actualJObject = JsonConvert.DeserializeObject <JObject>(actualJson); Assert.True(JToken.DeepEquals(expectedJObject, actualJObject)); }
public virtual async Task <GenericSearchResult <Sitemap> > SearchAsync(SitemapSearchCriteria criteria) { if (criteria == null) { throw new ArgumentNullException(nameof(criteria)); } var cacheKey = CacheKey.With(GetType(), nameof(SearchAsync), criteria.GetCacheKey()); return(await PlatformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async cacheEntry => { cacheEntry.AddExpirationToken(SitemapSearchCacheRegion.CreateChangeToken()); using (var repository = RepositoryFactory()) { var result = new GenericSearchResult <Sitemap>(); var query = repository.Sitemaps; if (!string.IsNullOrEmpty(criteria.StoreId)) { query = query.Where(s => s.StoreId == criteria.StoreId); } if (!string.IsNullOrEmpty(criteria.Location)) { query = query.Where(s => s.Filename == criteria.Location); } var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = ReflectionUtility.GetPropertyName <SitemapEntity>(x => x.CreatedDate), SortDirection = SortDirection.Descending } }; } query = query.OrderBySortInfos(sortInfos); result.TotalCount = await query.CountAsync(); if (criteria.Take > 0) { var sitemapIds = await query.Select(x => x.Id).Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync(); result.Results = (await GetByIdsAsync(sitemapIds, criteria.ResponseGroup)).AsQueryable().OrderBySortInfos(sortInfos).ToArray(); } return result; } })); }
public async Task <IActionResult> SearchSitemaps([FromBody] SitemapSearchCriteria request) { if (request == null) { return(BadRequest("request is null")); } var sitemapSearchResponse = await _sitemapService.SearchAsync(request); return(Ok(sitemapSearchResponse)); }
public virtual async Task <SitemapSearchResult> SearchAsync(SitemapSearchCriteria criteria) { if (criteria == null) { throw new ArgumentNullException(nameof(criteria)); } var result = AbstractTypeFactory <SitemapSearchResult> .TryCreateInstance(); using (var repository = _repositoryFactory()) { var query = repository.Sitemaps; if (!string.IsNullOrEmpty(criteria.StoreId)) { query = query.Where(s => s.StoreId == criteria.StoreId); } if (!string.IsNullOrEmpty(criteria.Location)) { query = query.Where(s => s.Filename == criteria.Location); } var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = ReflectionUtility.GetPropertyName <SitemapEntity>(x => x.CreatedDate), SortDirection = SortDirection.Descending } }; } query = query.OrderBySortInfos(sortInfos); result.TotalCount = await query.CountAsync(); if (criteria.Take > 0) { var sitemapIds = await query.Select(x => x.Id).Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync(); result.Results = (await _sitemapService.GetByIdsAsync(sitemapIds, criteria.ResponseGroup)).AsQueryable().OrderBySortInfos(sortInfos).ToArray(); } } return(result); }
private async Task <ICollection <Sitemap> > LoadAllStoreSitemaps(Store store, string baseUrl) { var result = new List <Sitemap>(); var sitemapSearchCriteria = new SitemapSearchCriteria { StoreId = store.Id, Skip = 0, Take = int.MaxValue }; var sitemapSearchResult = await SitemapService.SearchAsync(sitemapSearchCriteria); foreach (var sitemap in sitemapSearchResult.Results) { await LoadSitemapRecords(store, sitemap, baseUrl); result.Add(sitemap); } return(result); }