コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TournamentInfoCI"/> class
 /// </summary>
 /// <param name="exportable">A <see cref="ExportableTournamentInfoCI" /> specifying the current instance</param>
 /// <param name="dataRouterManager">The <see cref="IDataRouterManager"/> used to obtain summary and fixture</param>
 /// <param name="semaphorePool">A <see cref="ISemaphorePool" /> instance used to obtain sync objects</param>
 /// <param name="defaultCulture">A <see cref="CultureInfo" /> specifying the language used when fetching info which is not translatable (e.g. Scheduled, ..)</param>
 /// <param name="fixtureTimestampCache">A <see cref="MemoryCache"/> used to cache the sport events fixture timestamps</param>
 public TournamentInfoCI(ExportableTournamentInfoCI exportable,
                         IDataRouterManager dataRouterManager,
                         ISemaphorePool semaphorePool,
                         CultureInfo defaultCulture,
                         MemoryCache fixtureTimestampCache)
     : base(exportable, dataRouterManager, semaphorePool, defaultCulture, fixtureTimestampCache)
 {
     _categoryId         = exportable.CategoryId == null ? null : URN.Parse(exportable.CategoryId);
     _tournamentCoverage = exportable.TournamentCoverage != null
         ? new TournamentCoverageCI(exportable.TournamentCoverage)
         : null;
     _competitors       = exportable.Competitors?.Select(c => new CompetitorCI(c, dataRouterManager)).ToList();
     _currentSeasonInfo = exportable.CurrentSeasonInfo != null
         ? new CurrentSeasonInfoCI(exportable.CurrentSeasonInfo, dataRouterManager)
         : null;
     _groups              = exportable.Groups?.Select(g => new GroupCI(g, dataRouterManager)).ToList();
     _scheduleUrns        = exportable.ScheduleUrns?.Select(URN.Parse).ToList();
     _round               = exportable.Round != null ? new RoundCI(exportable.Round) : null;
     _year                = exportable.Year;
     _tournamentInfoBasic = exportable.TournamentInfoBasic != null
         ? new TournamentInfoBasicCI(exportable.TournamentInfoBasic, dataRouterManager)
         : null;
     _referenceId    = exportable.ReferenceId != null ? new ReferenceIdCI(exportable.ReferenceId) : null;
     _seasonCoverage = exportable.SeasonCoverage != null
         ? new SeasonCoverageCI(exportable.SeasonCoverage)
         : null;
     _seasons               = exportable.Seasons?.Select(URN.Parse).ToList();
     _loadedSeasons         = new List <CultureInfo>(exportable.LoadedSeasons ?? new List <CultureInfo>());
     _loadedSchedules       = new List <CultureInfo>(exportable.LoadedSchedules ?? new List <CultureInfo>());
     _competitorsReferences =
         exportable.CompetitorsReferences?.ToDictionary(c => URN.Parse(c.Key), c => new ReferenceIdCI(c.Value));
     _exhibitionGames = exportable.ExhibitionGames;
 }
コード例 #2
0
        /// <summary>
        /// Merges the specified event summary
        /// </summary>
        /// <param name="eventSummary">The event summary</param>
        /// <param name="culture">The culture</param>
        private void ActualMerge(MatchDTO eventSummary, CultureInfo culture)
        {
            base.Merge(eventSummary, culture, false);

            if (eventSummary.Season != null)
            {
                if (_season == null)
                {
                    _season = new CacheItem(eventSummary.Season.Id, eventSummary.Season.Name, culture);
                }
                else
                {
                    _season.Merge(eventSummary.Season, culture);
                }
            }
            if (eventSummary.Round != null)
            {
                if (_tournamentRound == null)
                {
                    _tournamentRound = new RoundCI(eventSummary.Round, culture);
                }
                else
                {
                    _tournamentRound.Merge(eventSummary.Round, culture);
                }
            }
            if (eventSummary.Tournament != null)
            {
                _tournamentId = eventSummary.Tournament.Id;
            }
        }
