public void InVariantMarketDescriptionCacheGetMarketMappingsTest()
        {
            var market1 = _inVariantMdCache.GetMarketDescriptionAsync(399, null, new[] { TestData.Culture }).Result;
            var market2 = _variantMdCache.GetMarketDescriptionAsync(10030, "lcoo:markettext:33421", new[] { TestData.Culture }).Result;

            Assert.IsNotNull(market1);
            Assert.IsNotNull(market2);
            Assert.AreEqual(399, market1.Id);
            Assert.AreEqual(10030, market2.Id);
            Assert.IsTrue(market1.Mappings.Any());
            Assert.IsTrue(market2.Outcomes.Any());
        }
예제 #2
0
        public void InVariantMarketDescriptionCacheIsCachingTest()
        {
            const string callType = "GetMarketDescriptionsAsync";
            var          market   = _inVariantMdCache.GetMarketDescriptionAsync(178, "lcoo:markettext:1", TestData.Cultures).Result;

            Assert.IsNotNull(market);
            Assert.AreEqual(178, market.Id);
            Assert.AreEqual(750, _invariantMemoryCache.Count());
            Assert.AreEqual(3, _dataRouterManager.GetCallCount(callType), $"{callType} should be called exactly 3 times.");

            market = _inVariantMdCache.GetMarketDescriptionAsync(178, "lcoo:markettext:1", TestData.Cultures).Result;
            Assert.IsNotNull(market);
            Assert.AreEqual(750, _invariantMemoryCache.Count());
            Assert.AreEqual(3, _dataRouterManager.GetCallCount(callType), $"{callType} - no new call should be made.");
        }
        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);
        }
예제 #4
0
        /// <summary>
        /// Gets a <see cref="IMarketDescription" /> instance for the market specified by <code>id</code> and <code>specifiers</code>
        /// </summary>
        /// <param name="marketId">The market identifier</param>
        /// <param name="specifiers">A dictionary specifying market specifiers or a null reference if market is invariant</param>
        /// <param name="cultures">A <see cref="IEnumerable{CultureInfo}"/> specifying required translations</param>
        /// <param name="fetchVariantDescriptions"></param>
        /// <returns>A <see cref="IMarketDescription" /> instance describing the specified markets</returns>
        /// <exception cref="CacheItemNotFoundException">The requested key was not found in the cache and could not be loaded</exception>
        public async Task <IMarketDescription> GetMarketDescriptionAsync(int marketId, IReadOnlyDictionary <string, string> specifiers, IEnumerable <CultureInfo> cultures, bool fetchVariantDescriptions)
        {
            IMarketDescription marketDescriptor;
            var cultureInfos = cultures as IList <CultureInfo> ?? cultures.ToList();

            try
            {
                //_executionLog.LogDebug($"Fetching invariant market description for id={marketId} and langs: [{string.Join(",", cultureInfos.Select(s => s.TwoLetterISOLanguageName))}].");
                marketDescriptor = await _invariantMarketsCache.GetMarketDescriptionAsync(marketId, null, cultureInfos).ConfigureAwait(false);

                //_executionLog.LogDebug($"Fetching invariant market description for id={marketId} and langs: [{string.Join(",", cultureInfos.Select(s => s.TwoLetterISOLanguageName))}] COMPLETED.");
            }
            catch (Exception e)
            {
                throw new CacheItemNotFoundException($"Market description with market id {marketId} could not be found", marketId.ToString(), e);
            }

            string variantValue = null;

            specifiers?.TryGetValue(SdkInfo.VariantDescriptionName, out variantValue);

            // case 1: if its not a variant market, return the static market descriptor as is
            if (string.IsNullOrEmpty(variantValue))
            {
                return(marketDescriptor);
            }

            if (fetchVariantDescriptions)
            {
                // case 2: defined/known dynamic variant market => (pre:outcometext market) || (market is player props)
                if (IsMarketOutcomeText(marketDescriptor) || IsMarketPlayerProps(marketDescriptor))
                {
                    return(await ProvideDynamicVariantEndpointMarketAsync(marketId, cultureInfos, marketDescriptor, variantValue).ConfigureAwait(false));
                }

                // case 3: "normal" variant market available on the full variant market list (static)
                var marketDesc = await ProvideFullVariantListEndpointMarketAsync(marketId, cultureInfos, marketDescriptor, variantValue).ConfigureAwait(false);

                if (marketDesc == null)
                {
                    // case 4: dynamic market which is not defined
                    marketDesc = await ProvideDynamicVariantEndpointMarketAsync(marketId, cultureInfos, marketDescriptor, variantValue).ConfigureAwait(false);
                }

                //if (marketDesc?.Mappings != null && marketDesc.Mappings.Any())
                //{
                //    var marketDescImpl = (MarketDescription) marketDesc;
                //    marketDescImpl.Mappings = marketDescImpl.Mappings.Where(s => s.MarketId.Equals(marketId.ToString()) || s.MarketId.StartsWith($"{marketId}:")).ToList();
                //    marketDesc = marketDescImpl;
                //}

                return(marketDesc);
            }

            return(marketDescriptor);
        }
