/// <summary> /// Asynchronously gets a list of <see cref="ISeason" /> associated with this tournament /// </summary> /// <returns>A list of <see cref="ISeason" /> associated with this tournament</returns> public async Task <IEnumerable <ISeason> > GetSeasonsAsync() { var tournamentInfoCI = (TournamentInfoCI)SportEventCache.GetEventCacheItem(Id); if (tournamentInfoCI == null) { ExecutionLogPrivate.Debug($"Missing data. No tournament cache item for id={Id}."); return(null); } var seasonIds = ExceptionStrategy == ExceptionHandlingStrategy.THROW ? await tournamentInfoCI.GetSeasonsAsync(Cultures).ConfigureAwait(false) : await new Func <IEnumerable <CultureInfo>, Task <IEnumerable <URN> > >(tournamentInfoCI.GetSeasonsAsync).SafeInvokeAsync(Cultures, ExecutionLog, GetFetchErrorMessage("Seasons")).ConfigureAwait(false); return(seasonIds?.Select(s => _sportEntityFactory.BuildSportEvent <ISeason>(s, SportId, Cultures, ExceptionStrategy))); }
public CurrentSeasonInfo(ITournamentInfoCI currentSeasonCI, IEnumerable <CultureInfo> cultures, ISportEntityFactory sportEntityFactory, ExceptionHandlingStrategy exceptionStrategy, IDictionary <URN, ReferenceIdCI> competitorsReferenceIds) { var cultureInfos = cultures as IList <CultureInfo> ?? cultures.ToList(); Id = currentSeasonCI.Id; Names = currentSeasonCI.GetNamesAsync(cultureInfos).Result; Year = currentSeasonCI.GetYearAsync().Result; StartDate = currentSeasonCI.GetScheduledAsync().Result ?? DateTime.MinValue; EndDate = currentSeasonCI.GetScheduledEndAsync().Result ?? DateTime.MinValue; Coverage = currentSeasonCI.GetSeasonCoverageAsync().Result == null ? null : new SeasonCoverage(currentSeasonCI.GetSeasonCoverageAsync().Result); Groups = currentSeasonCI.GetGroupsAsync(cultureInfos).Result == null ? null : currentSeasonCI.GetGroupsAsync(cultureInfos).Result.Select(s => new Group(s, cultureInfos, sportEntityFactory, exceptionStrategy, competitorsReferenceIds)); CurrentRound = currentSeasonCI.GetCurrentRoundAsync(cultureInfos).Result == null ? null : new Round(currentSeasonCI.GetCurrentRoundAsync(cultureInfos).Result, cultureInfos); Competitors = currentSeasonCI.GetCompetitorsAsync(cultureInfos).Result == null ? null : currentSeasonCI.GetCompetitorsAsync(cultureInfos).Result.Select(s => sportEntityFactory.BuildCompetitor(s, cultureInfos, competitorsReferenceIds, exceptionStrategy)); Schedule = currentSeasonCI.GetScheduleAsync(cultureInfos).Result == null ? null : currentSeasonCI.GetScheduleAsync(cultureInfos).Result.Select(s => sportEntityFactory.BuildSportEvent <ISportEvent>(s, null, cultureInfos, exceptionStrategy)); }
public CurrentSeasonInfo(CurrentSeasonInfoCI cacheItem, IEnumerable <CultureInfo> cultures, ISportEntityFactory sportEntityFactory, ExceptionHandlingStrategy exceptionHandlingStrategy, IDictionary <URN, ReferenceIdCI> competitorsReferenceIds) { Guard.Argument(cacheItem, nameof(cacheItem)).NotNull(); //Guard.Argument(sportEntityFactory, nameof()).NotNull(); var cultureInfos = cultures as IList <CultureInfo> ?? cultures.ToList(); Id = cacheItem.Id; Names = cacheItem.Name as IReadOnlyDictionary <CultureInfo, string>; Year = cacheItem.Year; StartDate = cacheItem.StartDate; EndDate = cacheItem.EndDate; Coverage = cacheItem.SeasonCoverage == null ? null : new SeasonCoverage(cacheItem.SeasonCoverage); Groups = cacheItem.Groups == null ? null : cacheItem.Groups.Select(s => new Group(s, cultureInfos, sportEntityFactory, exceptionHandlingStrategy, competitorsReferenceIds)); CurrentRound = cacheItem.CurrentRound == null ? null : new Round(cacheItem.CurrentRound, cultureInfos); Competitors = cacheItem.Competitors == null ? null : cacheItem.Competitors.Select(s => sportEntityFactory.BuildCompetitor(s, cultureInfos, competitorsReferenceIds, exceptionHandlingStrategy)); Schedule = cacheItem.Schedule == null ? null : cacheItem.Schedule.Select(s => sportEntityFactory.BuildSportEvent <ISportEvent>(s, null, cultureInfos, exceptionHandlingStrategy)); }
/// <summary> /// Builds and returns a <see cref="ISportEvent"/> derived instance /// </summary> /// <param name="eventId">A <see cref="string"/> representation of the event id</param> /// <param name="sportId">The sport identifier</param> /// <param name="cultures">A <see cref="IEnumerable{CultureInfo}" /> specifying the languages to which the mapped message will be translated</param> /// <param name="exceptionStrategy">A <see cref="ExceptionHandlingStrategy"/> enum member specifying how the constructed instance should handle potential exceptions</param> /// <returns>A <see cref="ISportEvent"/> derived constructed instance</returns> protected T BuildEvent <T>(URN eventId, URN sportId, IEnumerable <CultureInfo> cultures, ExceptionHandlingStrategy exceptionStrategy) where T : ISportEvent { Contract.Requires(!string.IsNullOrEmpty(eventId.ToString())); Contract.Requires(sportId != null); Contract.Requires(cultures != null && cultures.Any()); Contract.Ensures(Contract.Result <T>() != null); var cultureInfos = cultures as CultureInfo[] ?? cultures.ToArray(); T entity; switch (eventId.TypeGroup) { case ResourceTypeGroup.TOURNAMENT: case ResourceTypeGroup.BASIC_TOURNAMENT: case ResourceTypeGroup.SEASON: case ResourceTypeGroup.MATCH: case ResourceTypeGroup.STAGE: case ResourceTypeGroup.DRAW: case ResourceTypeGroup.LOTTERY: case ResourceTypeGroup.UNKNOWN: { entity = (T)_sportEntityFactory.BuildSportEvent <ISportEvent>(eventId, sportId, cultureInfos, exceptionStrategy); break; } case ResourceTypeGroup.OTHER: throw new InvalidOperationException($"Other entity with id={eventId} cannot be associated with feed message"); default: throw new InvalidOperationException($"Entity with id={eventId} cannot be associated with feed message"); } return(entity); }
/// <summary> /// Builds and returns a <see cref="ISportEvent"/> derived instance /// </summary> /// <param name="eventId">A <see cref="string"/> representation of the event id</param> /// <param name="sportId">The sport identifier</param> /// <param name="cultures">A <see cref="IEnumerable{CultureInfo}" /> specifying the languages to which the mapped message will be translated</param> /// <param name="exceptionStrategy">A <see cref="ExceptionHandlingStrategy"/> enum member specifying how the constructed instance should handle potential exceptions</param> /// <returns>A <see cref="ISportEvent"/> derived constructed instance</returns> protected T BuildEvent <T>(URN eventId, URN sportId, IEnumerable <CultureInfo> cultures, ExceptionHandlingStrategy exceptionStrategy) where T : ISportEvent { Guard.Argument(eventId, nameof(eventId)).NotNull(); Guard.Argument(sportId, nameof(sportId)).NotNull(); Guard.Argument(cultures, nameof(cultures)).NotNull().NotEmpty(); var cultureInfos = cultures as CultureInfo[] ?? cultures.ToArray(); T entity; switch (eventId.TypeGroup) { case ResourceTypeGroup.TOURNAMENT: case ResourceTypeGroup.BASIC_TOURNAMENT: case ResourceTypeGroup.SEASON: case ResourceTypeGroup.MATCH: case ResourceTypeGroup.STAGE: case ResourceTypeGroup.DRAW: case ResourceTypeGroup.LOTTERY: case ResourceTypeGroup.UNKNOWN: { entity = (T)_sportEntityFactory.BuildSportEvent <ISportEvent>(eventId, sportId, cultureInfos, exceptionStrategy); break; } case ResourceTypeGroup.OTHER: throw new InvalidOperationException($"Other entity with id={eventId} cannot be associated with feed message"); default: throw new InvalidOperationException($"Entity with id={eventId} cannot be associated with feed message"); } return(entity); }
/// <summary> /// Asynchronously gets a <see cref="IEnumerable{ICompetition}"/> representing currently live sport events in the language specified by <code>culture</code> /// </summary> /// <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{T}"/> representing the async operation</returns> public async Task <IEnumerable <ICompetition> > GetLiveSportEventsAsync(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.Info($"Invoked GetLiveSportEventsAsync: [Cultures={s}]."); var ids = await _sportEventCache.GetEventIdsAsync((DateTime?)null).ConfigureAwait(false); return(ids.Select(item => _sportEntityFactory.BuildSportEvent <ICompetition>( item.Item1, item.Item2, culture == null ? _defaultCultures : new[] { culture }, _exceptionStrategy)).ToList()); }
/// <summary> /// Gets the list of all events that belongs to the tournament schedule /// </summary> /// <returns>A <see cref="Task{T}"/> representing the asynchronous operation</returns> public async Task <IEnumerable <ICompetition> > GetScheduleAsync() { var sportEventIds = ExceptionStrategy == ExceptionHandlingStrategy.THROW ? await _sportEventCache.GetEventIdsAsync(Id).ConfigureAwait(false) : await new Func <URN, Task <IEnumerable <Tuple <URN, URN> > > >(_sportEventCache.GetEventIdsAsync).SafeInvokeAsync(Id, ExecutionLog, GetFetchErrorMessage("Schedule")).ConfigureAwait(false); return(sportEventIds?.Select(i => _sportEntityFactory.BuildSportEvent <ICompetition>(i.Item1, i.Item2, Cultures, ExceptionStrategy)).ToList()); }
/// <summary> /// Asynchronously gets a <see cref="IEnumerable{ICompetition}"/> representing currently live sport events in the language specified by <code>culture</code> /// </summary> /// <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{T}"/> representing the async operation</returns> public async Task <IEnumerable <ICompetition> > GetLiveSportEventsAsync(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); LogInt.LogInformation($"Invoked GetLiveSportEventsAsync: [Cultures={s}]"); var tasks = cs.Select(c => _sportEventCache.GetEventIdsAsync((DateTime?)null, c)).ToList(); try { await Task.WhenAll(tasks).ConfigureAwait(false); } catch (Exception e) { LogInt.LogError(e, $"Error executing GetLiveSportEventsAsync: [Cultures={s}]"); if (_exceptionStrategy == ExceptionHandlingStrategy.THROW) { throw; } return(null); } var ids = tasks.First().Result; if (ids.IsNullOrEmpty()) { return(new List <ICompetition>()); } return(ids.Select(item => _sportEntityFactory.BuildSportEvent <ICompetition>(item.Item1, item.Item2, culture == null ? _defaultCultures : new[] { culture }, _exceptionStrategy)).ToList()); }
/// <summary> /// Asynchronously gets a <see cref="ILongTermEvent"/> representing the tournament to which the sport event associated with the current instance belongs to /// </summary> /// <returns>A <see cref="Task{ILongTermEvent}"/> representing the retrieval operation</returns> public async Task<ILongTermEvent> GetTournamentAsync() { var matchCI = (IMatchCI)SportEventCache.GetEventCacheItem(Id); if (matchCI == null) { ExecutionLog.Debug($"Missing data. No match cache item for id={Id}."); return null; } var tournamentId = ExceptionStrategy == ExceptionHandlingStrategy.THROW ? await matchCI.GetTournamentIdAsync(Cultures).ConfigureAwait(false) : await new Func<IEnumerable<CultureInfo>, Task<URN>>(matchCI.GetTournamentIdAsync).SafeInvokeAsync(Cultures, ExecutionLog, GetFetchErrorMessage("ILongTermEvent")).ConfigureAwait(false); return tournamentId == null ? null : _sportEntityFactory.BuildSportEvent<ILongTermEvent>(tournamentId, SportId, Cultures, ExceptionStrategy); }
/// <summary> /// Gets the list of all events that belongs to the tournament schedule /// </summary> /// <returns>A <see cref="Task{T}"/> representing the asynchronous operation</returns> public async Task <IEnumerable <ICompetition> > GetScheduleAsync() { IEnumerable <Tuple <URN, URN> > sportEventIds; if (ExceptionStrategy == ExceptionHandlingStrategy.THROW) { var tasks = Cultures.Select(s => _sportEventCache.GetEventIdsAsync(Id, s)).ToList(); await Task.WhenAll(tasks).ConfigureAwait(false); sportEventIds = tasks.First().Result; } else { var tasks = Cultures.Select(s => new Func <URN, CultureInfo, Task <IEnumerable <Tuple <URN, URN> > > >(_sportEventCache.GetEventIdsAsync).SafeInvokeAsync(Id, s, ExecutionLog, GetFetchErrorMessage("Schedule"))).ToList(); await Task.WhenAll(tasks).ConfigureAwait(false); sportEventIds = tasks.First().Result; } return(sportEventIds?.Select(i => _sportEntityFactory.BuildSportEvent <ICompetition>(i.Item1, i.Item2 ?? SportId, Cultures, ExceptionStrategy)).ToList()); }