public GenericSearchResult <InventoryInfo> SearchInventories(InventorySearchCriteria criteria) { var cacheKey = GetCacheKey("IInventorySearchService.SearchInventories", criteria.GetCacheKey()); var retVal = _cacheManager.Get(cacheKey, RegionName, () => _inventorySearchService.SearchInventories(criteria)); return(retVal); }
public virtual async Task <InventoryInfoSearchResult> SearchInventoriesAsync(InventorySearchCriteria criteria) { var cacheKey = CacheKey.With(GetType(), "SearchInventoriesAsync", criteria.GetCacheKey()); return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(InventorySearchCacheRegion.CreateChangeToken()); var result = AbstractTypeFactory <InventoryInfoSearchResult> .TryCreateInstance(); using (var repository = _repositoryFactory()) { repository.DisableChangesTracking(); var sortInfos = GetSortInfos(criteria); var query = GetQuery(repository, criteria, sortInfos); result.TotalCount = await query.CountAsync(); if (criteria.Take > 0) { var inventoryIds = await query.Select(x => x.Id).Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync(); result.Results = (await _inventoryService.GetByIdsAsync(inventoryIds, criteria.ResponseGroup)).AsQueryable().OrderBySortInfos(sortInfos).ToArray(); } } return result; })); }
public void TracksShowAllThreadsForUnownedThreads(bool showAllThreads) { var source = new ThreadReference[] { GetExampleThreadReference(0) }; var criteria = new InventorySearchCriteria { ShowAllThreads = showAllThreads, SearchString = "Id" }; source.ApplyCriteria(criteria).Should().HaveCount(showAllThreads ? 1 : 0); }
public void ApplyWithInvalidTerm(string searchString) { var source = new ThreadReference[] { GetExampleThreadReference() }; var criteria = new InventorySearchCriteria { ShowAllThreads = true, SearchString = searchString }; var results = source.ApplyCriteria(criteria).ToArray(); Assert.False(results.Any()); }
public void ApplyToIdAndDescription(string searchString) { var source = new ThreadReference[] { GetExampleThreadReference() }; var criteria = new InventorySearchCriteria { ShowAllThreads = true, SearchString = searchString }; var results = source.ApplyCriteria(criteria).ToArray(); results.Should().NotBeEmpty(); }
protected virtual IList <SortInfo> GetSortInfos(InventorySearchCriteria criteria) { var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = "ModifiedDate" } }; } return(sortInfos); }
protected virtual IQueryable <InventoryEntity> GetQuery(IInventoryRepository repository, InventorySearchCriteria criteria, IEnumerable <SortInfo> sortInfos) { var query = repository.Inventories; if (!criteria.ProductIds.IsNullOrEmpty()) { query = query.Where(x => criteria.ProductIds.Contains(x.Sku)); } if (!criteria.FulfillmentCenterIds.IsNullOrEmpty()) { query = query.Where(x => criteria.FulfillmentCenterIds.Contains(x.FulfillmentCenterId)); } return(query.OrderBySortInfos(sortInfos)); }
public GenericSearchResult <InventoryInfo> SearchInventories(InventorySearchCriteria criteria) { var result = new GenericSearchResult <InventoryInfo>(); using (var repository = _repositoryFactory()) { repository.DisableChangesTracking(); var query = repository.Inventories; if (!criteria.ProductIds.IsNullOrEmpty()) { query = query.Where(x => criteria.ProductIds.Contains(x.Sku)); } if (!criteria.FulfillmentCenterIds.IsNullOrEmpty()) { query = query.Where(x => criteria.FulfillmentCenterIds.Contains(x.FulfillmentCenterId)); } var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = "ModifiedDate" } }; } query = query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id); result.TotalCount = query.Count(); result.Results = query.Skip(criteria.Skip) .Take(criteria.Take) .ToArray() .Select(x => x.ToModel(AbstractTypeFactory <InventoryInfo> .TryCreateInstance())) .ToList(); } return(result); }
public async Task <GenericSearchResult <InventoryInfo> > SearchInventoriesAsync(InventorySearchCriteria criteria) { var cacheKey = CacheKey.With(GetType(), "SearchInventoriesAsync", criteria.GetCacheKey()); return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { var result = new GenericSearchResult <InventoryInfo>(); using (var repository = _repositoryFactory()) { repository.DisableChangesTracking(); var query = repository.Inventories; if (!criteria.ProductIds.IsNullOrEmpty()) { query = query.Where(x => criteria.ProductIds.Contains(x.Sku)); } if (!criteria.FulfillmentCenterIds.IsNullOrEmpty()) { query = query.Where(x => criteria.FulfillmentCenterIds.Contains(x.FulfillmentCenterId)); } var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = "ModifiedDate" } }; } query = query.OrderBySortInfos(sortInfos); result.TotalCount = await query.CountAsync(); var list = await query.Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync(); result.Results = list .Select(x => { var inventory = x.ToModel(AbstractTypeFactory <InventoryInfo> .TryCreateInstance()); cacheEntry.AddExpirationToken(InventoryCacheRegion.CreateChangeToken(inventory)); return inventory; }) .ToList(); } return result; })); }
public override void Initialise(object param) { Criteria = new InventorySearchCriteria(); SearchResults = new ObservableCollection <WrappedThreadReference>(); _threadReferences = _threadReferenceRepository.GetAll().OrderBy(o => !o.Owned).ThenBy(o => o.Id).AsObservable(); }
public async Task DoExportAsync(Stream outStream, CsvExportInfo exportInfo, Action <ExportImportProgressInfo> progressCallback) { var prodgressInfo = new ExportImportProgressInfo { Description = "loading products..." }; var streamWriter = new StreamWriter(outStream, Encoding.UTF8, 1024, true) { AutoFlush = true }; using (var csvWriter = new CsvWriter(streamWriter)) { //Notification progressCallback(prodgressInfo); //Load all products to export var products = await LoadProducts(exportInfo.CatalogId, exportInfo.CategoryIds, exportInfo.ProductIds); var allProductIds = products.Select(x => x.Id).ToArray(); //Load prices for products prodgressInfo.Description = "loading prices..."; progressCallback(prodgressInfo); var priceEvalContext = new PriceEvaluationContext { ProductIds = allProductIds, PricelistIds = exportInfo.PriceListId == null ? null : new[] { exportInfo.PriceListId }, Currency = exportInfo.Currency }; var allProductPrices = (await _pricingService.EvaluateProductPricesAsync(priceEvalContext)).ToList(); //Load inventories prodgressInfo.Description = "loading inventory information..."; progressCallback(prodgressInfo); var inventorySearchCriteria = new InventorySearchCriteria() { ProductIds = allProductIds, FulfillmentCenterIds = string.IsNullOrWhiteSpace(exportInfo.FulfilmentCenterId) ? Array.Empty <string>() : new[] { exportInfo.FulfilmentCenterId }, Take = int.MaxValue, }; var allProductInventories = (await _inventorySearchService.SearchInventoriesAsync(inventorySearchCriteria)).Results.ToList(); //Export configuration exportInfo.Configuration.PropertyCsvColumns = products.SelectMany(x => x.Properties).Select(x => x.Name).Distinct().ToArray(); csvWriter.Configuration.Delimiter = exportInfo.Configuration.Delimiter; csvWriter.Configuration.RegisterClassMap(new CsvProductMap(exportInfo.Configuration)); //Write header csvWriter.WriteHeader <CsvProduct>(); csvWriter.NextRecord(); prodgressInfo.TotalCount = products.Count; var notifyProductSizeLimit = 50; var counter = 0; //convert to dict for faster search var pricesDict = allProductPrices.GroupBy(x => x.ProductId).ToDictionary(x => x.Key, x => x.First()); var inventoriesDict = allProductInventories.GroupBy(x => x.ProductId).ToDictionary(x => x.Key, x => x.First()); foreach (var product in products) { try { var csvProducts = MakeMultipleExportProducts(product, pricesDict, inventoriesDict); csvWriter.WriteRecords(csvProducts); } catch (Exception ex) { prodgressInfo.Errors.Add(ex.ToString()); progressCallback(prodgressInfo); } //Raise notification each notifyProductSizeLimit products counter++; prodgressInfo.ProcessedCount = counter; prodgressInfo.Description = string.Format("{0} of {1} products processed", prodgressInfo.ProcessedCount, prodgressInfo.TotalCount); if (counter % notifyProductSizeLimit == 0 || counter == prodgressInfo.TotalCount) { progressCallback(prodgressInfo); } } } }