private async Task <IMarketDescription> ProvideDynamicVariantEndpointMarketAsync(int marketId, IList <CultureInfo> locales, IMarketDescription marketDescription, string variantValue) { IMarketDescription variantDescription = null; try { variantDescription = await _variantMarketsCache.GetMarketDescriptionAsync(marketId, variantValue, locales).ConfigureAwait(false); } catch (Exception e) { var langs = string.Join(",", locales.Select(s => s.TwoLetterISOLanguageName)); _executionLog.LogWarning($"There was an error providing the explicit variant market description -> marketId:{marketId}, variantValue: {variantValue}, locales: [{langs}]", e); } if (marketDescription != null && variantDescription != null) { if (marketDescription.Mappings.IsNullOrEmpty() && !variantDescription.Mappings.IsNullOrEmpty()) { ((MarketDescription)marketDescription).SetMappings(variantDescription.Mappings as IReadOnlyCollection <IMarketMappingData>); ((MarketDescription)marketDescription).SetFetchInfo("VariantCache", DateTime.Now); } if (marketDescription.Outcomes.IsNullOrEmpty() && !variantDescription.Outcomes.IsNullOrEmpty()) { ((MarketDescription)marketDescription).SetOutcomes(variantDescription.Outcomes as IReadOnlyCollection <IOutcomeDescription>); ((MarketDescription)marketDescription).SetFetchInfo("VariantCache", DateTime.Now); } } return(marketDescription ?? variantDescription); }
private IEnumerable <IMarketMappingData> GetMarketMapping(IMarketDescription marketDescription) { if (marketDescription == null) { return(null); } if (marketDescription.Mappings == null || !marketDescription.Mappings.Any()) { ExecutionLog.Debug( $"An error occurred getting mapped marketId for marketId={_marketId} (no mappings exist)."); return(null); } var mappings = marketDescription.Mappings.Where(m => m.CanMap(_producer, _sportId, _specifiers)).ToList(); //var mappings1 = marketDescription.Mappings.Where(m => m.CanMap(_producerManager.Get(1), URN.Parse("sr:sport:1"), new Dictionary<string, string> { { "total", "5.5" } })).ToList(); //var mappings2 = marketDescription.Mappings.Where(m => m.CanMap(_producerManager.Get(3), URN.Parse("sr:sport:1"), new Dictionary<string, string> { { "total", "5.5" } })).ToList(); if (!mappings.Any()) { ExecutionLog.Debug( $"Market with id:{_marketId}, producer:{_producer}, sportId:{_sportId} has no mappings."); return(null); } return(mappings); }
/// <summary> /// Constructs a new market definition. The market definition represents additional market data which can be used for more advanced use cases /// </summary> /// <param name="marketDescription">The associated market descriptor</param> /// <param name="marketCacheProvider">The market cache provider used to retrieve name templates</param> /// <param name="sportId">The associated event sport identifier</param> /// <param name="producer">The producer which generated the market</param> /// <param name="specifiers">The associated market specifiers</param> internal MarketDefinition(IMarketDescription marketDescription, IMarketCacheProvider marketCacheProvider, URN sportId, IProducer producer, IReadOnlyDictionary <string, string> specifiers) { _marketDescription = marketDescription; _sportId = sportId; _producer = producer; _specifiers = specifiers; _marketCacheProvider = marketCacheProvider; }
/// <summary> /// Constructs a new market definition. The market definition represents additional market data which can be used for more advanced use cases /// </summary> /// <param name="marketDescription">The associated market descriptor</param> /// <param name="outcomeDescription">The associated outcome descriptor</param> /// <param name="cultures">A <see cref="IEnumerable{CultureInfo}"/> specifying languages the current instance supports</param> internal OutcomeDefinition(IMarketDescription marketDescription, IOutcomeDescription outcomeDescription, IEnumerable <CultureInfo> cultures) { _marketDescription = marketDescription; if (outcomeDescription != null) { _outcomeId = outcomeDescription.Id; foreach (var culture in cultures) { _names[culture] = outcomeDescription.GetName(culture); } } }
private async Task <IMarketDescription> ProvideDynamicVariantEndpointMarketAsync(int marketId, IList <CultureInfo> locales, IMarketDescription marketDescriptor, string variantValue) { IMarketDescription variantDescriptor = null; try { variantDescriptor = await _variantMarketsCache.GetMarketDescriptionAsync(marketId, variantValue, locales).ConfigureAwait(false); } catch (Exception e) { var langs = string.Join(",", locales.Select(s => s.TwoLetterISOLanguageName)); _executionLog.LogWarning($"There was an error providing the explicit variant market description -> marketId:{marketId}, variantValue: {variantValue}, locales: [{langs}]", e); } return(variantDescriptor ?? marketDescriptor); }
internal OutcomeDefinition(IMarketDescription marketDescription, string outcomeId, IMarketCacheProvider marketCacheProvider, IReadOnlyDictionary <string, string> specifiers, IEnumerable <CultureInfo> cultures, ExceptionHandlingStrategy exceptionHandlingStrategy) { Guard.Argument(cultures, nameof(cultures)).NotNull(); _marketDescription = marketDescription; _marketCacheProvider = marketCacheProvider; _outcomeId = outcomeId; _specifiers = specifiers; _cultures = cultures as IReadOnlyCollection <CultureInfo>; _exceptionHandlingStrategy = exceptionHandlingStrategy; }
/// <summary> /// Builds a <see cref="IMarketDefinition" /> associated with the provided data /// </summary> /// <param name="marketId">the id of the market</param> /// <param name="sportId">the sport id</param> /// <param name="producer">the source of the market</param> /// <param name="specifiers">the received market specifiers</param> /// <param name="cultures">the cultures in which the market data should be prefetched</param> /// <returns></returns> private IMarketDefinition BuildMarketDefinition(int marketId, URN sportId, IProducer producer, IReadOnlyDictionary <string, string> specifiers, IEnumerable <CultureInfo> cultures) { // market descriptor should exist or else the market generation would fail // variant always null because we are interested only in the general market attributes IMarketDescription marketDescription = null; try { marketDescription = _marketCacheProvider.GetMarketDescriptionAsync(marketId, specifiers, cultures, false).Result; } catch (CacheItemNotFoundException) { ExecutionLog.Warn($"Market description for market={marketId}, sport={sportId} and producer={producer.Name} not found."); } return(marketDescription == null ? null : new MarketDefinition(marketDescription, _marketCacheProvider, sportId, producer, specifiers)); }
private IEnumerable <IMarketMappingData> GetMarketMapping(IMarketDescription marketDescription) { if (marketDescription == null) { return(new List <IMarketMappingData>()); } if (marketDescription.Mappings == null || !marketDescription.Mappings.Any()) { ExecutionLog.LogDebug($"An error occurred getting mapped marketId for marketId={_marketId} (no mappings exist)."); return(new List <IMarketMappingData>()); } var mappings = marketDescription.Mappings.Where(m => m.CanMap(_producer, _sportId, _specifiers)).ToList(); if (!mappings.Any()) { ExecutionLog.LogDebug($"Market with id:{_marketId}, producer:{_producer}, sportId:{_sportId} has no mappings."); return(mappings); } if (mappings.Count > 1) { foreach (var mapping in mappings) { if (mapping.MarketId.Equals(marketDescription.Id.ToString())) { return(new[] { mapping }); } } ExecutionLog.LogWarning($"Market with id:{_marketId}, producer:{_producer.Id}, sportId:{_sportId.Id} has too many mappings [{mappings.Count}]."); CacheLog.LogWarning($"MarketId:{_marketId}, producer:{_producer.Id}, sportId:{_sportId.Id}, specifiers={SdkInfo.SpecifiersKeysToString(marketDescription.Specifiers)} has too many mappings [{mappings.Count}]."); var i = 0; foreach (var mapping in mappings) { CacheLog.LogDebug($"MarketId:{_marketId}, producer:{_producer.Id}, sportId:{_sportId.Id} mapping[{i}]: {mapping}."); i++; } } return(mappings); }
private IEnumerable <IMarketMappingData> GetMarketMapping(IMarketDescription marketDescription) { if (marketDescription == null) { return(new List <IMarketMappingData>()); } if (marketDescription.Mappings == null || !marketDescription.Mappings.Any()) { ExecutionLog.Debug($"MarketDescription for marketId={_marketId} has no mappings."); return(new List <IMarketMappingData>()); } var mappings = marketDescription.Mappings.Where(m => m.CanMap(_producerId, _sportId, _specifiers)).ToList(); if (!mappings.Any()) { ExecutionLog.Debug($"Market with id:{_marketId}, producer:{_producerId}, sportId:{_sportId} has no mappings."); return(mappings); } if (mappings.Count > 1) { foreach (var mapping in mappings) { if (mapping.MarketId.Equals(marketDescription.Id.ToString())) { return(new[] { mapping }); } } ExecutionLog.Warn($"Market with id:{_marketId}, producer:{_producerId}, sportId:{_sportId.Id} has multiple mappings [{mappings.Count}]."); CacheLog.Warn($"MarketId:{_marketId}, producer:{_producerId}, sportId:{_sportId.Id}, specifiers={MarketHelper.SpecifiersKeysToString(marketDescription.Specifiers)} has multiple mappings [{mappings.Count}]."); var i = 0; foreach (var mapping in mappings) { CacheLog.Debug($"MarketId:{_marketId}, producer:{_producerId}, sportId:{_sportId.Id} mapping[{i}]: {mapping}."); i++; } } return(mappings); }
/// <summary> /// Gets a <see cref="IMarketDefinition" /> associated with the provided data /// </summary> private void GetMarketDefinition() { // market descriptor should exist or else the market generation would fail // variant always null because we are interested only in the general market attributes if (_marketDescription != null) { return; } lock (_lock) { if (_marketDescription != null) { return; } try { _marketDescription = _marketCacheProvider.GetMarketDescriptionAsync(_marketId, _specifiers, _cultures, true).Result; // was false and true in GetNameTemplate } catch (CacheItemNotFoundException ci) { if (_exceptionHandlingStrategy == ExceptionHandlingStrategy.THROW) { throw new CacheItemNotFoundException($"Market description for market={_marketId}, sport={_sportId} and producer={_producerId} not found.", _marketId.ToString(), ci); } } catch (Exception ex) { if (_exceptionHandlingStrategy == ExceptionHandlingStrategy.THROW) { throw new CacheItemNotFoundException($"Market description for market={_marketId} not found.", _marketId.ToString(), ex); } } } }
private static bool IsMarketOutcomeText(IMarketDescription marketDescriptor) { return(!string.IsNullOrEmpty(marketDescriptor?.OutcomeType) && marketDescriptor.OutcomeType.Equals(SdkInfo.FreeTextVariantValue)); }
private static bool IsMarketPlayerProps(IMarketDescription marketDescriptor) { return(marketDescriptor?.Groups != null && marketDescriptor.Groups.Contains(SdkInfo.PlayerPropsMarketGroup)); }
private async Task <IMarketDescription> ProvideFullVariantListEndpointMarketAsync(int marketId, IList <CultureInfo> locales, IMarketDescription marketDescriptor, string variantValue) { try { var variantDescription = await _variantDescriptionListCache .GetVariantDescriptorAsync(variantValue, locales).ConfigureAwait(false); if (variantDescription == null) { return(null); } ((MarketDescription)marketDescriptor).SetOutcomes( variantDescription.Outcomes as IReadOnlyCollection <IOutcomeDescription>); ((MarketDescription)marketDescriptor).SetMappings( variantDescription.Mappings as IReadOnlyCollection <IMarketMappingData>); var variantCI = ((VariantDescription)variantDescription).VariantDescriptionCacheItem; ((MarketDescription)marketDescriptor).SetFetchInfo(variantCI.SourceCache, variantCI.LastDataReceived); return(marketDescriptor); } catch (Exception e) { var langs = string.Join(",", locales.Select(s => s.TwoLetterISOLanguageName)); _executionLog.Warn( $"There was an error providing the variant market description -> marketId:{marketId}, variantValue: {variantValue}, locales: [{langs}]", e); } return(null); }
private async Task <IMarketDescription> ProvideFullVariantListEndpointMarketAsync(int marketId, IList <CultureInfo> locales, IMarketDescription marketDescription, string variantValue) { try { var variantDescription = await _variantDescriptionListCache.GetVariantDescriptorAsync(variantValue, locales).ConfigureAwait(false); if (variantDescription == null) { return(null); } // select appropriate mappings if found; producer and sport is checked later List <IMarketMappingData> mappings = null; if (variantDescription.Mappings != null) { mappings = variantDescription.Mappings.Where(s => s.MarketId.Equals(marketDescription.Id.ToString())).ToList(); if (!mappings.Any()) { mappings = null; } } if (marketDescription != null) { if (!mappings.IsNullOrEmpty() || !variantDescription.Mappings.IsNullOrEmpty()) { ((MarketDescription)marketDescription).SetMappings((mappings ?? variantDescription.Mappings) as IReadOnlyCollection <IMarketMappingData>); var variantCI = ((VariantDescription)variantDescription).VariantDescriptionCacheItem; ((MarketDescription)marketDescription).SetFetchInfo(variantCI.SourceCache, variantCI.LastDataReceived); } if (!variantDescription.Outcomes.IsNullOrEmpty()) { ((MarketDescription)marketDescription).SetOutcomes(variantDescription.Outcomes as IReadOnlyCollection <IOutcomeDescription>); var variantCI = ((VariantDescription)variantDescription).VariantDescriptionCacheItem; ((MarketDescription)marketDescription).SetFetchInfo(variantCI.SourceCache, variantCI.LastDataReceived); } } return(marketDescription); } catch (Exception e) { var langs = string.Join(",", locales.Select(s => s.TwoLetterISOLanguageName)); _executionLog.Warn($"There was an error providing the variant market description -> marketId:{marketId}, variantValue: {variantValue}, locales: [{langs}]", e); } return(null); }