Esempio n. 1
0
        /// <summary>
        /// Fetches the data for languages specified by <code>cultures</code> and merges / adds it to internally used dictionaries.
        /// </summary>
        /// <param name="cultures">A <see cref="IEnumerable{CultureInfo}" /> specifying the languages in which to fetch the data</param>
        /// <param name="clearExistingData">Value indicating whether the internally used dictionaries should be cleared before fetched data is added</param>
        /// <returns>A <see cref="Task" /> representing the async operation</returns>
        private async Task FetchAndMergeAll(IEnumerable <CultureInfo> cultures, bool clearExistingData)
        {
            Contract.Requires(cultures != null && cultures.Any());

            var cultureInfos = cultures as IReadOnlyList <CultureInfo> ?? cultures.ToList();

            Metric.Context("CACHE").Meter("SportDataCache->FetchAndMergeAll", Unit.Calls).Mark($"Getting for cultures='{string.Join(",", cultureInfos.Select(c => c.TwoLetterISOLanguageName))}'.");

            var fetchTasks = cultureInfos.Select(c => _dataRouterManager.GetAllSportsAsync(c)).ToList();

            fetchTasks.AddRange(cultureInfos.Select(c => _dataRouterManager.GetAllTournamentsForAllSportAsync(c)).ToList());
            fetchTasks.AddRange(cultureInfos.Select(c => _dataRouterManager.GetAllLotteriesAsync(c)).ToList());

            if (clearExistingData)
            {
                FetchedCultures.Clear();
                Categories.Clear();
                Sports.Clear();
            }

            await Task.WhenAll(fetchTasks).ConfigureAwait(false);

            foreach (var culture in cultureInfos)
            {
                FetchedCultures.Add(culture);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the list of available lotteries
        /// </summary>
        /// <param name="culture">A <see cref="CultureInfo"/> specifying the language or a null reference to use the languages specified in the configuration</param>
        /// <returns>A list of available lotteries</returns>
        public async Task <IEnumerable <ILottery> > GetLotteriesAsync(CultureInfo culture = null)
        {
            culture = culture ?? _defaultCultures.First();

            LogInt.Info($"Invoked GetLotteriesAsync: Culture={culture.TwoLetterISOLanguageName}.");

            var result = (await _dataRouterManager.GetAllLotteriesAsync(culture, false).ConfigureAwait(false))?.ToList();

            if (result != null && result.Any())
            {
                var lotteries = result.Select(s => _sportEntityFactory.BuildSportEvent <ILottery>(s.Item1, s.Item2, new[] { culture }, _exceptionStrategy)).ToList();
                LogInt.Info($"GetLotteriesAsync returned {lotteries.Count} results.");
                return(lotteries);
            }

            LogInt.Info($"GetLotteriesAsync returned 0 results.");
            return(new List <ILottery>());
        }