Пример #1
0
        public virtual async Task <StoreSearchResult> SearchStoresAsync(StoreSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), "SearchStoresAsync", criteria.GetCacheKey());

            return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(StoreCacheRegion.CreateChangeToken());
                var result = AbstractTypeFactory <StoreSearchResult> .TryCreateInstance();
                using (var repository = _repositoryFactory())
                {
                    var sortInfos = criteria.SortInfos;
                    if (sortInfos.IsNullOrEmpty())
                    {
                        sortInfos = new[]
                        {
                            new SortInfo
                            {
                                SortColumn = "Name"
                            }
                        };
                    }

                    var query = GetStoresQuery(repository, criteria, sortInfos);

                    result.TotalCount = await query.CountAsync();
                    if (criteria.Take > 0)
                    {
                        var storeIds = await query.Select(x => x.Id).Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync();
                        result.Results = (await _storeService.GetByIdsAsync(storeIds)).AsQueryable().OrderBySortInfos(sortInfos).ToList();
                    }
                }
                return result;
            }));
        }
Пример #2
0
        public async Task <Store[]> GetByIdsAsync(string[] ids)
        {
            var cacheKey = CacheKey.With(GetType(), "GetByIdsAsync", string.Join("-", ids));

            return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                var stores = new List <Store>();

                using (var repository = _repositoryFactory())
                {
                    var dbStores = await repository.GetStoresByIdsAsync(ids);
                    foreach (var dbStore in dbStores)
                    {
                        var store = AbstractTypeFactory <Store> .TryCreateInstance();
                        dbStore.ToModel(store);

                        PopulateStore(store, dbStore);

                        await _settingManager.DeepLoadSettingsAsync(store);
                        stores.Add(store);
                        cacheEntry.AddExpirationToken(StoreCacheRegion.CreateChangeToken(store));
                    }
                }

                var result = stores.ToArray();
                var taskLoadDynamicPropertyValues = _dynamicPropertyService.LoadDynamicPropertyValuesAsync(result);
                var taskLoadSeoForObjects = _seoService.LoadSeoForObjectsAsync(result);
                await Task.WhenAll(taskLoadDynamicPropertyValues, taskLoadSeoForObjects);

                return result;
            }));
        }
        public async Task <Model.Stores.Store[]> GetAllStoresAsync()
        {
            var cacheKey = CacheKey.With(GetType(), "GetAllStoresAsync");

            return(await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(StoreCacheRegion.CreateChangeToken());
                cacheEntry.AddExpirationToken(_apiChangesWatcher.CreateChangeToken());

                return (await _storeApi.GetStoresAsync()).Select(x => x.ToStore()).ToArray();
            }, cacheNullValue : false));
        }
Пример #4
0
        public async Task <Store> GetStoreByIdAsync(string id, Currency currency = null)
        {
            var cacheKey = CacheKey.With(GetType(), "GetStoreByIdAsync", id, currency?.ToString());

            return(await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(StoreCacheRegion.CreateChangeToken());
                cacheEntry.AddExpirationToken(_apiChangesWatcher.CreateChangeToken());

                var storeDto = await _storeApi.GetStoreByIdAsync(id);
                return await ConvertStoreAndLoadDependeciesAsync(storeDto, currency);
            }, cacheNullValue : false));
        }
Пример #5
0
        public async Task <Model.Stores.Store[]> GetAllStoresAsync()
        {
            var cacheKey = CacheKey.With(GetType(), "GetAllStoresAsync");

            return(await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(StoreCacheRegion.CreateChangeToken());
                cacheEntry.AddExpirationToken(_apiChangesWatcher.CreateChangeToken());

                var storeDtos = await _storeApi.GetStoresAsync();
                return await Task.WhenAll(storeDtos.Select(x => ConvertStoreAndLoadDependeciesAsync(x)));
            }, cacheNullValue : false));
        }