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); } }
/// <summary> /// Initializes new TeamCompetitorCI instance /// </summary> /// <param name="competitor">A <see cref="TeamCompetitorDTO"/> to be used to construct new instance</param> /// <param name="culture">A culture to be used to construct new instance</param> /// <param name="dataRouterManager">The <see cref="IDataRouterManager"/> used to fetch missing data</param> public TeamCompetitorCI(TeamCompetitorDTO competitor, CultureInfo culture, IDataRouterManager dataRouterManager) : base(competitor, culture, dataRouterManager) { Contract.Requires(competitor != null); Contract.Requires(culture != null); Merge(competitor, culture); }
/// <summary> /// Initializes new TeamCompetitorCI instance /// </summary> /// <param name="competitor">A <see cref="TeamCompetitorDTO"/> to be used to construct new instance</param> /// <param name="culture">A culture to be used to construct new instance</param> /// <param name="dataRouterManager">The <see cref="IDataRouterManager"/> used to fetch missing data</param> public TeamCompetitorCI(TeamCompetitorDTO competitor, CultureInfo culture, IDataRouterManager dataRouterManager) : base(competitor, culture, dataRouterManager) { Guard.Argument(competitor, nameof(competitor)).NotNull(); Guard.Argument(culture, nameof(culture)).NotNull(); Merge(competitor, culture); }
/// <summary> /// Merges the specified <see cref="TeamCompetitorDTO"/> into instance /// </summary> /// <param name="competitor">The <see cref="TeamCompetitorDTO"/> used for merge</param> /// <param name="culture">The culture of the input <see cref="TeamCompetitorDTO"/></param> internal void Merge(TeamCompetitorDTO competitor, CultureInfo culture) { Contract.Requires(competitor != null); Contract.Requires(culture != null); base.Merge(competitor, culture); Qualifier = competitor.Qualifier; Division = competitor.Division; }
/// <summary> /// Merges the specified <see cref="TeamCompetitorDTO"/> into instance /// </summary> /// <param name="competitor">The <see cref="TeamCompetitorDTO"/> used for merge</param> /// <param name="culture">The culture of the input <see cref="TeamCompetitorDTO"/></param> internal void Merge(TeamCompetitorDTO competitor, CultureInfo culture) { Guard.Argument(competitor, nameof(competitor)).NotNull(); Guard.Argument(culture, nameof(culture)).NotNull(); base.Merge(competitor, culture); Qualifier = competitor.Qualifier; Division = competitor.Division; }
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); } } }
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")); }
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); } }
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); }