示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Group"/> class
        /// </summary>
        /// <param name="ci">A <see cref="GroupCI"/> used to create new instance</param>
        /// <param name="cultures">A culture of the current instance of <see cref="GroupDTO"/></param>
        /// <param name="sportEntityFactory">A <see cref="ISportEntityFactory"/> used to retrieve <see cref="IPlayerProfile"/></param>
        /// <param name="competitorsReferenceIds">A list of <see cref="ReferenceIdCI"/> for all competitors</param>
        public Group(GroupCI ci,
                     IEnumerable <CultureInfo> cultures,
                     ISportEntityFactory sportEntityFactory,
                     IDictionary <URN, ReferenceIdCI> competitorsReferenceIds)
        {
            Guard.Argument(ci, nameof(ci)).NotNull();

            Id   = ci.Id;
            Name = ci.Name;
            if (ci.Competitors != null)
            {
                //var competitors = new List<ICompetitor>();
                //var cultureInfos = cultures.ToList();
                //foreach (CompetitorCI competitorCI in ci.Competitors)
                //{
                //    if (competitorCI == null)
                //    {
                //        var x = "2";
                //    }
                //    var comp = new Competitor(competitorCI, cultureInfos, sportEntityFactory, competitorsReferenceIds);
                //    competitors.Add(comp);
                //}
                //_competitors = competitors;
                _competitors = ci.Competitors.Select(t => sportEntityFactory.BuildCompetitor(t, cultures, competitorsReferenceIds)).ToList();
            }
        }
示例#2
0
        public CurrentSeasonInfo(CurrentSeasonInfoCI cacheItem,
                                 IEnumerable <CultureInfo> cultures,
                                 ISportEntityFactory sportEntityFactory,
                                 ExceptionHandlingStrategy exceptionHandlingStrategy,
                                 IDictionary <URN, ReferenceIdCI> competitorsReferenceIds)
        {
            Guard.Argument(cacheItem, nameof(cacheItem)).NotNull();
            //Guard.Argument(sportEntityFactory, nameof()).NotNull();

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

            Id        = cacheItem.Id;
            Names     = cacheItem.Name as IReadOnlyDictionary <CultureInfo, string>;
            Year      = cacheItem.Year;
            StartDate = cacheItem.StartDate;
            EndDate   = cacheItem.EndDate;
            Coverage  = cacheItem.SeasonCoverage == null
                ? null
                : new SeasonCoverage(cacheItem.SeasonCoverage);
            Groups = cacheItem.Groups == null
                ? null
                : cacheItem.Groups.Select(s => new Group(s, cultureInfos, sportEntityFactory, exceptionHandlingStrategy, competitorsReferenceIds));
            CurrentRound = cacheItem.CurrentRound == null
                ? null
                : new Round(cacheItem.CurrentRound, cultureInfos);
            Competitors = cacheItem.Competitors == null
                ? null
                : cacheItem.Competitors.Select(s => sportEntityFactory.BuildCompetitor(s, cultureInfos, competitorsReferenceIds, exceptionHandlingStrategy));
            Schedule = cacheItem.Schedule == null
                ? null
                : cacheItem.Schedule.Select(s => sportEntityFactory.BuildSportEvent <ISportEvent>(s, null, cultureInfos, exceptionHandlingStrategy));
        }
        /// <summary>
        /// Asynchronously gets a <see cref="ICompetitor"/>
        /// </summary>
        /// <param name="id">A <see cref="URN"/> specifying the id for which <see cref="ICompetitor"/> to be retrieved</param>
        /// <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 <see cref="ICompetitor"/> representing the specified competitor or a null reference</returns>
        public async Task <ICompetitor> GetCompetitorAsync(URN id, CultureInfo culture = null)
        {
            var cs = culture == null ? _defaultCultures : new[] { culture };
            var s  = cs.Aggregate(string.Empty, (current, cultureInfo) => current + (";" + cultureInfo.TwoLetterISOLanguageName));

            s = s.Substring(1);

            LogInt.LogInformation($"Invoked GetCompetitorAsync: [Id={id}, Cultures={s}]");
            try
            {
                var cacheItem = await _profileCache.GetCompetitorProfileAsync(id, cs).ConfigureAwait(false);

                return(cacheItem == null
                           ? null
                           : _sportEntityFactory.BuildCompetitor(cacheItem, cs, (ICompetitionCI)null, _exceptionStrategy));
            }
            catch (Exception e)
            {
                LogInt.LogError(e, $"Error executing GetCompetitorAsync: [Id={id}, Cultures={s}]");
                if (_exceptionStrategy == ExceptionHandlingStrategy.THROW)
                {
                    throw;
                }
                return(null);
            }
        }