예제 #5
0
        /// <summary>
        /// Gets a <see cref="IMarketDescription" /> instance for the market specified by <code>id</code> and <code>specifiers</code>
        /// </summary>
        /// <param name="marketId">The market identifier</param>
        /// <param name="specifiers">A dictionary specifying market specifiers or a null reference if market is invariant</param>
        /// <param name="cultures">A <see cref="IEnumerable{CultureInfo}"/> specifying required translations</param>
        /// <param name="fetchVariantDescriptions"></param>
        /// <returns>A <see cref="IMarketDescription" /> instance describing the specified markets</returns>
        /// <exception cref="CacheItemNotFoundException">The requested key was not found in the cache and could not be loaded</exception>
        public async Task <IMarketDescription> GetMarketDescriptionAsync(int marketId, IReadOnlyDictionary <string, string> specifiers, IEnumerable <CultureInfo> cultures, bool fetchVariantDescriptions)
        {
            IMarketDescription marketDescriptor;
            var cultureInfos = cultures as IList <CultureInfo> ?? cultures.ToList();

            try
            {
                marketDescriptor = await _invariantMarketsCache.GetMarketDescriptionAsync(marketId, null, cultureInfos).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                throw new CacheItemNotFoundException($"Market description with market id {marketId} could not be found", marketId.ToString(), e);
            }

            string variantValue = null;

            specifiers?.TryGetValue(SdkInfo.VariantDescriptionName, out variantValue);

            // case 1: if it is not a variant market, return the static market descriptor as is
            if (string.IsNullOrEmpty(variantValue))
            {
                return(marketDescriptor);
            }

            if (variantValue.Equals("null", StringComparison.InvariantCultureIgnoreCase))
            {
                _executionLog.LogError($"Missing/wrong variant value -> marketId:{marketId}, variantValue: {variantValue}");
                return(marketDescriptor);
            }

            if (fetchVariantDescriptions)
            {
                // case 2: defined/known dynamic variant market => (pre:outcometext market) || (market is player props)
                if (IsMarketOutcomeText(marketDescriptor) || IsMarketPlayerProps(marketDescriptor))
                {
                    return(await ProvideDynamicVariantEndpointMarketAsync(marketId, cultureInfos, marketDescriptor, variantValue).ConfigureAwait(false));
                }

                // case 3: "normal" variant market available on the full variant market list (static)
                var marketDesc = await ProvideFullVariantListEndpointMarketAsync(marketId, cultureInfos, marketDescriptor, variantValue).ConfigureAwait(false);

                if (marketDesc == null)
                {
                    // case 4: dynamic market which is not defined
                    marketDesc = await ProvideDynamicVariantEndpointMarketAsync(marketId, cultureInfos, marketDescriptor, variantValue).ConfigureAwait(false);
                }

                return(marketDesc);
            }

            return(marketDescriptor);
        }
예제 #6
0
        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);
        }