コード例 #3
0
        /// <summary>
        /// Merges the specified event summary
        /// </summary>
        /// <param name="eventSummary">The event summary</param>
        /// <param name="culture">The culture</param>
        private void ActualMerge(MatchDTO eventSummary, CultureInfo culture)
        {
            base.Merge(eventSummary, culture, false);

            if (eventSummary.Season != null)
            {
                if (_season == null)
                {
                    _season = new SeasonCI(eventSummary.Season, culture);
                }
                else
                {
                    _season.Merge(eventSummary.Season, culture);
                }
            }
            if (eventSummary.Round != null)
            {
                if (_tournamentRound == null)
                {
                    _tournamentRound = new RoundCI(eventSummary.Round, culture);
                }
                else
                {
                    _tournamentRound.Merge(eventSummary.Round, culture);
                }
            }
            if (eventSummary.Tournament != null)
            {
                _tournamentId = eventSummary.Tournament.Id;
            }
            if (eventSummary.Coverage != null)
            {
                _coverageInfo = new CoverageInfoCI(eventSummary.Coverage);
            }
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MatchCI"/> class
 /// </summary>
 /// <param name="exportable">A <see cref="ExportableMatchCI" /> specifying the current instance</param>
 /// <param name="dataRouterManager">The <see cref="IDataRouterManager"/> used to obtain summary and fixture</param>
 /// <param name="semaphorePool">A <see cref="ISemaphorePool" /> instance used to obtain sync objects</param>
 /// <param name="defaultCulture">A <see cref="CultureInfo" /> specifying the language used when fetching info which is not translatable (e.g. Scheduled, ..)</param>
 /// <param name="fixtureTimestampCache">A <see cref="MemoryCache"/> used to cache the sport events fixture timestamps</param>
 public MatchCI(ExportableMatchCI exportable,
     IDataRouterManager dataRouterManager,
     ISemaphorePool semaphorePool,
     CultureInfo defaultCulture,
     MemoryCache fixtureTimestampCache)
     : base(exportable, dataRouterManager, semaphorePool, defaultCulture, fixtureTimestampCache)
 {
     _season = exportable.Season != null ? new CacheItem(exportable.Season) : null;
     _tournamentRound = exportable.TournamentRound != null ? new RoundCI(exportable.TournamentRound) : null;
     _tournamentId = exportable.TournamentId != null ? URN.Parse(exportable.TournamentId) : null;
     _fixture = exportable.Fixture != null ? new Fixture(exportable.Fixture) : null;
     _eventTimeline = exportable.EventTimeline != null ? new EventTimelineCI(exportable.EventTimeline) : null;
     _delayedInfo = exportable.DelayedInfo != null ? new DelayedInfoCI(exportable.DelayedInfo) : null;
 }
コード例 #5
0
        private static void ValidateSportEventCacheItem(IMatchCI item, bool ignoreDate = false)
        {
            Assert.IsNotNull(item, "Cached item not found.");
            Assert.AreEqual(TestData.EventId, item.Id);
            var              date        = new DateTime?();
            List <URN>       competitors = null;
            TeamCompetitorCI comp        = null;
            RoundCI          round       = null;
            SeasonCI         season      = null;

            Task.Run(async() =>
            {
                date        = await item.GetScheduledAsync();
                competitors = (await item.GetCompetitorsIdsAsync(TestData.Cultures)).ToList();
                //comp = competitors.FirstOrDefault();
                round  = await item.GetTournamentRoundAsync(TestData.Cultures);
                season = await item.GetSeasonAsync(TestData.Cultures);
            }).GetAwaiter().GetResult();

            if (!ignoreDate)
            {
                if (date != null)
                {
                    Assert.AreEqual(new DateTime(2016, 08, 10), new DateTime(date.Value.Year, date.Value.Month, date.Value.Day));
                }
            }

            Assert.AreEqual(2, competitors.Count);

            //TODO - this was removed
            if (comp != null)
            {
                Assert.AreEqual("sr:competitor:66390", comp.Id.ToString());
                Assert.AreEqual(@"Pericos de Puebla", comp.GetName(TestData.Culture));
                Assert.AreEqual("Mexico", comp.GetCountry(TestData.Culture));
                Assert.AreNotEqual(comp.GetCountry(TestData.Culture), comp.GetCountry(new CultureInfo("de")));
            }
            Assert.IsTrue(string.IsNullOrEmpty(round.GetName(TestData.Culture)));

            Assert.AreEqual(3, season.Names.Count);
            Assert.AreEqual("Mexican League 2016", season.Names[TestData.Culture]);
        }
コード例 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Round"/> class
        /// </summary>
        /// <param name="ci">A <see cref="RoundCI"/> used to create new instance</param>
        /// <param name="cultures">A cultures of the current instance of <see cref="RoundCI"/></param>
        public Round(RoundCI ci, IEnumerable <CultureInfo> cultures)
        {
            Contract.Requires(ci != null);

            Type                 = ci.Type;
            Number               = ci.Number;
            GroupName            = ci.Group;
            GroupId              = ci.GroupId;
            OtherMatchId         = ci.OtherMatchId;
            CupRoundMatches      = ci.CupRoundMatches;
            CupRoundMatchNumber  = ci.CupRoundMatchNumber;
            Name                 = new Dictionary <CultureInfo, string>();
            PhaseOrGroupLongName = new Dictionary <CultureInfo, string>();
            foreach (var c in cultures)
            {
                Name.Add(c, ci.GetName(c));
                PhaseOrGroupLongName.Add(c, ci.GetPhaseOrGroupLongName(c));
            }
            BetradarId = ci.BetradarId ?? 0;
            Phase      = ci.Phase;
        }
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Round"/> class
        /// </summary>
        /// <param name="ci">A <see cref="RoundCI"/> used to create new instance</param>
        /// <param name="cultures">A cultures of the current instance of <see cref="RoundCI"/></param>
        public Round(RoundCI ci, IEnumerable <CultureInfo> cultures)
        {
            Guard.Argument(ci, nameof(ci)).NotNull();

            Type                 = ci.Type;
            Number               = ci.Number;
            GroupName            = ci.Group;
            GroupId              = ci.GroupId;
            OtherMatchId         = ci.OtherMatchId;
            CupRoundMatches      = ci.CupRoundMatches;
            CupRoundMatchNumber  = ci.CupRoundMatchNumber;
            Name                 = new Dictionary <CultureInfo, string>();
            PhaseOrGroupLongName = new Dictionary <CultureInfo, string>();
            foreach (var c in cultures)
            {
                Name.Add(c, ci.GetName(c));
                PhaseOrGroupLongName.Add(c, ci.GetPhaseOrGroupLongName(c));
            }
            BetradarId = ci.BetradarId ?? 0;
            Phase      = ci.Phase;
        }
コード例 #8
0
        public void RoundMergeTest()
        {
            var matchRoundTypeEn = new matchRound
            {
                name = "round name in english",
                cup_round_match_number          = 1,
                cup_round_match_numberSpecified = true,
                cup_round_matches          = 2,
                cup_round_matchesSpecified = true,
                number          = 10,
                numberSpecified = true,
                type            = "match type 1",
            };

            var matchRoundTypeDe = new matchRound
            {
                name = "round name in deutsch",
                cup_round_match_number          = 1,
                cup_round_match_numberSpecified = true,
                cup_round_matches          = 2,
                cup_round_matchesSpecified = true,
                number          = 10,
                numberSpecified = true,
                type            = "match type 1",
            };

            var roundDTO1 = new RoundDTO(matchRoundTypeEn);
            var roundDTO2 = new RoundDTO(matchRoundTypeDe);
            var roundCI   = new RoundCI(roundDTO1, _cultureFirst);

            roundCI.Merge(roundDTO2, _cultureSecond);

            Assert.IsNotNull(roundCI);
            Assert.AreEqual(matchRoundTypeEn.name, roundCI.GetName(_cultureFirst));
            Assert.AreEqual(matchRoundTypeDe.name, roundCI.GetName(_cultureSecond));
            Assert.AreEqual(matchRoundTypeEn.cup_round_match_number, roundCI.CupRoundMatchNumber);
            Assert.AreEqual(matchRoundTypeEn.cup_round_matches, roundCI.CupRoundMatches);
            Assert.AreEqual(matchRoundTypeEn.number, roundCI.Number);
            Assert.AreEqual(matchRoundTypeEn.type, roundCI.Type);
        }
コード例 #9
0
        public static void ValidateTestEventId(MatchCI ci, IEnumerable <CultureInfo> cultures, bool canHaveOtherLanguage)
        {
            Assert.IsNotNull(ci, "Cached item not found.");
            Assert.AreEqual(EventId, ci.Id);
            if (cultures == null)
            {
                Assert.IsNull(ci);
            }

            var      date   = new DateTime?();
            RoundCI  round  = null;
            SeasonCI season = null;

            var cultureInfos = cultures.ToList();
            var cStr         = string.Join(",", cultureInfos);
            var lStr         = string.Join(",", ci.LoadedSummaries);

            Assert.IsTrue(ci.HasTranslationsFor(cultureInfos), $"Culture missing: {cStr}, loaded summaries: {lStr}");
            if (!canHaveOtherLanguage)
            {
                Assert.IsTrue(ci.LoadedSummaries.Count >= cultureInfos.Count || ci.LoadedFixtures.Count >= cultureInfos.Count);
            }
            foreach (var culture in cultureInfos)
            {
                var checkCulture = new[] { culture };
                Task.Run(async() =>
                {
                    date   = await ci.GetScheduledAsync();
                    round  = await ci.GetTournamentRoundAsync(checkCulture);
                    season = await ci.GetSeasonAsync(checkCulture);
                }).GetAwaiter().GetResult();

                Debug.Assert(date != null, "date != null");
                Assert.AreEqual(new DateTime(2016, 08, 10), new DateTime(date.Value.Year, date.Value.Month, date.Value.Day));

                Assert.IsTrue(string.IsNullOrEmpty(round.GetName(culture)));

                Assert.IsTrue(Math.Max(ci.LoadedSummaries.Count, ci.LoadedFixtures.Count) >= season.Names.Count);
            }
        }
コード例 #10
0
        internal static void ValidateTestEventId(MatchCI ci, IEnumerable <CultureInfo> cultures, bool canHaveOtherLanguage)
        {
            Assert.IsNotNull(ci, "Cached item not found.");
            Assert.AreEqual(EventId, ci.Id);
            if (cultures == null)
            {
                Assert.IsNull(ci);
            }

            var date = new DateTime?();
            List <TeamCompetitorCI> competitors = null;
            TeamCompetitorCI        comp        = null;
            RoundCI   round  = null;
            CacheItem season = null;

            var cultureInfos = cultures.ToList();
            var cStr         = string.Join(",", cultureInfos);
            var lStr         = string.Join(",", ci.LoadedSummaries);

            Assert.IsTrue(ci.HasTranslationsFor(cultureInfos), $"Culture missing: {cStr}, loaded summaries: {lStr}");
            if (!canHaveOtherLanguage)
            {
                Assert.IsTrue(ci.LoadedSummaries.Count >= cultureInfos.Count || ci.LoadedFixtures.Count >= cultureInfos.Count);
            }
            foreach (var culture in cultureInfos)
            {
                var checkCulture = new[] { culture };
                Task.Run(async() =>
                {
                    date = await ci.GetScheduledAsync();
                    //competitors = (await ci.GetCompetitorsAsync(checkCulture)).ToList();
                    // ReSharper disable once AssignNullToNotNullAttribute
                    //comp = competitors.FirstOrDefault();
                    round  = await ci.GetTournamentRoundAsync(checkCulture);
                    season = await ci.GetSeasonAsync(checkCulture);
                }).GetAwaiter().GetResult();

                Debug.Assert(date != null, "date != null");
                Assert.AreEqual(new DateTime(2016, 08, 10), new DateTime(date.Value.Year, date.Value.Month, date.Value.Day));

                //Assert.AreEqual(2, competitors.Count);

                //TODO - this was removed
                if (comp != null)
                {
                    Assert.AreEqual("sr:competitor:66390", comp.Id.ToString());
                    Assert.AreEqual(@"Pericos de Puebla", comp.GetName(culture));
                    if (Equals(culture, Culture))
                    {
                        Assert.AreEqual("Mexico", comp.GetCountry(culture));
                        Assert.AreEqual("Mexican League 2016", season.Name[culture]);
                    }
                    if (culture.TwoLetterISOLanguageName != "de")
                    {
                        Assert.AreNotEqual(comp.GetCountry(culture), comp.GetCountry(new CultureInfo("de")));
                    }
                }
                Assert.IsTrue(string.IsNullOrEmpty(round.GetName(culture)));

                Assert.IsTrue(Math.Max(ci.LoadedSummaries.Count, ci.LoadedFixtures.Count) >= season.Name.Count);
            }
        }
コード例 #11
0
        /// <summary>
        /// Merges the specified dto
        /// </summary>
        /// <param name="dto">The dto</param>
        /// <param name="culture">The culture</param>
        private void ActualMerge(TournamentInfoDTO dto, CultureInfo culture)
        {
            base.Merge(dto, culture, false);

            if (dto.Category != null)
            {
                _categoryId = dto.Category.Id;
            }
            if (dto.TournamentCoverage != null)
            {
                _tournamentCoverage = new TournamentCoverageCI(dto.TournamentCoverage);
            }
            if (dto.Competitors != null)
            {
                if (_competitors == null)
                {
                    _competitors = new List <CompetitorCI>(dto.Competitors.Select(t => new CompetitorCI(t, culture, DataRouterManager)));
                }
                else
                {
                    MergeCompetitors(dto.Competitors, culture);
                }
                FillCompetitorsReferences(dto.Competitors);
            }
            if (dto.CurrentSeason != null)
            {
                if (_currentSeasonInfo == null)
                {
                    _currentSeasonInfo = new CurrentSeasonInfoCI(dto.CurrentSeason, culture, DataRouterManager);
                }
                else
                {
                    _currentSeasonInfo.Merge(dto.CurrentSeason, culture);
                }
            }
            if (dto.Groups != null)
            {
                if (_groups == null)
                {
                    _groups = new List <GroupCI>(dto.Groups.Select(s => new GroupCI(s, culture, DataRouterManager)));
                }
                else
                {
                    MergeGroups(dto.Groups, culture);
                }
                var comps = new List <CompetitorDTO>();
                foreach (var groupDTO in dto.Groups)
                {
                    comps.AddRange(groupDTO.Competitors);
                }
                FillCompetitorsReferences(comps);
            }
            if (dto.Schedule != null)
            {
                _scheduleUrns = new ReadOnlyCollection <URN>(dto.Schedule.Select(s => s.Id).ToList());
            }
            if (dto.CurrentRound != null)
            {
                if (_round == null)
                {
                    _round = new RoundCI(dto.CurrentRound, culture);
                }
                else
                {
                    _round.Merge(dto.CurrentRound, culture);
                }
            }
            if (!string.IsNullOrEmpty(dto.Year))
            {
                _year = dto.Year;
            }
            if (dto.TournamentInfo != null)
            {
                if (_tournamentInfoBasic == null)
                {
                    _tournamentInfoBasic = new TournamentInfoBasicCI(dto.TournamentInfo, culture, DataRouterManager);
                }
                else
                {
                    _tournamentInfoBasic.Merge(dto.TournamentInfo, culture);
                }
            }
            if (dto.SeasonCoverage != null)
            {
                _seasonCoverage = new SeasonCoverageCI(dto.SeasonCoverage);
            }

            if (dto.ExhibitionGames != null)
            {
                _exhibitionGames = dto.ExhibitionGames;
            }
        }