internal MarketDescription(MarketDescriptionCacheItem cacheItem, IEnumerable <CultureInfo> cultures) { Contract.Requires(cacheItem != null); Contract.Requires(cultures != null && cultures.Any()); var cultureList = cultures as IList <CultureInfo> ?? cultures.ToList(); MarketDescriptionCI = cacheItem; Id = cacheItem.Id; _names = new ReadOnlyDictionary <CultureInfo, string>(cultureList.ToDictionary(c => c, cacheItem.GetName)); _descriptions = new ReadOnlyDictionary <CultureInfo, string>(cultureList.Where(cacheItem.HasTranslationsFor) .ToDictionary(c => c, cacheItem.GetDescription)); Outcomes = cacheItem.Outcomes == null ? null : new ReadOnlyCollection <IOutcomeDescription>(cacheItem.Outcomes .Select(o => (IOutcomeDescription) new OutcomeDescription(o, cultureList)).ToList()); Specifiers = cacheItem.Specifiers == null ? null : new ReadOnlyCollection <ISpecifier>(cacheItem.Specifiers.Select(s => (ISpecifier) new Specifier(s)) .ToList()); Mappings = cacheItem.Mappings == null ? null : new ReadOnlyCollection <IMarketMappingData>(cacheItem.Mappings .Select(m => (IMarketMappingData) new MarketMapping(m)).ToList()); Attributes = cacheItem.Attributes == null ? null : new ReadOnlyCollection <IMarketAttribute>(cacheItem.Attributes .Select(a => (IMarketAttribute) new MarketAttribute(a)).ToList()); OutcomeType = cacheItem.OutcomeType; Groups = cacheItem.Groups == null ? null : new ReadOnlyCollection <string>(cacheItem.Groups.ToList()); }
internal MarketDescription(MarketDescriptionCacheItem cacheItem, IEnumerable <CultureInfo> cultures) { Guard.Argument(cacheItem, nameof(cacheItem)).NotNull(); Guard.Argument(cultures, nameof(cultures)).NotNull();//.NotEmpty(); if (!cultures.Any()) { throw new ArgumentOutOfRangeException(nameof(cultures)); } var cultureList = cultures as IList <CultureInfo> ?? cultures.ToList(); MarketDescriptionCI = cacheItem; Id = cacheItem.Id; _names = new ReadOnlyDictionary <CultureInfo, string>(cultureList.ToDictionary(c => c, cacheItem.GetName)); _descriptions = new ReadOnlyDictionary <CultureInfo, string>(cultureList.Where(cacheItem.HasTranslationsFor).ToDictionary(c => c, cacheItem.GetDescription)); Outcomes = cacheItem.Outcomes == null ? null : new ReadOnlyCollection <IOutcomeDescription>(cacheItem.Outcomes.Select(o => (IOutcomeDescription) new OutcomeDescription(o, cultureList)).ToList()); Specifiers = cacheItem.Specifiers == null ? null : new ReadOnlyCollection <ISpecifier>(cacheItem.Specifiers.Select(s => (ISpecifier) new Specifier(s)).ToList()); Mappings = cacheItem.Mappings == null ? null : new ReadOnlyCollection <IMarketMappingData>(cacheItem.Mappings.Select(m => (IMarketMappingData) new MarketMapping(m)).ToList()); Attributes = cacheItem.Attributes == null ? null : new ReadOnlyCollection <IMarketAttribute>(cacheItem.Attributes.Select(a => (IMarketAttribute) new MarketAttribute(a)).ToList()); OutcomeType = cacheItem.OutcomeType; Groups = cacheItem.Groups == null ? null : new ReadOnlyCollection <string>(cacheItem.Groups.ToList()); }
public void MarketDescriptionMergeTest() { var msg1 = RMF.GetDescMarket(10); var msg2 = RMF.GetDescMarket(msg1); var ci = MarketDescriptionCacheItem.Build(new MarketDescriptionDTO(msg1), _mappingValidatorFactory, FirstCulture, "test"); ci.Merge(new MarketDescriptionDTO(msg2), SecondCulture); Assert.AreEqual(msg1.id, ci.Id); Assert.AreEqual(msg1.name, ci.GetName(FirstCulture)); Assert.AreEqual(msg1.description, ci.GetDescription(FirstCulture)); Assert.AreEqual(msg1.variant, ci.Variant); Assert.AreEqual(msg1.mappings.Length, ci.Mappings.Count()); Assert.AreEqual(msg1.outcomes.Length, ci.Outcomes.Count()); Assert.AreEqual(msg1.specifiers.Length, ci.Specifiers.Count()); for (var i = 0; i < msg1.mappings.Length; i++) { ValidateMapping(msg1.mappings[i], ci.Mappings.ToArray()[i]); } for (var i = 0; i < msg1.outcomes.Length; i++) { ValidateOutcome(msg1.outcomes[i], ci.Outcomes.ToArray()[i], FirstCulture); } for (var i = 0; i < msg1.specifiers.Length; i++) { ValidateSpecifier(msg1.specifiers[i], ci.Specifiers.ToArray()[i]); } Assert.AreEqual(msg2.id, ci.Id); Assert.AreEqual(msg2.name, ci.GetName(SecondCulture)); Assert.AreEqual(msg2.description, ci.GetDescription(SecondCulture)); Assert.AreEqual(msg2.variant, ci.Variant); // TODO: variant is not overriding Assert.AreEqual(msg2.mappings.Length, ci.Mappings.Count()); Assert.AreEqual(msg2.outcomes.Length, ci.Outcomes.Count()); Assert.AreEqual(msg2.specifiers.Length, ci.Specifiers.Count()); for (var i = 0; i < msg2.mappings.Length; i++) { ValidateMapping(msg2.mappings[i], ci.Mappings.ToArray()[i]); } for (var i = 0; i < msg2.outcomes.Length; i++) { ValidateOutcome(msg2.outcomes[i], ci.Outcomes.ToArray()[i], SecondCulture); } for (var i = 0; i < msg2.specifiers.Length; i++) { ValidateSpecifier(msg2.specifiers[i], ci.Specifiers.ToArray()[i]); } Assert.AreNotEqual(ci.GetName(FirstCulture), ci.GetName(SecondCulture)); Assert.AreNotEqual(ci.GetDescription(FirstCulture), ci.GetDescription(SecondCulture)); Assert.IsTrue(ci.HasTranslationsFor(FirstCulture)); Assert.IsTrue(ci.HasTranslationsFor(SecondCulture)); Assert.IsFalse(ci.HasTranslationsFor(new CultureInfo("es"))); }
private IReadOnlyDictionary <string, string> HandleMarketDescription(int productId, string sportId, int marketId, IReadOnlyDictionary <string, string> specifiers, IReadOnlyDictionary <string, object> sportEventStatus) { Guard.Argument(marketId, nameof(marketId)).Positive(); if (!_config.ProvideAdditionalMarketSpecifiers) { return(specifiers); } MarketDescriptionCacheItem marketDescription = null; try { marketDescription = _marketDescriptionProvider.GetMarketDescriptorAsync(marketId, null).Result; } catch (Exception ex) { var baseEx = ex.GetBaseException(); if (baseEx.InnerException != null) { baseEx = baseEx.InnerException; if (baseEx.InnerException != null) { baseEx = baseEx.InnerException; } } if (baseEx is CacheItemNotFoundException) { ExecutionLog.Warn($"No market description found for marketId={marketId}, sportId={sportId}, productId={productId}. Ex: {baseEx.Message}"); } else if (baseEx is CommunicationException) { ExecutionLog.Warn($"Exception during fetching market descriptions. Ex: {baseEx.Message}"); } else { ExecutionLog.Warn("Exception during fetching market descriptions.", baseEx); } } if (marketDescription == null) { ExecutionLog.Info($"No market description found for marketId={marketId}, sportId={sportId}, productId={productId}."); return(specifiers); } //handle market 215 if (marketId == 215) { var newSpecifiers = specifiers == null ? new Dictionary <string, string>() : specifiers.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); if (sportEventStatus == null) { throw new ArgumentException("SportEventStatus is missing."); } newSpecifiers.Add("$server", sportEventStatus["CurrentServer"].ToString()); return(new ReadOnlyDictionary <string, string>(newSpecifiers)); } //handle $score sov_template if (marketDescription.Mappings == null) { ExecutionLog.Info($"Market description {marketDescription.Id} has no mapping."); return(specifiers); } var marketMapping = marketDescription.Mappings.FirstOrDefault(f => f.ProductId == productId && Equals(f.SportId, URN.Parse(sportId))); if (marketMapping == null || marketMapping.ProductId == 0) { ExecutionLog.Info($"Market description {marketDescription.Id} has no mapping sportId={sportId}, productId={productId}."); return(specifiers); } if (!string.IsNullOrEmpty(marketMapping.SovTemplate) && marketMapping.SovTemplate.Contains("{$score}")) { if (sportEventStatus == null) { throw new ArgumentException("SportEventStatus is missing."); } if (!sportEventStatus.ContainsKey("HomeScore")) { throw new ArgumentException("SportEventStatus is missing HomeScore property."); } if (!sportEventStatus.ContainsKey("AwayScore")) { throw new ArgumentException("SportEventStatus is missing AwayScore property."); } var newSpecifiers = specifiers == null ? new Dictionary <string, string>() : specifiers.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); Debug.Assert(newSpecifiers != null, "newSpecifiers != null"); newSpecifiers.Add("$score", $"{sportEventStatus["HomeScore"]}:{sportEventStatus["AwayScore"]}"); return(new ReadOnlyDictionary <string, string>(newSpecifiers)); } return(specifiers); }