private async Task GetCompetitorProfileAsync(URN id, CultureInfo culture, ISportEventCI requester) { Debug.Print($"DRM-GetCompetitorProfileAsync for {id} and culture {culture.TwoLetterISOLanguageName} - START"); var filePath = GetFile($"{culture.TwoLetterISOLanguageName}.competitor.{id?.Id ?? 1}.xml", culture); CompetitorProfileDTO dto = null; await ExecuteDelayAsync(id, culture).ConfigureAwait(false); if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath)) { //filePath = GetFile(CompetitorProfileXml, culture); dto = new CompetitorProfileDTO(MessageFactoryRest.GetCompetitorProfileEndpoint(id == null ? 1 : (int)id.Id, StaticRandom.I(15))); } else { var restDeserializer = new Deserializer <competitorProfileEndpoint>(); var mapper = new CompetitorProfileMapperFactory(); var stream = FileHelper.OpenFile(filePath); dto = mapper.CreateMapper(restDeserializer.Deserialize(stream)).Map(); } if (dto != null) { await LogSaveDtoAsync(id, dto, culture, DtoType.CompetitorProfile, requester).ConfigureAwait(false); } Debug.Print($"DRM-GetCompetitorProfileAsync for {id} and culture {culture.TwoLetterISOLanguageName} - END"); }
/// <summary> /// Merges the information from the provided <see cref="CompetitorProfileDTO" /> into the current instance /// </summary> /// <param name="competitorProfile">A <see cref="CompetitorProfileDTO" /> containing information about the competitor</param> /// <param name="culture">A <see cref="CultureInfo" /> specifying the language of the passed <code>dto</code></param> internal void Merge(CompetitorProfileDTO competitorProfile, CultureInfo culture) { Contract.Requires(competitorProfile != null); Contract.Requires(competitorProfile.Competitor != null); _isVirtual = competitorProfile.Competitor.IsVirtual; Names[culture] = competitorProfile.Competitor.Name; _countryNames[culture] = competitorProfile.Competitor.CountryName; _abbreviations[culture] = string.IsNullOrEmpty(competitorProfile.Competitor.Abbreviation) ? SdkInfo.GetAbbreviationFromName(competitorProfile.Competitor.Name) : competitorProfile.Competitor.Abbreviation; ReferenceId = UpdateReferenceIds(competitorProfile.Competitor.Id, competitorProfile.Competitor.ReferenceIds); _countryCode = competitorProfile.Competitor.CountryCode; if (competitorProfile.Players != null && competitorProfile.Players.Any()) { _associatedPlayerIds.Clear(); _associatedPlayerIds.AddRange(competitorProfile.Players.Select(s => s.Id)); } if (competitorProfile.Jerseys != null && competitorProfile.Jerseys.Any()) { _jerseys.Clear(); _jerseys.AddRange(competitorProfile.Jerseys.Select(s => new JerseyCI(s))); } if (competitorProfile.Manager != null) { if (_manager == null) { _manager = new ManagerCI(competitorProfile.Manager, culture); } else { _manager.Merge(competitorProfile.Manager, culture); } } if (competitorProfile.Venue != null) { if (_venue == null) { _venue = new VenueCI(competitorProfile.Venue, culture); } else { _venue.Merge(competitorProfile.Venue, culture); } } if (!string.IsNullOrEmpty(competitorProfile.Competitor.Gender)) { _gender = competitorProfile.Competitor.Gender; } ((List <CultureInfo>)_fetchedCultures).Add(culture); }
public void CompetitorProfileDTOMappingTest() { var msg = RMF.GetCompetitorProfileEndpoint(0, 10); var dto = new CompetitorProfileDTO(msg); ValidateTeamExtended(msg.competitor, dto.Competitor); //TODO: missing extended properties Assert.AreEqual(msg.players.Length, dto.Players.Count()); for (var i = 0; i < msg.players.Length; i++) { ValidatePlayerExtended(msg.players[i], dto.Players.ToArray()[i]); } }
private void AddCompetitorProfile(URN id, CompetitorProfileDTO item, CultureInfo culture, bool useSemaphore) { if (_cache.Contains(id.ToString())) { try { var ci = (CompetitorCI)_cache.Get(id.ToString()); if (useSemaphore) { _semaphoreCacheMerge.Wait(); } ci.Merge(item, culture); } catch (Exception ex) { ExecutionLog.Error($"Error adding competitor for id={id}, dto type={item?.GetType().Name} and lang={culture.TwoLetterISOLanguageName}.", ex); } finally { if (useSemaphore) { if (!_isDisposed) { _semaphoreCacheMerge.Release(); } } } if (item?.Players != null && item.Players.Any()) { foreach (var player in item.Players) { AddPlayerProfile(player, id, culture, false); } } } else { _cache.Add(id.ToString(), new CompetitorCI(item, culture, _dataRouterManager), GetCorrectCacheItemPolicy(id)); if (item.Players != null && item.Players.Any()) { foreach (var player in item.Players) { AddPlayerProfile(player, id, culture, false); } } } }
/// <summary> /// Initializes a new instance of the <see cref="CompetitorCI" /> class /// </summary> /// <param name="competitor">A <see cref="CompetitorProfileDTO" /> containing information about the competitor</param> /// <param name="culture">A <see cref="CultureInfo" /> specifying the language of the passed <code>dto</code></param> /// <param name="dataRouterManager"> /// The <see cref="IDataRouterManager" /> used to fetch <see cref="CompetitorProfileDTO" /> /// </param> internal CompetitorCI(CompetitorProfileDTO competitor, CultureInfo culture, IDataRouterManager dataRouterManager = null) : base(competitor.Competitor) { Contract.Requires(competitor != null); Contract.Requires(culture != null); _fetchedCultures = new List <CultureInfo>(); _primaryCulture = culture; _dataRouterManager = dataRouterManager; Names = new Dictionary <CultureInfo, string>(); _countryNames = new Dictionary <CultureInfo, string>(); _abbreviations = new Dictionary <CultureInfo, string>(); _associatedPlayerIds = new List <URN>(); _jerseys = new List <JerseyCI>(); Merge(competitor, culture); }
private async Task AddCompetitorProfileAsync(URN id, CompetitorProfileDTO item, CultureInfo culture, bool useSemaphore) { if (_cache.Contains(id.ToString())) { try { var ci = (CompetitorCI)_cache.Get(id.ToString()); if (useSemaphore) { await WaitTillIdIsAvailableAsync(_mergeUrns, id).ConfigureAwait(false); } ci?.Merge(item, culture); } catch (Exception ex) { ExecutionLog.LogError(ex, $"Error adding competitor for id={id}, dto type={item?.GetType().Name} and lang={culture.TwoLetterISOLanguageName}."); } finally { if (useSemaphore && !_isDisposed) { await ReleaseIdAsync(_mergeUrns, id).ConfigureAwait(false); } } if (item?.Players != null && item.Players.Any()) { var tasks = item.Players.Select(s => AddPlayerProfileAsync(s, id, culture, false)); await Task.WhenAll(tasks).ConfigureAwait(false); } } else { _cache.Add(id.ToString(), new CompetitorCI(item, culture, _dataRouterManager), GetCorrectCacheItemPolicy(id)); if (item.Players != null && item.Players.Any()) { var tasks = item.Players.Select(s => AddPlayerProfileAsync(s, id, culture, false)); await Task.WhenAll(tasks).ConfigureAwait(false); } } }
/// <summary> /// Initializes a new instance of the <see cref="CompetitorCI"/> class /// </summary> /// <param name="competitor">A <see cref="CompetitorProfileDTO"/> containing information about the competitor</param> /// <param name="culture">A <see cref="CultureInfo"/> specifying the language of the passed <code>dto</code></param> /// <param name="dataRouterManager">The <see cref="IDataRouterManager"/> used to fetch <see cref="CompetitorProfileDTO"/></param> internal CompetitorCI(CompetitorProfileDTO competitor, CultureInfo culture, IDataRouterManager dataRouterManager = null) : base(competitor.Competitor) { Guard.Argument(competitor, nameof(competitor)).NotNull(); Guard.Argument(culture, nameof(culture)).NotNull(); _fetchedCultures = new List <CultureInfo>(); _primaryCulture = culture; _dataRouterManager = dataRouterManager; Names = new Dictionary <CultureInfo, string>(); _countryNames = new Dictionary <CultureInfo, string>(); _abbreviations = new Dictionary <CultureInfo, string>(); _associatedPlayerIds = new List <URN>(); _jerseys = new List <JerseyCI>(); _lastTimeCompetitorProfileFetched = DateTime.MinValue; _cultureCompetitorProfileFetched = new List <CultureInfo>(); Merge(competitor, culture); }
/// <summary> /// Merges the information from the provided <see cref="CompetitorProfileDTO"/> into the current instance /// </summary> /// <param name="competitorProfile">A <see cref="CompetitorProfileDTO"/> containing information about the competitor</param> /// <param name="culture">A <see cref="CultureInfo"/> specifying the language of the passed <code>dto</code></param> internal void Merge(CompetitorProfileDTO competitorProfile, CultureInfo culture) { Guard.Argument(competitorProfile, nameof(competitorProfile)).NotNull(); Guard.Argument(competitorProfile.Competitor, nameof(competitorProfile.Competitor)).NotNull(); _isVirtual = competitorProfile.Competitor.IsVirtual; Names[culture] = competitorProfile.Competitor.Name; _countryNames[culture] = competitorProfile.Competitor.CountryName; _abbreviations[culture] = string.IsNullOrEmpty(competitorProfile.Competitor.Abbreviation) ? SdkInfo.GetAbbreviationFromName(competitorProfile.Competitor.Name) : competitorProfile.Competitor.Abbreviation; _referenceId = UpdateReferenceIds(competitorProfile.Competitor.Id, competitorProfile.Competitor.ReferenceIds); _countryCode = competitorProfile.Competitor.CountryCode; _state = competitorProfile.Competitor.State; if (competitorProfile.Players != null && competitorProfile.Players.Any()) { _associatedPlayerIds.Clear(); _associatedPlayerIds.AddRange(competitorProfile.Players.Select(s => s.Id)); } if (competitorProfile.Jerseys != null && competitorProfile.Jerseys.Any()) { _jerseys.Clear(); _jerseys.AddRange(competitorProfile.Jerseys.Select(s => new JerseyCI(s))); } if (competitorProfile.Manager != null) { if (_manager == null) { _manager = new ManagerCI(competitorProfile.Manager, culture); } else { _manager.Merge(competitorProfile.Manager, culture); } } if (competitorProfile.Venue != null) { if (_venue == null) { _venue = new VenueCI(competitorProfile.Venue, culture); } else { _venue.Merge(competitorProfile.Venue, culture); } } if (!string.IsNullOrEmpty(competitorProfile.Competitor.Gender)) { _gender = competitorProfile.Competitor.Gender; } if (!string.IsNullOrEmpty(competitorProfile.Competitor.AgeGroup)) { _ageGroup = competitorProfile.Competitor.AgeGroup; } if (competitorProfile.RaceDriverProfile != null) { _raceDriverProfile = new RaceDriverProfileCI(competitorProfile.RaceDriverProfile); } if (competitorProfile.Players != null && competitorProfile.Players.Any()) { _lastTimeCompetitorProfileFetched = DateTime.Now; _cultureCompetitorProfileFetched.Add(culture); } if (competitorProfile.Competitor.SportId != null) { _sportId = competitorProfile.Competitor.SportId; } if (competitorProfile.Competitor.CategoryId != null) { _categoryId = competitorProfile.Competitor.CategoryId; } ((List <CultureInfo>)_fetchedCultures).Add(culture); }