public SportEventStatisticsDTO(matchStatistics statistics, IDictionary <HomeAway, URN> homeAwayCompetitors) { Contract.Requires(statistics != null); var teamStats = new List <TeamStatisticsDTO>(); if (statistics.totals != null) { foreach (var total in statistics.totals) { teamStats.Add(new TeamStatisticsDTO(total, homeAwayCompetitors)); } TotalStatisticsDTOs = teamStats; } if (statistics.periods != null) { var periodStats = new List <PeriodStatisticsDTO>(); foreach (var period in statistics.periods) { periodStats.Add(new PeriodStatisticsDTO(period, homeAwayCompetitors)); } PeriodStatisticsDTOs = periodStats; } }
// from API public SportEventStatisticsDTO(matchStatistics statistics, IDictionary <HomeAway, URN> homeAwayCompetitors) { Guard.Argument(statistics, nameof(statistics)).NotNull(); var teamStats = new List <TeamStatisticsDTO>(); if (statistics.totals != null && statistics.totals.Any()) { // can here be more then 1 sub-array? foreach (var total in statistics.totals) { foreach (var teamStatistics in total) { teamStats.Add(new TeamStatisticsDTO(teamStatistics, homeAwayCompetitors)); } } TotalStatisticsDTOs = teamStats; } if (statistics.periods != null) { var periodStats = new List <PeriodStatisticsDTO>(); foreach (var period in statistics.periods) { periodStats.Add(new PeriodStatisticsDTO(period, homeAwayCompetitors)); } PeriodStatisticsDTOs = periodStats; } }
/// <summary> /// Initializes a new instance of the <see cref="SportEventStatusDTO"/> class. /// </summary> /// <param name="restSES">A <see cref="restSportEventStatus" /> instance containing status data about the associated sport event</param> /// <param name="statistics"></param> /// <param name="homeAwayCompetitors"></param> public SportEventStatusDTO(restSportEventStatus restSES, matchStatistics statistics, IDictionary <HomeAway, URN> homeAwayCompetitors) { Guard.Argument(restSES, nameof(restSES)).NotNull(); _homeAwayCompetitors = homeAwayCompetitors; var tempProperties = new Dictionary <string, object>(); if (restSES.clock != null) { var i = 0; foreach (var clock in restSES.clock) { i++; ApplyPropertyValue(true, $"Clock{i}_MatchTime", clock.match_time, tempProperties); ApplyPropertyValue(true, $"Clock{i}_StoppageTime", clock.stoppage_time, tempProperties); ApplyPropertyValue(true, $"Clock{i}_StoppageTimeAnnounced", clock.stoppage_time_announced, tempProperties); } } ApplyPropertyValue(restSES.periodSpecified, "Period", restSES.period, tempProperties); if (restSES.period_scores != null && restSES.period_scores.Any()) { var periodScores = new List <PeriodScoreDTO>(); foreach (var periodScore in restSES.period_scores) { periodScores.Add(new PeriodScoreDTO(periodScore)); if (periodScore.numberSpecified) { ApplyPropertyValue(periodScore.numberSpecified, $"PeriodScore{periodScore.number}_Number", periodScore.number, tempProperties); } ApplyPropertyValue(true, $"PeriodScore{periodScore.number}_HomeScore", periodScore.home_score, tempProperties); ApplyPropertyValue(true, $"PeriodScore{periodScore.number}_AwayScore", periodScore.away_score, tempProperties); ApplyPropertyValue(true, $"PeriodScore{periodScore.number}_Type", periodScore.type, tempProperties); } PeriodScores = periodScores; } ApplyPropertyValue(!string.IsNullOrEmpty(restSES.winner_id), "WinnerId", restSES.winner_id, tempProperties); ApplyPropertyValue(!string.IsNullOrEmpty(restSES.winning_reason), "WinningReason", restSES.winning_reason, tempProperties); ApplyPropertyValue(!string.IsNullOrEmpty(restSES.aggregate_home_score), "AggregateHomeScore", restSES.aggregate_home_score, tempProperties); ApplyPropertyValue(!string.IsNullOrEmpty(restSES.aggregate_away_score), "AggregateAwayScore", restSES.aggregate_away_score, tempProperties); ApplyPropertyValue(!string.IsNullOrEmpty(restSES.aggregate_winner_id), "AggregateWinnerId", restSES.aggregate_winner_id, tempProperties); ApplyPropertyValue(!string.IsNullOrEmpty(restSES.home_score), "HomeScore", restSES.home_score, tempProperties); // BELOW ApplyPropertyValue(!string.IsNullOrEmpty(restSES.away_score), "AwayScore", restSES.away_score, tempProperties); // BELOW Properties = new ReadOnlyDictionary <string, object>(tempProperties); int statusId; Status = restSES.status_codeSpecified ? MessageMapperHelper.GetEnumValue(restSES.status_code, EventStatus.Unknown) : int.TryParse(restSES.status, out statusId) ? MessageMapperHelper.GetEnumValue(statusId, EventStatus.Unknown) : MessageMapperHelper.GetEnumValue(restSES.status, EventStatus.Unknown); ApplyPropertyValue(true, "Status", (int)Status, tempProperties); //BELOW //IsReported = ses.reportingSpecified // ? (int?)ses.reporting // : null; HomeScore = decimal.TryParse(restSES.home_score, NumberStyles.AllowDecimalPoint, NumberFormatInfo.InvariantInfo, out var homeScore) ? (decimal?)homeScore : null; AwayScore = decimal.TryParse(restSES.away_score, NumberStyles.AllowDecimalPoint, NumberFormatInfo.InvariantInfo, out var awayScore) ? (decimal?)awayScore : null; var matchStatusId = -1; if (restSES.match_status_codeSpecified) { matchStatusId = restSES.match_status_code; ApplyPropertyValue(true, MATCH_STATUS, matchStatusId, tempProperties); } if (matchStatusId < 0 && !string.IsNullOrEmpty(restSES.match_status)) { //TODO: status here is received as "2nd_set", not even like descriptions on API (there are no "_" between words) if (int.TryParse(restSES.match_status, out matchStatusId)) { ApplyPropertyValue(true, MATCH_STATUS, matchStatusId, tempProperties); } else if (restSES.match_status.Equals("not_started", StringComparison.InvariantCultureIgnoreCase)) { matchStatusId = 0; ApplyPropertyValue(true, MATCH_STATUS, matchStatusId, tempProperties); } else { //ignored } } MatchStatusId = matchStatusId; if (!string.IsNullOrEmpty(restSES.winner_id)) { WinnerId = URN.Parse(restSES.winner_id); } PeriodOfLadder = null; ReportingStatus = ReportingStatus.Unknown; EventClock = null; EventResults = null; if (restSES.results != null) { var eventResults = new List <EventResultDTO>(); foreach (var result in restSES.results) { eventResults.Add(new EventResultDTO(result)); } EventResults = eventResults; } if (statistics != null) { SportEventStatistics = new SportEventStatisticsDTO(statistics, _homeAwayCompetitors); } DecidedByFed = restSES.decided_by_fedSpecified ? restSES.decided_by_fed : (bool?)null; // load home and away penalty score from the penalty period score if (HomePenaltyScore == null && AwayPenaltyScore == null && PeriodScores != null && PeriodScores.Any()) { try { foreach (var periodScoreDTO in PeriodScores) { if (periodScoreDTO.Type.HasValue && periodScoreDTO.Type.Value == PeriodType.Penalties) { HomePenaltyScore = (int)periodScoreDTO.HomeScore; AwayPenaltyScore = (int)periodScoreDTO.AwayScore; } } } catch (Exception) { //ignored } } }
/// <summary> /// Initializes a new instance of the <see cref="SportEventStatusDTO" /> class. /// </summary> /// <param name="record"> /// A <see cref="restSportEventStatus" /> instance containing status data about the associated sport /// event /// </param> /// <param name="statistics"></param> /// <param name="homeAwayCompetitors"></param> public SportEventStatusDTO(restSportEventStatus record, matchStatistics statistics, IDictionary <HomeAway, URN> homeAwayCompetitors) { Contract.Requires(record != null); _homeAwayCompetitors = homeAwayCompetitors; var tempProperties = new Dictionary <string, object>(); if (record.clock != null) { var i = 0; foreach (var clock in record.clock) { i++; ApplyPropertyValue(true, $"Clock{i}_MatchTime", clock.match_time, tempProperties); ApplyPropertyValue(true, $"Clock{i}_StoppageTime", clock.stoppage_time, tempProperties); ApplyPropertyValue(true, $"Clock{i}_StoppageTimeAnnounced", clock.stoppage_time_announced, tempProperties); } } ApplyPropertyValue(record.periodSpecified, "Period", record.period, tempProperties); if (record.period_scores != null && record.period_scores.Any()) { var periodScores = new List <PeriodScoreDTO>(); foreach (var periodScore in record.period_scores) { periodScores.Add(new PeriodScoreDTO(periodScore)); if (periodScore.numberSpecified) { ApplyPropertyValue(periodScore.numberSpecified, $"PeriodScore{periodScore.number}_Number", periodScore.number, tempProperties); } ApplyPropertyValue(true, $"PeriodScore{periodScore.number}_HomeScore", periodScore.home_score, tempProperties); ApplyPropertyValue(true, $"PeriodScore{periodScore.number}_AwayScore", periodScore.away_score, tempProperties); ApplyPropertyValue(true, $"PeriodScore{periodScore.number}_Type", periodScore.type, tempProperties); } PeriodScores = periodScores; } ApplyPropertyValue(true, "WinnerId", record.winner_id, tempProperties); ApplyPropertyValue(true, "WinningReason", record.winning_reason, tempProperties); ApplyPropertyValue(record.aggregate_away_scoreSpecified, "AggregateAwayScore", record.aggregate_away_score, tempProperties); ApplyPropertyValue(record.aggregate_home_scoreSpecified, "AggregateHomeScore", record.aggregate_home_score, tempProperties); ApplyPropertyValue(true, "AggregateWinnerId", record.aggregate_winner_id, tempProperties); ApplyPropertyValue(record.away_scoreSpecified, "AwayScore", record.away_score, tempProperties); // BELOW ApplyPropertyValue(record.home_scoreSpecified, "HomeScore", record.home_score, tempProperties); // BELOW Properties = new ReadOnlyDictionary <string, object>(tempProperties); int statusId; Status = record.status_codeSpecified ? MessageMapperHelper.GetEnumValue(record.status_code, EventStatus.Unknown) : int.TryParse(record.status, out statusId) ? MessageMapperHelper.GetEnumValue(statusId, EventStatus.Unknown) : MessageMapperHelper.GetEnumValue(record.status, EventStatus.Unknown); ApplyPropertyValue(true, "Status", (int)Status, tempProperties); //BELOW //IsReported = record.reportingSpecified // ? (int?)record.reporting // : null; HomeScore = record.home_scoreSpecified ? (decimal?)record.home_score : null; AwayScore = record.away_scoreSpecified ? (decimal?)record.away_score : null; var matchStatusId = -1; if (record.match_status_codeSpecified) { matchStatusId = record.match_status_code; ApplyPropertyValue(true, MATCH_STATUS, matchStatusId, tempProperties); } if (matchStatusId < 0 && !string.IsNullOrEmpty(record.match_status)) { //TODO: status here is received as "2nd_set", not even like descriptions on API (there are no "_" between words) if (int.TryParse(record.match_status, out matchStatusId)) { ApplyPropertyValue(true, MATCH_STATUS, matchStatusId, tempProperties); } else if (record.match_status.Equals("not_started", StringComparison.InvariantCultureIgnoreCase)) { matchStatusId = 0; ApplyPropertyValue(true, MATCH_STATUS, matchStatusId, tempProperties); } } MatchStatusId = matchStatusId; if (!string.IsNullOrEmpty(record.winner_id)) { WinnerId = URN.Parse(record.winner_id); } ReportingStatus = ReportingStatus.Unknown; EventClock = null; EventResults = null; if (statistics != null) { SportEventStatistics = new SportEventStatisticsDTO(statistics, _homeAwayCompetitors); } }