Beispiel #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);
         }
     }
        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);
                }
            }
        }
        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);
            }
        }
Beispiel #4
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);
        }
Beispiel #5
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.Merge(new TeamCompetitorCI(item, _dataRouterManager));
             }
             else
             {
                 _semaphoreCacheMerge.Wait();
                 teamCI = new TeamCompetitorCI(ci);
                 teamCI.Merge(new TeamCompetitorCI(item, _dataRouterManager));
                 _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)
             {
                 _semaphoreCacheMerge.Release();
             }
         }
     }
     else
     {
         _cache.Add(item.Id, new TeamCompetitorCI(item, _dataRouterManager), GetCorrectCacheItemPolicy(URN.Parse(item.Id)));
     }
 }