Exemplo n.º 1
0
 private void AddTeamCompetitor(URN id, TeamCompetitorDTO item, CultureInfo culture, bool useSemaphore)
 {
     if (_cache.Contains(id.ToString()))
     {
         try
         {
             var ci     = (CompetitorCI)_cache.Get(id.ToString());
             var teamCI = ci as TeamCompetitorCI;
             if (teamCI != null)
             {
                 if (useSemaphore)
                 {
                     _semaphoreCacheMerge.Wait();
                 }
                 teamCI.Merge(item, culture);
             }
             else
             {
                 if (useSemaphore)
                 {
                     _semaphoreCacheMerge.Wait();
                 }
                 teamCI = new TeamCompetitorCI(ci);
                 teamCI.Merge(item, culture);
                 _cache.Set(id.ToString(), teamCI, GetCorrectCacheItemPolicy(id));
             }
         }
         catch (Exception ex)
         {
             ExecutionLog.Error(
                 $"Error adding team competitor for id={id}, dto type={item?.GetType().Name} and lang={culture.TwoLetterISOLanguageName}.",
                 ex);
         }
     }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TeamCompetitor"/> class
 /// </summary>
 /// <param name="ci">A <see cref="TeamCompetitorCI"/> used to create new instance</param>
 /// <param name="culture">A culture of the current instance of <see cref="TeamCompetitorCI"/></param>
 /// <param name="sportEntityFactory">A <see cref="ISportEntityFactory"/> used to retrieve <see cref="IPlayer"/></param>
 /// <param name="profileCache">A <see cref="IProfileCache"/> used for fetching profile data</param>
 /// <param name="rootCompetitionCI">A root <see cref="CompetitionCI"/> to which this competitor belongs to</param>
 public TeamCompetitor(TeamCompetitorCI ci,
                       IEnumerable <CultureInfo> culture,
                       ISportEntityFactory sportEntityFactory,
                       IProfileCache profileCache,
                       ICompetitionCI rootCompetitionCI)
     : base(ci, profileCache, culture, sportEntityFactory, rootCompetitionCI)
 {
     Division = ci.Division;
 }
Exemplo n.º 3
0
        private void AddTeamCompetitor(URN id, TeamCompetitorDTO item, CultureInfo culture, bool useSemaphore)
        {
            if (_cache.Contains(id.ToString()))
            {
                try
                {
                    var ci     = (CompetitorCI)_cache.Get(id.ToString());
                    var teamCI = ci as TeamCompetitorCI;
                    if (teamCI != null)
                    {
                        if (useSemaphore)
                        {
                            WaitTillIdIsAvailable(_mergeUrns, id);
                        }
                        teamCI.Merge(item, culture);
                    }
                    else
                    {
                        if (useSemaphore)
                        {
                            WaitTillIdIsAvailable(_mergeUrns, id);
                        }
                        teamCI = new TeamCompetitorCI(ci);
                        teamCI.Merge(item, culture);
                        _cache.Set(id.ToString(), teamCI, GetCorrectCacheItemPolicy(id));
                    }
                }
                catch (Exception ex)
                {
                    ExecutionLog.Error($"Error adding team competitor for id={id}, dto type={item?.GetType().Name} and lang={culture.TwoLetterISOLanguageName}.", ex);
                }
                finally
                {
                    if (useSemaphore)
                    {
                        if (!_isDisposed)
                        {
                            ReleaseId(_mergeUrns, id);
                        }
                    }
                }
            }
            else
            {
                var teamCompetitor = new TeamCompetitorCI(item, culture, _dataRouterManager);
                _cache.Add(id.ToString(), teamCompetitor, GetCorrectCacheItemPolicy(id));
            }

            if (item?.Players != null && item.Players.Any())
            {
                foreach (var player in item.Players)
                {
                    AddPlayerCompetitor(player, item.Id, culture, false);
                }
            }
        }
Exemplo n.º 4
0
        public void TeamCompetitorDTOMappingTest()
        {
            var msg = RMF.GetTeamCompetitor();
            var dto = new TeamCompetitorDTO(msg);

            var ci = new TeamCompetitorCI(dto, new CultureInfo("en"), new TestDataRouterManager(new CacheManager()));

            ValidateTeamCompetitor(msg, dto);
            ValidateTeamCompetitor(msg, ci, new CultureInfo("en"));
        }
Exemplo n.º 5
0
 private static void ValidateTeamCompetitor(teamCompetitor msg, TeamCompetitorCI ci, CultureInfo culture)
 {
     Assert.AreEqual(msg.id, ci.Id.ToString());
     Assert.AreEqual(msg.name, ci.GetName(culture));
     Assert.AreEqual(msg.abbreviation, ci.GetAbbreviation(culture));
     Assert.AreEqual(msg.country, ci.GetCountry(culture));
     Assert.AreEqual(msg.@virtual, ci.IsVirtual);
     Assert.AreEqual(msg.qualifier, ci.Qualifier);
     Assert.AreEqual(msg.divisionSpecified, ci.Division.HasValue);
     Assert.AreEqual(msg.division, ci.Division);
 }
        private async Task AddTeamCompetitorAsync(URN id, TeamCompetitorDTO item, CultureInfo culture, bool useSemaphore)
        {
            if (_cache.Contains(id.ToString()))
            {
                try
                {
                    var ci     = (CompetitorCI)_cache.Get(id.ToString());
                    var teamCI = ci == null ? (TeamCompetitorCI)_cache.Get(id.ToString()) : ci as TeamCompetitorCI;
                    if (teamCI != null)
                    {
                        if (useSemaphore)
                        {
                            await WaitTillIdIsAvailableAsync(_mergeUrns, id).ConfigureAwait(false);
                        }
                        teamCI.Merge(item, culture);
                    }
                    else
                    {
                        if (useSemaphore)
                        {
                            await WaitTillIdIsAvailableAsync(_mergeUrns, id).ConfigureAwait(false);
                        }
                        teamCI = new TeamCompetitorCI(ci);
                        teamCI.Merge(item, culture);
                        _cache.Set(id.ToString(), teamCI, GetCorrectCacheItemPolicy(id));
                    }
                }
                catch (Exception ex)
                {
                    ExecutionLog.LogError(ex, $"Error adding team competitor for id={id}, dto type={item?.GetType().Name} and lang={culture.TwoLetterISOLanguageName}.");
                }
                finally
                {
                    if (useSemaphore && !_isDisposed)
                    {
                        await ReleaseIdAsync(_mergeUrns, id).ConfigureAwait(false);
                    }
                }
            }
            else
            {
                var teamCompetitor = new TeamCompetitorCI(item, culture, _dataRouterManager);
                _cache.Add(id.ToString(), teamCompetitor, GetCorrectCacheItemPolicy(id));
            }

            if (item?.Players != null && item.Players.Any())
            {
                var tasks = item.Players.Select(s => AddPlayerCompetitorAsync(s, item.Id, culture, false));
                await Task.WhenAll(tasks).ConfigureAwait(false);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Builds the instance of the <see cref="ITeamCompetitor"/> class
        /// </summary>
        /// <param name="teamCompetitorId">A <see cref="URN"/> of the <see cref="TeamCompetitorCI"/> used to create new instance</param>
        /// <param name="cultures">A culture of the current instance of <see cref="TeamCompetitorCI"/></param>
        /// <param name="rootCompetitionCI">A root <see cref="CompetitionCI"/> to which this competitor belongs to</param>
        /// <param name="exceptionStrategy">A <see cref="ExceptionHandlingStrategy"/> enum member specifying how the build instance will handle potential exceptions</param>
        /// <returns>The constructed <see cref="ITeamCompetitor"/> instance</returns>
        public async Task <ITeamCompetitor> BuildTeamCompetitorAsync(URN teamCompetitorId, IEnumerable <CultureInfo> cultures, ICompetitionCI rootCompetitionCI, ExceptionHandlingStrategy exceptionStrategy)
        {
            var cultureInfos = cultures.ToList();
            var competitorCI = await _profileCache.GetCompetitorProfileAsync(teamCompetitorId, cultureInfos).ConfigureAwait(false);

            if (competitorCI is TeamCompetitorCI teamCompetitorCI)
            {
                return(BuildTeamCompetitor(teamCompetitorCI, cultureInfos, rootCompetitionCI, exceptionStrategy));
            }
            if (competitorCI != null)
            {
                var teamCI = new TeamCompetitorCI(competitorCI);
                return(BuildTeamCompetitor(teamCI, cultureInfos, rootCompetitionCI, exceptionStrategy));
            }
            return(null);
        }
Exemplo n.º 8
0
        public void TeamCompetitorMergeTest()
        {
            var teamType1 = new teamCompetitor
            {
                abbreviation      = "ABC",
                country           = "Germany",
                id                = "sr:team:1",
                name              = "Team A",
                @virtual          = true,
                virtualSpecified  = true,
                qualifier         = "qua 1",
                divisionSpecified = true,
                division          = 1,
                state             = "state"
            };
            var teamType2 = new teamCompetitor
            {
                abbreviation      = "ABC",
                country           = "Deutschland",
                id                = "sr:team:1",
                name              = "Team A",
                @virtual          = true,
                virtualSpecified  = true,
                qualifier         = "qua 1",
                divisionSpecified = true,
                division          = 1,
                state             = "state"
            };
            var competitorDTO1 = new TeamCompetitorDTO(teamType1);
            var competitorDTO2 = new TeamCompetitorDTO(teamType2);

            var competitorCI = new TeamCompetitorCI(competitorDTO1, _cultureFirst, new TestDataRouterManager(new CacheManager()));

            competitorCI.Merge(competitorDTO2, _cultureSecond);

            Assert.IsNotNull(competitorCI);
            Assert.AreEqual(competitorCI.Id.ToString(), teamType1.id);
            Assert.AreEqual(competitorCI.GetName(_cultureFirst), teamType1.name);
            Assert.AreEqual(competitorCI.GetAbbreviation(_cultureFirst), teamType1.abbreviation);
            Assert.AreEqual(competitorCI.IsVirtual, teamType1.@virtual);
            Assert.AreEqual(competitorCI.Qualifier, teamType1.qualifier);
            Assert.AreEqual(competitorCI.State, teamType1.state);
            Assert.AreEqual(teamType1.country, competitorCI.GetCountry(_cultureFirst));
            Assert.AreEqual(teamType2.country, competitorCI.GetCountry(_cultureSecond));
            Assert.IsNotNull(competitorCI.Division);
            Assert.AreEqual(competitorCI.Division.Value, teamType1.division);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Builds the instance of the <see cref="ITeamCompetitor"/> class
        /// </summary>
        /// <param name="teamCompetitorId">A <see cref="URN"/> of the <see cref="TeamCompetitorCI"/> used to create new instance</param>
        /// <param name="cultures">A culture of the current instance of <see cref="TeamCompetitorCI"/></param>
        /// <param name="rootCompetitionCI">A root <see cref="CompetitionCI"/> to which this competitor belongs to</param>
        /// <returns>The constructed <see cref="ITeamCompetitor"/> instance</returns>
        public async Task <ITeamCompetitor> BuildTeamCompetitorAsync(URN teamCompetitorId, IEnumerable <CultureInfo> cultures, ICompetitionCI rootCompetitionCI)
        {
            var cultureInfos = cultures.ToList();
            var competitorCI = await _profileCache.GetCompetitorProfileAsync(teamCompetitorId, cultureInfos).ConfigureAwait(false);

            var teamCompetitorCI = competitorCI as TeamCompetitorCI;

            if (teamCompetitorCI != null)
            {
                return(BuildTeamCompetitor(teamCompetitorCI, cultureInfos, rootCompetitionCI));
            }
            if (competitorCI != null)
            {
                ExecutionLog.LogWarning($"Transforming CompetitorCI to TeamCompetitorCI for {teamCompetitorId}");
                var teamCI = new TeamCompetitorCI(competitorCI);
                return(BuildTeamCompetitor(teamCI, cultureInfos, rootCompetitionCI));
            }
            return(null);
        }
Exemplo n.º 10
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]);
        }
        private async Task AddTeamCompetitorAsync(ExportableTeamCompetitorCI item)
        {
            if (_cache.Contains(item.Id))
            {
                var itemId = URN.Parse(item.Id);
                try
                {
                    var ci     = (CompetitorCI)_cache.Get(item.Id);
                    var teamCI = ci == null ? (TeamCompetitorCI)_cache.Get(item.Id) : ci as TeamCompetitorCI;
                    if (teamCI != null)
                    {
                        await WaitTillIdIsAvailableAsync(_mergeUrns, itemId).ConfigureAwait(false);

                        teamCI.Import(item);
                    }
                    else
                    {
                        await WaitTillIdIsAvailableAsync(_mergeUrns, itemId).ConfigureAwait(false);

                        teamCI = new TeamCompetitorCI(ci);
                        teamCI.Import(item);
                        _cache.Set(item.Id, teamCI, GetCorrectCacheItemPolicy(URN.Parse(item.Id)));
                    }
                }
                catch (Exception ex)
                {
                    ExecutionLog.LogError(ex, $"Error importing team competitor for id={item.Id}.");
                }
                finally
                {
                    if (!_isDisposed)
                    {
                        await ReleaseIdAsync(_mergeUrns, itemId).ConfigureAwait(false);
                    }
                }
            }
            else
            {
                _cache.Add(item.Id, new TeamCompetitorCI(item, _dataRouterManager), GetCorrectCacheItemPolicy(URN.Parse(item.Id)));
            }
        }
Exemplo n.º 12
0
 private void AddTeamCompetitor(ExportableTeamCompetitorCI item)
 {
     if (_cache.Contains(item.Id))
     {
         var itemId = URN.Parse(item.Id);
         try
         {
             var competitorCI = (CompetitorCI)_cache.Get(item.Id);
             var teamCI       = competitorCI as TeamCompetitorCI;
             if (teamCI != null)
             {
                 WaitTillIdIsAvailable(_mergeUrns, itemId);
                 teamCI.Import(item);
             }
             else
             {
                 WaitTillIdIsAvailable(_mergeUrns, itemId);
                 teamCI = new TeamCompetitorCI(competitorCI);
                 teamCI.Import(item);
                 _cache.Set(item.Id, teamCI, GetCorrectCacheItemPolicy(URN.Parse(item.Id)));
             }
         }
         catch (Exception ex)
         {
             ExecutionLog.Error($"Error importing team competitor for id={item.Id}.", ex);
         }
         finally
         {
             if (!_isDisposed)
             {
                 ReleaseId(_mergeUrns, itemId);
             }
         }
     }
     else
     {
         _cache.Add(item.Id, new TeamCompetitorCI(item, _dataRouterManager), GetCorrectCacheItemPolicy(URN.Parse(item.Id)));
     }
 }
Exemplo n.º 13
0
 private void AddTeamCompetitor(ExportableTeamCompetitorCI item)
 {
     if (_cache.Contains(item.Id))
     {
         try
         {
             var ci     = (CompetitorCI)_cache.Get(item.Id);
             var teamCI = ci as TeamCompetitorCI;
             if (teamCI != null)
             {
                 _semaphoreCacheMerge.Wait();
                 teamCI.Import(item);
             }
             else
             {
                 _semaphoreCacheMerge.Wait();
                 teamCI = new TeamCompetitorCI(ci);
                 teamCI.Import(item);
                 _cache.Set(item.Id, teamCI, GetCorrectCacheItemPolicy(URN.Parse(item.Id)));
             }
         }
         catch (Exception ex)
         {
             ExecutionLog.LogError($"Error importing team competitor for id={item.Id}.", ex);
         }
         finally
         {
             if (!_isDisposed)
             {
                 _semaphoreCacheMerge.Release();
             }
         }
     }
     else
     {
         _cache.Add(item.Id, new TeamCompetitorCI(item, _dataRouterManager), GetCorrectCacheItemPolicy(URN.Parse(item.Id)));
     }
 }
 public ITeamCompetitor BuildTeamCompetitor(TeamCompetitorCI teamCompetitorCI, IEnumerable <CultureInfo> cultures, ICompetitionCI rootCompetitionCI, ExceptionHandlingStrategy exceptionStrategy)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 15
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);
            }
        }
Exemplo n.º 16
0
 public ITeamCompetitor BuildTeamCompetitor(TeamCompetitorCI ci, IEnumerable <CultureInfo> cultures, ICompetitionCI rootCompetitionCI)
 {
     return(new TeamCompetitor(ci, cultures, this, _profileCache, rootCompetitionCI));
 }
Exemplo n.º 17
0
 public ITeamCompetitor BuildTeamCompetitor(TeamCompetitorCI ci, IEnumerable <CultureInfo> culture, ICompetitionCI rootCompetitionCI)
 {
     throw new NotImplementedException();
 }
 public ITeamCompetitor BuildTeamCompetitor(TeamCompetitorCI teamCompetitorCI, IEnumerable <CultureInfo> cultures, ICompetitionCI rootCompetitionCI, ExceptionHandlingStrategy exceptionStrategy)
 {
     return(new TeamCompetitor(teamCompetitorCI, cultures, this, exceptionStrategy, _profileCache, rootCompetitionCI));
 }