コード例 #1
0
        /// <summary>
        /// Asynchronously gets a <see cref="ISport"/> instance representing the sport specified by it's id in the language specified by <code>culture</code>, or a null reference if sport with specified id does not exist
        /// </summary>
        /// <param name="id">A <see cref="URN"/> identifying the sport to retrieve</param>
        /// <param name="culture">A <see cref="CultureInfo"/> specifying the language or a null reference to use the languages specified in the configuration</param>
        /// <returns>A <see cref="Task{ISport}"/> representing the async operation</returns>
        public async Task <ISport> GetSportAsync(URN id, CultureInfo culture = null)
        {
            var cs = culture == null ? _defaultCultures : new[] { culture };
            var s  = cs.Aggregate(string.Empty, (current, cultureInfo) => current + (";" + cultureInfo.TwoLetterISOLanguageName));

            s = s.Substring(1);

            Log.LogInformation($"Invoked GetSportsAsync: [Id={id}, Cultures={s}].");
            return(await _sportEntityFactory.BuildSportAsync(id, cs, _exceptionStrategy).ConfigureAwait(false));
        }
コード例 #2
0
        /// <summary>
        /// Gets associated sport
        /// </summary>
        /// <returns>The associated sport</returns>
        public async Task <ISport> GetSportAsync()
        {
            var sportId = GetOrLoadCompetitor()?.SportId;

            if (sportId != null)
            {
                return(await _sportEntityFactory.BuildSportAsync(sportId, _cultures, _exceptionStrategy).ConfigureAwait(false));
            }

            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Asynchronously gets a <see cref="ISport"/> instance representing the sport specified by it's id in the language specified by <code>culture</code>, or a null reference if sport with specified id does not exist
        /// </summary>
        /// <param name="id">A <see cref="URN"/> identifying the sport to retrieve</param>
        /// <param name="culture">A <see cref="CultureInfo"/> specifying the language or a null reference to use the languages specified in the configuration</param>
        /// <returns>A <see cref="Task{ISport}"/> representing the async operation</returns>
        public async Task <ISport> GetSportAsync(URN id, CultureInfo culture = null)
        {
            var cs = culture == null ? _defaultCultures : new[] { culture };
            var s  = cs.Aggregate(string.Empty, (current, cultureInfo) => current + (";" + cultureInfo.TwoLetterISOLanguageName));

            s = s.Substring(1);

            try
            {
                LogInt.LogInformation($"Invoked GetSportsAsync: [Id={id}, Cultures={s}]");
                return(await _sportEntityFactory.BuildSportAsync(id, cs, _exceptionStrategy).ConfigureAwait(false));
            }
            catch (Exception e)
            {
                LogInt.LogError(e, $"Error executing GetSportsAsync: [Id={id}, Cultures={s}]");
                if (_exceptionStrategy == ExceptionHandlingStrategy.THROW)
                {
                    throw;
                }
                return(null);
            }
        }