示例#4
0
        public CurrentSeasonInfo(ITournamentInfoCI currentSeasonCI,
                                 IEnumerable <CultureInfo> cultures,
                                 ISportEntityFactory _sportEntityFactory,
                                 ExceptionHandlingStrategy exceptionStrategy,
                                 IDictionary <URN, ReferenceIdCI> competitorsReferenceIds)
        {
            var cultureInfos = cultures as IList <CultureInfo> ?? cultures.ToList();

            Id        = currentSeasonCI.Id;
            Names     = currentSeasonCI.GetNamesAsync(cultureInfos).Result;
            Year      = currentSeasonCI.GetYearAsync().Result;
            StartDate = currentSeasonCI.GetScheduledAsync().Result ?? DateTime.MinValue;
            EndDate   = currentSeasonCI.GetScheduledEndAsync().Result ?? DateTime.MinValue;
            Coverage  = currentSeasonCI.GetSeasonCoverageAsync().Result == null
                ? null
                : new SeasonCoverage(currentSeasonCI.GetSeasonCoverageAsync().Result);
            Groups = currentSeasonCI.GetGroupsAsync(cultureInfos).Result == null
                ? null
                : currentSeasonCI.GetGroupsAsync(cultureInfos).Result.Select(s =>
                                                                             new Group(s, cultureInfos, _sportEntityFactory, competitorsReferenceIds));
            CurrentRound = currentSeasonCI.GetCurrentRoundAsync(cultureInfos).Result == null
                ? null
                : new Round(currentSeasonCI.GetCurrentRoundAsync(cultureInfos).Result, cultureInfos);
            Competitors = currentSeasonCI.GetCompetitorsAsync(cultureInfos).Result == null
                ? null
                : currentSeasonCI.GetCompetitorsAsync(cultureInfos).Result.Select(s =>
                                                                                  _sportEntityFactory.BuildCompetitor(s, cultureInfos, competitorsReferenceIds));
            Schedule = currentSeasonCI.GetScheduleAsync(cultureInfos).Result == null
                ? null
                : currentSeasonCI.GetScheduleAsync(cultureInfos).Result.Select(s =>
                                                                               _sportEntityFactory.BuildSportEvent <ISportEvent>(s, null, cultureInfos, exceptionStrategy));
        }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Group"/> class
        /// </summary>
        /// <param name="ci">A <see cref="GroupCI"/> used to create new instance</param>
        /// <param name="cultures">A culture of the current instance of <see cref="GroupDTO"/></param>
        /// <param name="sportEntityFactory">A <see cref="ISportEntityFactory"/> used to retrieve <see cref="IPlayerProfile"/></param>
        /// <param name="exceptionStrategy">The exception strategy</param>
        /// <param name="competitorsReferenceIds">A list of <see cref="ReferenceIdCI"/> for all competitors</param>
        public Group(GroupCI ci,
                     IEnumerable <CultureInfo> cultures,
                     ISportEntityFactory sportEntityFactory,
                     ExceptionHandlingStrategy exceptionStrategy,
                     IDictionary <URN, ReferenceIdCI> competitorsReferenceIds)
        {
            Guard.Argument(ci, nameof(ci)).NotNull();

            Id   = ci.Id;
            Name = ci.Name;
            if (ci.CompetitorsIds != null)
            {
                _competitors = ci.CompetitorsIds.Select(t => sportEntityFactory.BuildCompetitor(t, cultures, competitorsReferenceIds, exceptionStrategy)).ToList();
            }
        }
        /// <summary>
        /// Asynchronously gets a <see cref="ICompetitor"/>
        /// </summary>
        /// <param name="id">A <see cref="URN"/> specifying the id for which <see cref="ICompetitor"/> to be retrieved</param>
        /// <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 <see cref="ICompetitor"/> representing the specified competitor or a null reference</returns>
        public async Task <ICompetitor> GetCompetitorAsync(URN id, CultureInfo culture = null)
        {
            var cs = culture == null ? _defaultCultures : new[] { culture };
            var s  = cs.Aggregate(string.Empty, (current, cultureInfo) => current + (";" + cultureInfo.TwoLetterISOLanguageName));

            s = s.Substring(1);

            Log.LogInformation($"Invoked GetCompetitorAsync: [Id={id}, Cultures={s}].");

            var cacheItem = await _profileCache.GetCompetitorProfileAsync(id, cs).ConfigureAwait(false);

            return(cacheItem == null
                       ? null
                       : _sportEntityFactory.BuildCompetitor(cacheItem, cs, (ICompetitionCI)null));
        }
示例#7
0
        /// <summary>
        /// Asynchronously gets the list of competitors
        /// </summary>
        /// <value>The list of competitors</value>
        public async Task <IEnumerable <ICompetitor> > GetCompetitorsAsync()
        {
            var seasonCI = (ITournamentInfoCI)_sportEventCache.GetEventCacheItem(Id);

            if (seasonCI == null)
            {
                ExecutionLogPrivate.Debug($"Missing data. No tournament cache item for id={Id}.");
                return(null);
            }
            var item = ExceptionStrategy == ExceptionHandlingStrategy.THROW
                ? await seasonCI.GetCompetitorsAsync(Cultures).ConfigureAwait(false)
                : await new Func <IEnumerable <CultureInfo>, Task <IEnumerable <CompetitorCI> > >(seasonCI.GetCompetitorsAsync).SafeInvokeAsync(Cultures, ExecutionLog, GetFetchErrorMessage("Competitors")).ConfigureAwait(false);

            var competitorsReferences = await seasonCI.GetCompetitorsReferencesAsync().ConfigureAwait(false);

            return(item?.Select(s => _sportEntityFactory.BuildCompetitor(s, Cultures, competitorsReferences)));
        }