/// <summary> /// Merges the provided descriptions with those found in cache /// </summary> /// <param name="culture">A <see cref="CultureInfo"/> specifying the language of the <code>descriptions</code></param> /// <param name="descriptions">A <see cref="IEnumerable{MarketDescriptionDTO}"/> containing market descriptions in specified language</param> private void Merge(CultureInfo culture, IEnumerable <VariantDescriptionDTO> descriptions) { Guard.Argument(culture, nameof(culture)).NotNull(); Guard.Argument(descriptions, nameof(descriptions)).NotNull();//.NotEmpty(); if (!descriptions.Any()) { throw new ArgumentOutOfRangeException(nameof(descriptions)); } var descriptionList = descriptions as List <VariantDescriptionDTO> ?? descriptions.ToList(); try { _semaphoreCacheMerge.Wait(); foreach (var marketDescription in descriptionList) { var cachedItem = _cache.GetCacheItem(marketDescription.Id); if (cachedItem == null) { cachedItem = new CacheItem(marketDescription.Id, VariantDescriptionCacheItem.Build(marketDescription, _mappingValidatorFactory, culture, CacheName)); _cache.Add(cachedItem, new CacheItemPolicy()); } else { ((VariantDescriptionCacheItem)cachedItem.Value).Merge(marketDescription, culture); } } _fetchedLanguages.Add(culture); } catch (Exception e) { if (!(e is InvalidOperationException)) { throw; } ExecutionLog.Warn("Mapping validation for VariantDescriptionCacheItem failed.", e); } finally { if (!_isDisposed) { _semaphoreCacheMerge.ReleaseSafe(); } } }
/// <summary> /// Merges the provided descriptions with those found in cache /// </summary> /// <param name="culture">A <see cref="CultureInfo" /> specifying the language of the <code>descriptions</code></param> /// <param name="descriptions"> /// A <see cref="IEnumerable{MarketDescriptionDTO}" /> containing market descriptions in /// specified language /// </param> private void Merge(CultureInfo culture, IEnumerable <VariantDescriptionDTO> descriptions) { Contract.Requires(culture != null); Contract.Requires(descriptions != null && descriptions.Any()); var descriptionList = descriptions as List <VariantDescriptionDTO> ?? descriptions.ToList(); try { _semaphoreCacheMerge.Wait(); foreach (var marketDescription in descriptionList) { var cachedItem = _cache.GetCacheItem(marketDescription.Id); if (cachedItem == null) { cachedItem = new CacheItem(marketDescription.Id, VariantDescriptionCacheItem.Build(marketDescription, _mappingValidatorFactory, culture, CacheName)); _cache.Add(cachedItem, new CacheItemPolicy()); } else { ((VariantDescriptionCacheItem)cachedItem.Value).Merge(marketDescription, culture); } } _fetchedLanguages.Add(culture); } catch (Exception e) { if (!(e is InvalidOperationException)) { throw; } ExecutionLog.Warn("Mapping validation for VariantDescriptionCacheItem failed.", e); } finally { if (!_isDisposed) { _semaphoreCacheMerge.Release(); } } }