public virtual async Task <FindStoresQueryResult> GetStoresAsync(GetStoresParam getStoresParam) { if (string.IsNullOrWhiteSpace(getStoresParam.Scope)) { throw new ArgumentException("scope"); } var cacheKey = new CacheKey(CacheConfigurationCategoryNames.Store) { Scope = getStoresParam.Scope }; cacheKey.AppendKeyParts(GETSTORES_CACHE_KEYPART); var request = new FindStoresRequest { ScopeId = getStoresParam.Scope, Query = new Query { StartingIndex = 0, MaximumItems = int.MaxValue, IncludeTotalCount = false, Filter = new FilterGroup { Filters = GetStoreFilters() } } }; var stores = await CacheProvider.GetOrAddAsync(cacheKey, () => OvertureClient.SendAsync(request)) .ConfigureAwait(false); // TODO: Remove this as soon as the FindStoresRequest returns localized display names. if (stores.Results.Any(s => s.DisplayName != null)) { return(stores); } // Try get DisplayNames if (getStoresParam.IncludeExtraInfo) { var ids = stores.Results.Select(x => x.Id).ToList(); var extraStoresInfo = await GetExtraStoresInfoAsync(ids, getStoresParam).ConfigureAwait(false); for (var index = 0; index < stores.Results.Count; index++) { var store = stores.Results[index]; var extraInfo = extraStoresInfo[index]; object displayName = null; extraInfo?.PropertyBag.TryGetValue("DisplayName", out displayName); if (displayName != null) { store.DisplayName = displayName as Overture.ServiceModel.LocalizedString; } } } return(stores); }
public virtual async Task <FindStoresQueryResult> GetStoresAsync(GetStoresParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (param.CultureInfo == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param)); } var cacheKey = new CacheKey(CacheConfigurationCategoryNames.Store) { Scope = param.Scope }; cacheKey.AppendKeyParts(GETSTORES_CACHE_KEYPART); var request = new FindStoresRequest { ScopeId = param.Scope, IncludeChildScopes = true, CultureName = param.CultureInfo.Name, Query = new Query { StartingIndex = 0, MaximumItems = int.MaxValue, IncludeTotalCount = false, Filter = new FilterGroup { Filters = GetStoreFilters() } } }; var stores = await CacheProvider.GetOrAddAsync(cacheKey, () => OvertureClient.SendAsync(request)).ConfigureAwait(false); // TODO: Remove this as soon as the FindStoresRequest returns localized display names. if (stores.Results.Any(s => s.DisplayName != null)) { return(stores); } // Try get DisplayNames if (param.IncludeExtraInfo) { var ids = stores.Results.Select(x => x.Id).ToList(); var extraStoresInfo = await GetExtraStoresInfoAsync(ids, param).ConfigureAwait(false); extraStoresInfo?.ForEach(extraStoreInfo => { extraStoreInfo.PropertyBag.TryGetValue("DisplayName", out object displayName); if (displayName == null) { return; } var store = stores.Results.FirstOrDefault(st => st.Id == extraStoreInfo.Id); if (store == null) { return; } store.DisplayName = displayName as Overture.ServiceModel.LocalizedString; }); } return(stores); }