public async Task <CacheGoodsInformation <string> > GetGoodsInformation(string key, GoodsSelector selector) { var cacheGoodsInformationType = _cacheGoodsInformationTypeCreator.GetCacheGoodsInformationType(selector); var cacheGoodsInformation = new CacheGoodsInformation <string>() { Type = cacheGoodsInformationType }; switch (cacheGoodsInformationType) { case CacheGoodsInformationType.GoodsInformation: case CacheGoodsInformationType.GoodsQuestions: var goodsInformationFactory = new GoodsInformationFactory(); var json = await _client.GetGoodsInformationAsync(new Key() { Key_ = key }); if (json.Equals(new GrpcCacheGoodsInformation())) { return(new CacheGoodsInformation <string>() { Type = CacheGoodsInformationType.AddNew }); } var goodsInformation = goodsInformationFactory.CreateGoodsInformation(json); cacheGoodsInformation.GoodsInformation = goodsInformation; break; } return(cacheGoodsInformation); }
public async Task <GoodsInformation <string> > CreateGoodsInformation(GoodsSelector goodsSelector, IGoodsInformationSearcherFactory goodsInformationSearcherFactory) { var cacheGoodsInformation = await _cache.GetGoodsInformation(goodsInformationSearcherFactory.GetKey(), goodsSelector); if (cacheGoodsInformation == null) { cacheGoodsInformation = new CacheGoodsInformation <string>(); } if (cacheGoodsInformation.Type == CacheGoodsInformationType.No || cacheGoodsInformation.Type == CacheGoodsInformationType.AddNew) { cacheGoodsInformation.GoodsInformation = await goodsInformationSearcherFactory.SearchGoodsInformation(); if (cacheGoodsInformation.Type == CacheGoodsInformationType.AddNew) { await _cache.AddGoodsInformation(goodsInformationSearcherFactory.GetKey(), cacheGoodsInformation.GoodsInformation); } } else if (cacheGoodsInformation.Type == CacheGoodsInformationType.GoodsQuestions) { cacheGoodsInformation.GoodsInformation.GoodCells = await goodsInformationSearcherFactory.SearchGoodCells(); } return(cacheGoodsInformation.GoodsInformation); }