private void AddCompetitorProfile(URN id, SimpleTeamProfileDTO 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.LogError($"Error adding competitor for id={id}, dto type={item?.GetType().Name} and lang={culture.TwoLetterISOLanguageName}.", ex);
         }
         finally
         {
             if (useSemaphore && !_isDisposed)
             {
                 _semaphoreCacheMerge.Release();
             }
         }
     }
     else
     {
         _cache.Add(id.ToString(), new CompetitorCI(item, culture, _dataRouterManager), GetCorrectCacheItemPolicy(id));
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Merges the information from the provided <see cref="SimpleTeamProfileDTO"/> into the current instance
        /// </summary>
        /// <param name="simpleTeamProfile">A <see cref="SimpleTeamProfileDTO"/> 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(SimpleTeamProfileDTO simpleTeamProfile, CultureInfo culture)
        {
            Guard.Argument(simpleTeamProfile, nameof(simpleTeamProfile)).NotNull();
            Guard.Argument(simpleTeamProfile.Competitor, nameof(simpleTeamProfile.Competitor)).NotNull();

            _isVirtual              = simpleTeamProfile.Competitor.IsVirtual;
            Names[culture]          = simpleTeamProfile.Competitor.Name;
            _countryNames[culture]  = simpleTeamProfile.Competitor.CountryName;
            _abbreviations[culture] = string.IsNullOrEmpty(simpleTeamProfile.Competitor.Abbreviation)
                ? SdkInfo.GetAbbreviationFromName(simpleTeamProfile.Competitor.Name)
                : simpleTeamProfile.Competitor.Abbreviation;
            _referenceId =
                UpdateReferenceIds(simpleTeamProfile.Competitor.Id, simpleTeamProfile.Competitor.ReferenceIds);
            _countryCode = simpleTeamProfile.Competitor.CountryCode;
            _state       = simpleTeamProfile.Competitor.State;
            if (!string.IsNullOrEmpty(simpleTeamProfile.Competitor.Gender))
            {
                _gender = simpleTeamProfile.Competitor.Gender;
            }
            if (!string.IsNullOrEmpty(simpleTeamProfile.Competitor.AgeGroup))
            {
                _ageGroup = simpleTeamProfile.Competitor.AgeGroup;
            }

            if (simpleTeamProfile.Competitor.Players != null && simpleTeamProfile.Competitor.Players.Any())
            {
                _lastTimeCompetitorProfileFetched = DateTime.Now;
                _cultureCompetitorProfileFetched.Add(culture);
            }
            ((List <CultureInfo>)_fetchedCultures).Add(culture);
        }
 private async Task AddCompetitorProfileAsync(URN id, SimpleTeamProfileDTO 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);
             }
         }
     }
     else
     {
         _cache.Add(id.ToString(), new CompetitorCI(item, culture, _dataRouterManager), GetCorrectCacheItemPolicy(id));
     }
 }
Ejemplo n.º 4
0
        private SimpleTeamProfileDTO CacheSimpleTeam(int id, IDictionary <string, string> referenceIds)
        {
            var simpleTeam    = MessageFactoryRest.GetSimpleTeamCompetitorProfileEndpoint(id, referenceIds);
            var simpleTeamDto = new SimpleTeamProfileDTO(simpleTeam);

            _cacheManager.SaveDto(simpleTeamDto.Competitor.Id, simpleTeamDto, CultureInfo.CurrentCulture, DtoType.SimpleTeamProfile, null);
            return(simpleTeamDto);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="CompetitorCI" /> class
        /// </summary>
        /// <param name="competitor">A <see cref="SimpleTeamProfileDTO" /> 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="SimpleTeamProfileDTO" />
        /// </param>
        internal CompetitorCI(SimpleTeamProfileDTO 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);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Merges the information from the provided <see cref="SimpleTeamProfileDTO" /> into the current instance
        /// </summary>
        /// <param name="simpleTeamProfile">A <see cref="SimpleTeamProfileDTO" /> 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(SimpleTeamProfileDTO simpleTeamProfile, CultureInfo culture)
        {
            Contract.Requires(simpleTeamProfile != null);
            Contract.Requires(simpleTeamProfile.Competitor != null);

            _isVirtual              = simpleTeamProfile.Competitor.IsVirtual;
            Names[culture]          = simpleTeamProfile.Competitor.Name;
            _countryNames[culture]  = simpleTeamProfile.Competitor.CountryName;
            _abbreviations[culture] = string.IsNullOrEmpty(simpleTeamProfile.Competitor.Abbreviation)
                ? SdkInfo.GetAbbreviationFromName(simpleTeamProfile.Competitor.Name)
                : simpleTeamProfile.Competitor.Abbreviation;
            ReferenceId =
                UpdateReferenceIds(simpleTeamProfile.Competitor.Id, simpleTeamProfile.Competitor.ReferenceIds);
            _countryCode = simpleTeamProfile.Competitor.CountryCode;
            if (!string.IsNullOrEmpty(simpleTeamProfile.Competitor.Gender))
            {
                _gender = simpleTeamProfile.Competitor.Gender;
            }
            ((List <CultureInfo>)_fetchedCultures).Add(culture);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CompetitorCI"/> class
        /// </summary>
        /// <param name="competitor">A <see cref="SimpleTeamProfileDTO"/> 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="SimpleTeamProfileDTO"/></param>
        internal CompetitorCI(SimpleTeamProfileDTO 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);
        }