예제 #1
0
        /// <summary>
        /// Gets the new <see cref="IMarketWithOdds"/> instance
        /// </summary>
        /// <param name="sportEvent">A <see cref="ISportEvent"/> representing the sport event associated with the generated message</param>
        /// <param name="marketOddsChange">The <see cref="oddsChangeMarket"/> instance used</param>
        /// <param name="producerId">A producerId of the <see cref="ISportEvent"/></param>
        /// <param name="sportId">A sportId of the <see cref="ISportEvent"/></param>
        /// <param name="cultures">The list of cultures that should be prefetched</param>
        /// <returns>Returns the new <see cref="IMarketWithOdds"/> instance</returns>
        protected virtual IMarketWithOdds GetMarketWithOdds(ISportEvent sportEvent, oddsChangeMarket marketOddsChange, int producerId, URN sportId, IEnumerable <CultureInfo> cultures)
        {
            var cultureInfos = cultures.ToList();
            var specifiers   = string.IsNullOrEmpty(marketOddsChange.specifiers)
                ? null
                : FeedMapperHelper.GetSpecifiers(marketOddsChange.specifiers);

            var additionalInfo = string.IsNullOrEmpty(marketOddsChange.extended_specifiers)
                ? null
                : FeedMapperHelper.GetSpecifiers(marketOddsChange.extended_specifiers);

            var marketMetadata = marketOddsChange.market_metadata == null ||
                                 !marketOddsChange.market_metadata.next_betstopSpecified
                ? new MarketMetadata(null)
                : new MarketMetadata(marketOddsChange.market_metadata.next_betstop);

            var producer = _producerManager.Get(producerId);

            var nameProvider    = _nameProviderFactory.BuildNameProvider(sportEvent, marketOddsChange.id, specifiers);
            var mappingProvider = _mappingProviderFactory.BuildMarketMappingProvider(sportEvent, marketOddsChange.id, specifiers, _producerManager.Get(producerId), sportId);

            return(new MarketWithOdds(
                       marketOddsChange.id,
                       specifiers,
                       additionalInfo,
                       nameProvider,
                       mappingProvider,
                       MessageMapperHelper.GetEnumValue <MarketStatus>(marketOddsChange.status),
                       marketOddsChange.cashout_statusSpecified ? (CashoutStatus?)MessageMapperHelper.GetEnumValue <CashoutStatus>(marketOddsChange.cashout_status) : null,
                       marketOddsChange.favouriteSpecified && marketOddsChange.favourite == 1,
                       marketOddsChange.outcome?.Select(o => GetOutcomeWithOdds(sportEvent, nameProvider, mappingProvider, o, cultureInfos, BuildOutcomeDefinition(marketOddsChange.id, sportId, producer, specifiers, o.id, cultureInfos))),
                       marketMetadata,
                       BuildMarketDefinition(marketOddsChange.id, sportId, producer, specifiers, cultureInfos),
                       cultureInfos));
        }
예제 #2
0
        /// <summary>
        /// Gets the new <see cref="IMarketWithProbabilities"/> instance
        /// </summary>
        /// <param name="sportEvent">A <see cref="ISportEvent"/> representing the sport event associated with the generated message</param>
        /// <param name="marketOddsChange">The <see cref="oddsChangeMarket"/> instance used</param>
        /// <param name="producerId">A producerId specifying message producerId</param>
        /// <param name="sportId">A sportId of the <see cref="ISportEvent"/></param>
        /// <param name="cultures">The list of cultures that should be prefetched</param>
        /// <returns>Returns the new <see cref="IMarketWithOdds"/> instance</returns>
        protected virtual IMarketWithProbabilities GetMarketWithProbabilities(ISportEvent sportEvent, oddsChangeMarket marketOddsChange, int producerId, URN sportId, IEnumerable <CultureInfo> cultures)
        {
            var cultureInfos = cultures.ToList();
            var specifiers   = string.IsNullOrEmpty(marketOddsChange.specifiers)
                ? null
                : FeedMapperHelper.GetSpecifiers(marketOddsChange.specifiers);

            var additionalInfo = string.IsNullOrEmpty(marketOddsChange.extended_specifiers)
                ? null
                : FeedMapperHelper.GetSpecifiers(marketOddsChange.extended_specifiers);

            var nameProvider    = _nameProviderFactory.BuildNameProvider(sportEvent, marketOddsChange.id, specifiers);
            var mappingProvider = _mappingProviderFactory.BuildMarketMappingProvider(sportEvent, marketOddsChange.id, specifiers, producerId, sportId);

            var marketDefinition = new MarketDefinition(marketOddsChange.id, _marketCacheProvider, sportId, producerId, specifiers, cultureInfos, _externalExceptionStrategy);

            return(new MarketWithProbabilities(marketOddsChange.id,
                                               specifiers,
                                               additionalInfo,
                                               nameProvider,
                                               mappingProvider,
                                               MessageMapperHelper.GetEnumValue <MarketStatus>(marketOddsChange.status),
                                               marketOddsChange.outcome?
                                               .Select(outcomeOdds => new OutcomeProbabilities(
                                                           outcomeOdds.id,
                                                           outcomeOdds.activeSpecified ? (bool?)(outcomeOdds.active != 0) : null,
                                                           outcomeOdds.probabilitiesSpecified ? (double?)outcomeOdds.probabilities : null,
                                                           nameProvider,
                                                           mappingProvider,
                                                           cultureInfos,
                                                           new OutcomeDefinition(marketOddsChange.id, outcomeOdds.id, _marketCacheProvider, specifiers, cultureInfos, _externalExceptionStrategy))),
                                               marketDefinition,
                                               cultureInfos,
                                               marketOddsChange.cashout_statusSpecified ? (CashoutStatus?)MessageMapperHelper.GetEnumValue <CashoutStatus>(marketOddsChange.cashout_status) : null));
        }
예제 #3
0
        /// <summary>
        /// Maps (converts) the provided <see cref="odds_change"/> instance to the <see cref="IOddsChange{T}"/> instance
        /// </summary>
        /// <param name="message">A <see cref="odds_change"/> instance to be mapped (converted)</param>
        /// <param name="cultures">A <see cref="IEnumerable{CultureInfo}" /> specifying the languages to which the mapped message will be translated</param>
        /// <param name="rawMessage">The raw message</param>
        /// <returns>A <see cref="IOddsChange{T}"/> instance constructed from information in the provided <see cref="odds_change"/></returns>
        public IOddsChange <T> MapOddsChange <T>(odds_change message, IEnumerable <CultureInfo> cultures, byte[] rawMessage) where T : ISportEvent
        {
            Guard.Argument(message, nameof(message)).NotNull();

            var culturesList = cultures as List <CultureInfo> ?? cultures.ToList();

            var markets = message.odds?.market?.Select(m => GetMarketWithOdds(GetEventForNameProvider <T>(message.EventURN, message.SportId, culturesList), m, message.ProducerId, message.SportId, culturesList)).ToList();

            return(new OddsChange <T>(new MessageTimestamp(message.GeneratedAt, message.SentAt, message.ReceivedAt, SdkInfo.ToEpochTime(DateTime.Now)),
                                      _producerManager.Get(message.product),
                                      GetEventForMessage <T>(URN.Parse(message.event_id), message.SportId, culturesList),
                                      message.request_idSpecified
                    ? (long?)message.request_id
                    : null,
                                      MessageMapperHelper.GetEnumValue(message.odds_change_reasonSpecified, message.odds_change_reason, OddsChangeReason.NORMAL),
                                      message.odds != null && message.odds.betstop_reasonSpecified
                    ? (int?)message.odds.betstop_reason
                    : null,
                                      message.odds != null && message.odds.betting_statusSpecified
                    ? (int?)message.odds.betting_status
                    : null,
                                      markets,
                                      message.odds_generation_properties,
                                      _namedValuesProvider,
                                      rawMessage));
        }
        /// <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>
        public SportEventStatusDTO(stageSportEventStatus record)
        {
            Guard.Argument(record, nameof(record)).NotNull();

            var tempProperties = new Dictionary <string, object>(0);

            if (record.results != null && record.results.Any())
            {
                var i = 0;
                foreach (var resultType in record.results)
                {
                    i++;
                    ApplyPropertyValue(true, $"Result{i}_Climber", resultType.climber, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_ClimberRanking", resultType.climber_ranking, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_Id", resultType.id, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_Points", resultType.points, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_Sprint", resultType.sprint, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_SprintRanking", resultType.sprint_ranking, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_Status", resultType.status, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_StatusComment", resultType.status_comment, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_Time", resultType.time, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_TimeRanking", resultType.time_ranking, tempProperties);
                }
            }
            ApplyPropertyValue(true, "WinnerId", record.winner_id, tempProperties);

            Properties = new ReadOnlyDictionary <string, object>(tempProperties);

            Status = MessageMapperHelper.GetEnumValue(record.status, EventStatus.Unknown);
            ApplyPropertyValue(true, "Status", (int)Status, tempProperties);

            MatchStatusId = -1;

            WinnerId = !string.IsNullOrEmpty(record.winner_id) ? URN.Parse(record.winner_id) : null;

            ReportingStatus = ReportingStatus.Unknown;

            PeriodScores = null;

            EventClock = null;

            var eventResults = new List <EventResultDTO>();

            if (record.results != null && record.results.Any())
            {
                foreach (var stageResultCompetitor in record.results)
                {
                    eventResults.Add(new EventResultDTO(stageResultCompetitor));
                }

                EventResults = eventResults;
            }

            SportEventStatistics = null;
        }
예제 #5
0
        private void TestEntityValues(IBetStop <ICompetition> entity, bet_stop record, AssertHelper assertHelper)
        {
            TestEventMessageProperties(assertHelper, entity, record.timestamp, record.product, record.event_id, record.RequestId);

            var recordGroupsCount = record.groups?.Split(new[] { SdkInfo.MarketGroupsDelimiter }, StringSplitOptions.RemoveEmptyEntries).Length ?? 0;
            var entityGroupsCount = entity.Groups?.Count() ?? 0;

            Assert.AreEqual(entityGroupsCount, recordGroupsCount);
            //assertHelper.AreEqual(() => entityGroupsCount, recordGroupsCount);
            assertHelper.AreEqual(() => entity.MarketStatus, MessageMapperHelper.GetEnumValue(record.market_statusSpecified, record.market_status, MarketStatus.SUSPENDED));
        }
예제 #6
0
 /// <summary>
 /// Maps (converts) the provided <see cref="bet_stop" /> instance to the <see cref="IBetStop{T}" /> instance
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="message">A <see cref="bet_stop" /> instance to be mapped (converted)</param>
 /// <param name="cultures">A <see cref="IEnumerable{CultureInfo}" /> specifying the languages to which the mapped message will be translated</param>
 /// <param name="rawMessage">The raw message</param>
 /// <returns>A <see cref="IBetStop{T}" /> instance constructed from information in the provided <see cref="bet_stop" /></returns>
 public IBetStop <T> MapBetStop <T>(bet_stop message, IEnumerable <CultureInfo> cultures, byte[] rawMessage) where T : ISportEvent
 {
     return(new BetStop <T>(
                new MessageTimestamp(message.GeneratedAt, message.SentAt, message.ReceivedAt, SdkInfo.ToEpochTime(DateTime.Now)),
                _producerManager.Get(message.product),
                GetEventForMessage <T>(URN.Parse(message.event_id), message.SportId, cultures),
                message.request_idSpecified ? (long?)message.request_id : null,
                MessageMapperHelper.GetEnumValue(message.market_statusSpecified, message.market_status, MarketStatus.SUSPENDED),
                message.groups?.Split('|'),
                rawMessage));
 }
 /// <summary>
 /// Maps (converts) the provided <see cref="fixture_change" /> instance to the <see cref="IFixtureChange{T}" /> instance
 /// </summary>
 /// <param name="message">A <see cref="fixture_change" /> instance to be mapped (converted)</param>
 /// <param name="cultures">A <see cref="IEnumerable{CultureInfo}" /> specifying the languages to which the mapped message will be translated</param>
 /// <param name="rawMessage">The raw message</param>
 /// <returns>A <see cref="IFixtureChange{T}" /> instance constructed from information in the provided <see cref="fixture_change" /></returns>
 public IFixtureChange <T> MapFixtureChange <T>(fixture_change message, IEnumerable <CultureInfo> cultures, byte[] rawMessage) where T : ISportEvent
 {
     return(new FixtureChange <T>(
                new MessageTimestamp(message.GeneratedAt, message.SentAt, message.ReceivedAt, SdkInfo.ToEpochTime(DateTime.Now)),
                _producerManager.Get(message.product),
                GetEventForMessage <T>(URN.Parse(message.event_id), message.SportId, cultures),
                message.request_idSpecified ? (long?)message.request_id : null,
                MessageMapperHelper.GetEnumValue(message.change_typeSpecified, message.change_type, FixtureChangeType.OTHER),
                message.next_live_timeSpecified ? (long?)message.next_live_time : null,
                message.start_time,
                rawMessage));
 }
예제 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SportEventStatusDTO"/> class.
        /// </summary>
        /// <param name="stageSES">A <see cref="restSportEventStatus" /> instance containing status data about the associated sport event</param>
        /// <remarks>From SportEventSummary</remarks>
        public SportEventStatusDTO(stageSportEventStatus stageSES)
        {
            Guard.Argument(stageSES, nameof(stageSES)).NotNull();

            var tempProperties = new Dictionary <string, object>();

            //TODO: review this
            var eventResults = new List <EventResultDTO>();

            if (stageSES.results != null && stageSES.results.competitor != null && stageSES.results.competitor.Any())
            {
                var i = 0;
                foreach (var resultType in stageSES.results.competitor)
                {
                    i++;
                    ApplyPropertyValue(true, $"Result{i}_Climber", resultType.climber, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_ClimberRanking", resultType.climber_ranking, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_Id", resultType.id, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_Points", resultType.points, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_Sprint", resultType.sprint, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_SprintRanking", resultType.sprint_ranking, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_Status", resultType.status, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_StatusComment", resultType.status_comment, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_Time", resultType.time, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_TimeRanking", resultType.time_ranking, tempProperties);

                    eventResults.Add(new EventResultDTO(resultType));
                }
                EventResults = eventResults;
            }

            ApplyPropertyValue(true, "WinnerId", stageSES.winner_id, tempProperties);
            ApplyPropertyValue(stageSES.period_of_leaderSpecified, "period_of_leader", stageSES.period_of_leader, tempProperties);

            Properties = new ReadOnlyDictionary <string, object>(tempProperties);

            Status = MessageMapperHelper.GetEnumValue(stageSES.status, EventStatus.Unknown);
            ApplyPropertyValue(true, "Status", (int)Status, tempProperties);

            MatchStatusId = -1;

            WinnerId = !string.IsNullOrEmpty(stageSES.winner_id) ? URN.Parse(stageSES.winner_id) : null;

            PeriodOfLadder = stageSES.period_of_leaderSpecified ? stageSES.period_of_leader : (int?)null;

            ReportingStatus = ReportingStatus.Unknown;

            PeriodScores = null;

            EventClock = null;

            SportEventStatistics = null;
        }
        public void CorrectEnumValuesAreResolved()
        {
            var active = MessageMapperHelper.GetEnumValue <MarketStatus>(1);

            Assert.AreEqual(active, MarketStatus.ACTIVE, "Value of active must be MarketStatus.ACTIVE");

            var suspended = MessageMapperHelper.GetEnumValue <MarketStatus>(-1);

            Assert.AreEqual(suspended, MarketStatus.SUSPENDED, "Value of active must be MarketStatus.SUSPENDED");

            var deactivated = MessageMapperHelper.GetEnumValue <MarketStatus>(0);

            Assert.AreEqual(deactivated, MarketStatus.INACTIVE, "Value of active must be MarketStatus.DEACTIVATED");
        }
예제 #10
0
        /// <summary>
        /// Gets the new <see cref="IMarketWithOdds"/> instance
        /// </summary>
        /// <param name="sportEvent">A <see cref="ISportEvent"/> representing the sport event associated with the generated message</param>
        /// <param name="marketOddsChange">The <see cref="oddsChangeMarket"/> instance used</param>
        /// <param name="producerId">A producerId of the <see cref="ISportEvent"/></param>
        /// <param name="sportId">A sportId of the <see cref="ISportEvent"/></param>
        /// <param name="cultures">The list of cultures that should be prefetched</param>
        /// <returns>Returns the new <see cref="IMarketWithOdds"/> instance</returns>
        protected virtual IMarketWithOdds GetMarketWithOdds(ISportEvent sportEvent, oddsChangeMarket marketOddsChange, int producerId, URN sportId, IEnumerable <CultureInfo> cultures)
        {
            var cultureInfos = cultures.ToList();
            var specifiers   = string.IsNullOrEmpty(marketOddsChange.specifiers)
                ? null
                : FeedMapperHelper.GetSpecifiers(marketOddsChange.specifiers);

            var additionalInfo = string.IsNullOrEmpty(marketOddsChange.extended_specifiers)
                ? null
                : FeedMapperHelper.GetSpecifiers(marketOddsChange.extended_specifiers);

            var marketMetadata = new MarketMetadata(marketOddsChange.market_metadata);

            var nameProvider    = _nameProviderFactory.BuildNameProvider(sportEvent, marketOddsChange.id, specifiers);
            var mappingProvider = _mappingProviderFactory.BuildMarketMappingProvider(sportEvent, marketOddsChange.id, specifiers, producerId, sportId);

            var outcomes = marketOddsChange.outcome?.Select(outcome =>
                                                            GetOutcomeWithOdds(sportEvent,
                                                                               nameProvider,
                                                                               mappingProvider,
                                                                               outcome,
                                                                               cultureInfos,
                                                                               new OutcomeDefinition(marketOddsChange.id, outcome.id, _marketCacheProvider, specifiers, cultureInfos, _externalExceptionStrategy)));

            var marketDefinition = new MarketDefinition(marketOddsChange.id, _marketCacheProvider, sportId, producerId, specifiers, cultureInfos, _externalExceptionStrategy);

            return(new MarketWithOdds(marketOddsChange.id,
                                      specifiers,
                                      additionalInfo,
                                      nameProvider,
                                      mappingProvider,
                                      MessageMapperHelper.GetEnumValue <MarketStatus>(marketOddsChange.status),
                                      marketOddsChange.cashout_statusSpecified ? (CashoutStatus?)MessageMapperHelper.GetEnumValue <CashoutStatus>(marketOddsChange.cashout_status) : null,
                                      marketOddsChange.favouriteSpecified && marketOddsChange.favourite == 1,
                                      outcomes,
                                      marketMetadata,
                                      marketDefinition,
                                      cultureInfos));
        }
        private void TestEntityValues(IOddsChange <ICompetition> entity, odds_change record, AssertHelper assertHelper)
        {
            TestEventMessageProperties(assertHelper, entity, record.timestamp, record.product, record.event_id, record.RequestId);
            assertHelper.AreEqual(() => entity.ChangeReason,
                                  MessageMapperHelper.GetEnumValue <OddsChangeReason>(record.odds_change_reason));

            if (record.odds.betstop_reasonSpecified)
            {
                assertHelper.AreEqual(() => entity.BetStopReason.Id, record.odds.betstop_reason);
            }
            else
            {
                assertHelper.IsNull(() => entity.BetStopReason);
            }

            if (record.odds.betting_statusSpecified)
            {
                assertHelper.AreEqual(() => entity.BettingStatus.Id, record.odds.betting_status);
            }
            else
            {
                assertHelper.IsNull(() => entity.BettingStatus);
            }

            if (record.odds?.market == null || record.odds.market.Length == 0)
            {
                Assert.IsNull(entity.Markets);
            }
            else
            {
                foreach (var marketRecord in record.odds.market)
                {
                    var market = FindMarket(entity.Markets, marketRecord.id, marketRecord.specifiers);
                    Assert.IsNotNull(market, $"Market with id={marketRecord.id} does not exist on mapped message");
                    TestMarketValues(market, marketRecord);
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Return the status of player. Possible values are: player is playing, player is stopped, player was never playing.
        /// </summary>
        /// <returns>A <see cref="IReplayStatus"/></returns>
        public IReplayStatus GetStatusOfReplay()
        {
            var uri = new Uri($"{_apiHost}/status{BuildNodeIdQuery("?")}");

            var response = _dataRestful.GetDataAsync(uri).Result;

            if (response == null)
            {
                HandleHttpResponseMessage(null);
                return(new ReplayStatus(null, ReplayPlayerStatus.NotStarted));
            }

            var xml = new XmlDocument {
                XmlResolver = null
            };

            xml.Load(response);

            string urn    = null;
            string status = null;

            if (xml.DocumentElement != null && xml.DocumentElement.HasAttribute("last_msg_from_event"))
            {
                urn = xml.DocumentElement.Attributes["last_msg_from_event"].Value;
            }
            if (xml.DocumentElement != null && xml.DocumentElement.HasAttribute("status"))
            {
                status = xml.DocumentElement.Attributes["status"].Value;
            }
            var eventId = string.IsNullOrEmpty(urn) ? null : URN.Parse(urn);

            if (string.IsNullOrEmpty(status))
            {
                throw new HttpRequestException("Status value missing");
            }

            return(new ReplayStatus(eventId, MessageMapperHelper.GetEnumValue(status, ReplayPlayerStatus.NotStarted)));
        }
        private void TestMarketValues(IMarketWithOdds entity, oddsChangeMarket record)
        {
            Assert.AreEqual(entity.Id, record.id, "Market id is not correct");
            Assert.IsTrue(CompareSpecifiers(entity.Specifiers, record.specifiers), "The market specifiers do not match");
            Assert.IsTrue(CompareSpecifiers(entity.AdditionalInfo, record.extended_specifiers), "Market additional specifiers do not match");
            Assert.AreEqual(entity.CashoutStatus, record.cashout_statusSpecified ? (CashoutStatus?)MessageMapperHelper.GetEnumValue <CashoutStatus>(record.cashout_status) : null, $"Market id={entity.Id} cashout status do not match");
            Assert.AreEqual(entity.IsFavorite, record.favouriteSpecified && record.favourite == 1, $"Market id={entity.Id} favorite does not match");
            Assert.AreEqual(entity.Status, MessageMapperHelper.GetEnumValue <MarketStatus>(record.status), $"Market id={entity.Id} status does not match");


            if (record.outcome == null || record.outcome.Length == 0)
            {
                Assert.IsNull(entity.OutcomeOdds);
            }
            else
            {
                foreach (var outcomeRecord in record.outcome)
                {
                    var outcome = FindOutcome(entity.OutcomeOdds, outcomeRecord.id);
                    Assert.IsNotNull(outcome, $"Outcome marketId={entity.Id} id={outcomeRecord.id} does not exist");
                    TestOutcomeValues(outcome, outcomeRecord);
                }
            }
        }
예제 #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SportEventStatusDTO"/> class
        /// </summary>
        /// <param name="ses">A <see cref="sportEventStatus" /> instance containing status data about the associated sport event</param>
        /// <param name="homeAwayCompetitors">The list of competitors with the indicator if it is a home or away team</param>
        public SportEventStatusDTO(sportEventStatus ses, IDictionary <HomeAway, URN> homeAwayCompetitors)
        {
            Guard.Argument(ses, nameof(ses)).NotNull();

            _homeAwayCompetitors = homeAwayCompetitors;

            var tempProperties = new Dictionary <string, object>();

            ApplyPropertyValue(ses.throwSpecified, THROW_PROPERTY, ses.@throw, tempProperties);
            ApplyPropertyValue(ses.trySpecified, TRY_PROPERTY, ses.@try, tempProperties);
            ApplyPropertyValue(ses.away_batterSpecified, AWAY_BATTER_PROPERTY, ses.away_batter, tempProperties);
            ApplyPropertyValue(ses.away_dismissalsSpecified, AWAY_DISMISSALS_PROPERTY, ses.away_dismissals, tempProperties);
            ApplyPropertyValue(ses.away_gamescoreSpecified, AWAY_GAME_SCORE_PROPERTY, ses.away_gamescore, tempProperties);
            ApplyPropertyValue(ses.away_legscoreSpecified, AWAY_LEG_SCORE_PROPERTY, ses.away_legscore, tempProperties);
            ApplyPropertyValue(ses.away_penalty_runsSpecified, AWAY_PENALTY_RUNS_PROPERTY, ses.away_penalty_runs, tempProperties);
            ApplyPropertyValue(ses.away_remaining_bowlsSpecified, AWAY_REMAINING_BOWLS_PROPERTY, ses.away_remaining_bowls, tempProperties);
            ApplyPropertyValue(ses.away_suspendSpecified, AWAY_SUSPEND_PROPERTY, ses.away_suspend, tempProperties);
            ApplyPropertyValue(ses.away_scoreSpecified, "AwayScore", ses.away_score, tempProperties); // BELOW
            ApplyPropertyValue(ses.ballsSpecified, BALLS_PROPERTY, ses.balls, tempProperties);
            ApplyPropertyValue(!string.IsNullOrEmpty(ses.bases), BASES_PROPERTY, ses.bases, tempProperties);
            ApplyPropertyValue(ses.current_ct_teamSpecified, "CurrentCtTeam", ses.current_ct_team, tempProperties);
            ApplyPropertyValue(ses.current_endSpecified, "CurrentEnd", ses.current_end, tempProperties);
            ApplyPropertyValue(ses.current_serverSpecified, "CurrentServer", ses.current_server, tempProperties);
            ApplyPropertyValue(ses.deliverySpecified, "Delivery", ses.delivery, tempProperties);
            ApplyPropertyValue(ses.expedite_modeSpecified, "ExpediteMode", ses.expedite_mode, tempProperties);
            ApplyPropertyValue(ses.home_batterSpecified, HOME_BATTER_PROPERTY, ses.home_batter, tempProperties);
            ApplyPropertyValue(ses.home_dismissalsSpecified, HOME_DISMISSALS_PROPERTY, ses.home_dismissals, tempProperties);
            ApplyPropertyValue(ses.home_gamescoreSpecified, HOME_GAME_SCORE_PROPERTY, ses.home_gamescore, tempProperties);
            ApplyPropertyValue(ses.home_legscoreSpecified, HOME_LEG_SCORE_PROPERTY, ses.home_legscore, tempProperties);
            ApplyPropertyValue(ses.home_penalty_runsSpecified, HOME_PENALTY_RUNS_PROPERTY, ses.home_penalty_runs, tempProperties);
            ApplyPropertyValue(ses.home_remaining_bowlsSpecified, HOME_REMAINING_BOWLS_PROPERTY, ses.home_remaining_bowls, tempProperties);
            ApplyPropertyValue(ses.home_suspendSpecified, HOME_SUSPEND_PROPERTY, ses.home_suspend, tempProperties);
            ApplyPropertyValue(ses.home_scoreSpecified, "HomeScore", ses.home_score, tempProperties); // BELOW
            ApplyPropertyValue(ses.inningsSpecified, "Innings", ses.innings, tempProperties);
            ApplyPropertyValue(true, MATCH_STATUS, ses.match_status, tempProperties);                 //BELOW
            ApplyPropertyValue(ses.outsSpecified, "Outs", ses.outs, tempProperties);
            ApplyPropertyValue(ses.overSpecified, "Over", ses.over, tempProperties);
            ApplyPropertyValue(ses.positionSpecified, "Position", ses.position, tempProperties);
            ApplyPropertyValue(ses.possessionSpecified, "Possession", ses.possession, tempProperties);
            ApplyPropertyValue(ses.remaining_redsSpecified, "RemainingReds", ses.remaining_reds, tempProperties);
            ApplyPropertyValue(ses.reportingSpecified, "Reporting", ses.reporting, tempProperties); // BELOW
            ApplyPropertyValue(true, "Status", ses.status, tempProperties);                         //BELOW
            ApplyPropertyValue(ses.strikesSpecified, "Strikes", ses.strikes, tempProperties);
            ApplyPropertyValue(ses.tiebreakSpecified, "Tiebreak", ses.tiebreak, tempProperties);
            ApplyPropertyValue(ses.visitSpecified, "Visit", ses.visit, tempProperties);
            ApplyPropertyValue(ses.yardsSpecified, "Yards", ses.yards, tempProperties);
            ApplyPropertyValue(ses.home_penalty_scoreSpecified, "home_penalty_score", ses.home_penalty_score, tempProperties);
            ApplyPropertyValue(ses.away_penalty_scoreSpecified, "away_penalty_score", ses.away_penalty_score, tempProperties);
            ApplyPropertyValue(ses.period_of_leaderSpecified, "period_of_leader", ses.period_of_leader, tempProperties);
            ApplyPropertyValue(!string.IsNullOrEmpty(ses.pitcher), "pitcher", ses.pitcher, tempProperties);
            ApplyPropertyValue(!string.IsNullOrEmpty(ses.batter), "batter", ses.batter, tempProperties);
            ApplyPropertyValue(ses.pitch_countSpecified, "pitch_count", ses.pitch_count, tempProperties);
            ApplyPropertyValue(ses.pitches_seenSpecified, "pitches_seen", ses.pitches_seen, tempProperties);
            ApplyPropertyValue(ses.total_hitsSpecified, "total_hits", ses.total_hits, tempProperties);
            ApplyPropertyValue(ses.total_pitchesSpecified, "total_pitches", ses.total_pitches, tempProperties);
            ApplyPropertyValue(ses.home_drive_countSpecified, "home_drive_count", ses.home_drive_count, tempProperties);
            ApplyPropertyValue(ses.home_play_countSpecified, "home_play_count", ses.home_play_count, tempProperties);
            ApplyPropertyValue(ses.away_drive_countSpecified, "away_drive_count", ses.away_drive_count, tempProperties);
            ApplyPropertyValue(ses.away_play_countSpecified, "away_play_count", ses.away_play_count, tempProperties);

            if (ses.period_scores != null && ses.period_scores.Any())
            {
                var periodScores = new List <PeriodScoreDTO>();
                foreach (var periodScore in ses.period_scores)
                {
                    periodScores.Add(new PeriodScoreDTO(periodScore));
                    ApplyPropertyValue(true, $"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}_MatchStatusCode", periodScore.match_status_code, tempProperties);
                }
                PeriodScores = periodScores;
            }

            if (ses.clock != null)
            {
                EventClock = new EventClockDTO(ses.clock.match_time,
                                               ses.clock.stoppage_time,
                                               ses.clock.stoppage_time_announced,
                                               ses.clock.remaining_time,
                                               ses.clock.remaining_time_in_period,
                                               ses.clock.stoppedSpecified,
                                               ses.clock.stopped);
                ApplyPropertyValue(true, "Clock_MatchTime", ses.clock.match_time, tempProperties);
                ApplyPropertyValue(true, "Clock_RemainingTime", ses.clock.remaining_time, tempProperties);
                ApplyPropertyValue(true, "Clock_RemainingTimeInPeriod", ses.clock.remaining_time_in_period, tempProperties);
                ApplyPropertyValue(true, "Clock_StoppageTime", ses.clock.stoppage_time, tempProperties);
                ApplyPropertyValue(true, "Clock_StoppageTimeAnnounced", ses.clock.stoppage_time_announced, tempProperties);
                ApplyPropertyValue(ses.clock.stoppedSpecified, "Clock_Stopped", ses.clock.stopped, tempProperties);
            }

            if (ses.results != null && ses.results.Any())
            {
                var i = 0;
                foreach (var resultType in ses.results)
                {
                    i++;
                    ApplyPropertyValue(true, $"Result{i}_HomeScore", resultType.home_score, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_AwayScore", resultType.away_score, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_MatchStatusCode", resultType.match_status_code, tempProperties);
                }
            }

            Properties = new ReadOnlyDictionary <string, object>(tempProperties);

            Status = MessageMapperHelper.GetEnumValue(ses.status, EventStatus.Unknown);

            IsReported = ses.reportingSpecified
                ? (int?)ses.reporting
                : null;

            HomeScore = ses.home_scoreSpecified
                ? (decimal?)ses.home_score
                : null;

            AwayScore = ses.away_scoreSpecified
                ? (decimal?)ses.away_score
                : null;

            MatchStatusId = ses.match_status;

            WinnerId = null;

            PeriodOfLadder = ses.period_of_leaderSpecified ? ses.period_of_leader : (int?)null;

            if (ses.reportingSpecified)
            {
                ReportingStatus = MessageMapperHelper.GetEnumValue(ses.reporting, ReportingStatus.Unknown);
            }

            if (ses.results != null)
            {
                var eventResults = new List <EventResultDTO>();
                foreach (var result in ses.results)
                {
                    eventResults.Add(new EventResultDTO(result));
                }
                EventResults = eventResults;
            }

            if (ses.statistics != null)
            {
                SportEventStatistics = new SportEventStatisticsDTO(ses.statistics);
            }

            if (ses.home_penalty_scoreSpecified)
            {
                HomePenaltyScore = ses.home_penalty_score;
            }
            if (ses.away_penalty_scoreSpecified)
            {
                AwayPenaltyScore = ses.away_penalty_score;
            }

            // 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
                }
            }
        }
예제 #15
0
        /// <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);
            }
        }
 public void IncorrectMarketStatusesThrow()
 {
     MessageMapperHelper.GetEnumValue <MarketStatus>(2);
 }
        public void DefaultValueIsReturned()
        {
            var active = MessageMapperHelper.GetEnumValue(false, 99, MarketStatus.ACTIVE);

            Assert.AreEqual(active, MarketStatus.ACTIVE, "Value of active must be MarketStatus.ACTIVE");
        }
예제 #18
0
        /// <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>
        public SportEventStatusDTO(stageSportEventStatus record)
        {
            Contract.Requires(record != null);

            var tempProperties = new Dictionary <string, object>(0);

            if (record.results != null && record.results.Any())
            {
                var i = 0;
                foreach (var resultType in record.results)
                {
                    i++;
                    ApplyPropertyValue(true, $"Result{i}_Climber", resultType.climber, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_ClimberRanking", resultType.climber_ranking, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_Id", resultType.id, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_Points", resultType.points, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_Sprint", resultType.sprint, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_SprintRanking", resultType.sprint_ranking, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_Status", resultType.status, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_StatusComment", resultType.status_comment, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_Time", resultType.time, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_TimeRanking", resultType.time_ranking, tempProperties);
                }
            }

            ApplyPropertyValue(true, "WinnerId", record.winner_id, tempProperties);

            Properties = new ReadOnlyDictionary <string, object>(tempProperties);

            Status = MessageMapperHelper.GetEnumValue(record.status, EventStatus.Unknown);
            ApplyPropertyValue(true, "Status", (int)Status, tempProperties);
            //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;

            //if (!string.IsNullOrEmpty(record.status))
            //{
            //    int statusId;
            //    int.TryParse(record.status, out statusId);
            //    MatchStatusId = statusId;
            //}

            MatchStatusId = -1;

            WinnerId = !string.IsNullOrEmpty(record.winner_id) ? URN.Parse(record.winner_id) : null;

            ReportingStatus = ReportingStatus.Unknown;

            PeriodScores = null;

            EventClock = null;

            var eventResults = new List <EventResultDTO>();

            if (record.results != null && record.results.Any())
            {
                foreach (var stageResultCompetitor in record.results)
                {
                    eventResults.Add(new EventResultDTO(stageResultCompetitor));
                }

                EventResults = eventResults;
            }

            SportEventStatistics = null;
        }
예제 #19
0
        /// <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="homeAwayCompetitors">The list of competitors with the indicator if it is a home or away team</param>
        public SportEventStatusDTO(sportEventStatus record, IDictionary <HomeAway, URN> homeAwayCompetitors)
        {
            Contract.Requires(record != null);

            _homeAwayCompetitors = homeAwayCompetitors;

            var tempProperties = new Dictionary <string, object>();

            ApplyPropertyValue(record.throwSpecified, THROW_PROPERTY, record.@throw, tempProperties);
            ApplyPropertyValue(record.trySpecified, TRY_PROPERTY, record.@try, tempProperties);
            ApplyPropertyValue(record.away_batterSpecified, AWAY_BATTER_PROPERTY, record.away_batter, tempProperties);
            ApplyPropertyValue(record.away_dismissalsSpecified, AWAY_DISMISSALS_PROPERTY, record.away_dismissals,
                               tempProperties);
            ApplyPropertyValue(record.away_gamescoreSpecified, AWAY_GAME_SCORE_PROPERTY, record.away_gamescore,
                               tempProperties);
            ApplyPropertyValue(record.away_legscoreSpecified, AWAY_LEG_SCORE_PROPERTY, record.away_legscore,
                               tempProperties);
            ApplyPropertyValue(record.away_penalty_runsSpecified, AWAY_PENALTY_RUNS_PROPERTY, record.away_penalty_runs,
                               tempProperties);
            ApplyPropertyValue(record.away_remaining_bowlsSpecified, AWAY_REMAINING_BOWLS_PROPERTY,
                               record.away_remaining_bowls, tempProperties);
            ApplyPropertyValue(record.away_suspendSpecified, AWAY_SUSPEND_PROPERTY, record.away_suspend,
                               tempProperties);
            ApplyPropertyValue(record.away_scoreSpecified, "AwayScore", record.away_score, tempProperties); // BELOW
            ApplyPropertyValue(record.ballsSpecified, BALLS_PROPERTY, record.balls, tempProperties);
            ApplyPropertyValue(!string.IsNullOrEmpty(record.bases), BASES_PROPERTY, record.bases, tempProperties);
            ApplyPropertyValue(record.current_ct_teamSpecified, "CurrentCtTeam", record.current_ct_team,
                               tempProperties);
            ApplyPropertyValue(record.current_endSpecified, "CurrentEnd", record.current_end, tempProperties);
            ApplyPropertyValue(record.current_serverSpecified, "CurrentServer", record.current_server, tempProperties);
            ApplyPropertyValue(record.deliverySpecified, "Delivery", record.delivery, tempProperties);
            ApplyPropertyValue(record.expedite_modeSpecified, "ExpediteMode", record.expedite_mode, tempProperties);
            ApplyPropertyValue(record.home_batterSpecified, HOME_BATTER_PROPERTY, record.home_batter, tempProperties);
            ApplyPropertyValue(record.home_dismissalsSpecified, HOME_DISMISSALS_PROPERTY, record.home_dismissals,
                               tempProperties);
            ApplyPropertyValue(record.home_gamescoreSpecified, HOME_GAME_SCORE_PROPERTY, record.home_gamescore,
                               tempProperties);
            ApplyPropertyValue(record.home_legscoreSpecified, HOME_LEG_SCORE_PROPERTY, record.home_legscore,
                               tempProperties);
            ApplyPropertyValue(record.home_penalty_runsSpecified, HOME_PENALTY_RUNS_PROPERTY, record.home_penalty_runs,
                               tempProperties);
            ApplyPropertyValue(record.home_remaining_bowlsSpecified, HOME_REMAINING_BOWLS_PROPERTY,
                               record.home_remaining_bowls, tempProperties);
            ApplyPropertyValue(record.home_suspendSpecified, HOME_SUSPEND_PROPERTY, record.home_suspend,
                               tempProperties);
            ApplyPropertyValue(record.home_scoreSpecified, "HomeScore", record.home_score, tempProperties); // BELOW
            ApplyPropertyValue(record.inningsSpecified, "Innings", record.innings, tempProperties);
            ApplyPropertyValue(true, MATCH_STATUS, record.match_status, tempProperties);                    //BELOW
            ApplyPropertyValue(record.outsSpecified, "Outs", record.outs, tempProperties);
            ApplyPropertyValue(record.overSpecified, "Over", record.over, tempProperties);
            ApplyPropertyValue(record.positionSpecified, "Position", record.position, tempProperties);
            ApplyPropertyValue(record.possessionSpecified, "Possession", record.possession, tempProperties);
            ApplyPropertyValue(record.remaining_redsSpecified, "RemainingReds", record.remaining_reds, tempProperties);
            ApplyPropertyValue(record.reportingSpecified, "Reporting", record.reporting, tempProperties); // BELOW
            ApplyPropertyValue(true, "Status", record.status, tempProperties);                            //BELOW
            ApplyPropertyValue(record.strikesSpecified, "Strikes", record.strikes, tempProperties);
            ApplyPropertyValue(record.tiebreakSpecified, "Tiebreak", record.tiebreak, tempProperties);
            ApplyPropertyValue(record.visitSpecified, "Visit", record.visit, tempProperties);
            ApplyPropertyValue(record.yardsSpecified, "Yards", record.yards, tempProperties);
            ApplyPropertyValue(record.home_penalty_scoreSpecified, "home_penalty_score", record.home_penalty_score,
                               tempProperties);
            ApplyPropertyValue(record.away_penalty_scoreSpecified, "away_penalty_score", record.away_penalty_score,
                               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));
                    ApplyPropertyValue(true, $"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}_MatchStatusCode",
                                       periodScore.match_status_code, tempProperties);
                }

                PeriodScores = periodScores;
            }

            if (record.clock != null)
            {
                EventClock = new EventClockDTO(record.clock.match_time,
                                               record.clock.stoppage_time,
                                               record.clock.stoppage_time_announced,
                                               record.clock.remaining_time,
                                               record.clock.remaining_time_in_period,
                                               record.clock.stoppedSpecified,
                                               record.clock.stopped);
                ApplyPropertyValue(true, "Clock_MatchTime", record.clock.match_time, tempProperties);
                ApplyPropertyValue(true, "Clock_RemainingTime", record.clock.remaining_time, tempProperties);
                ApplyPropertyValue(true, "Clock_RemainingTimeInPeriod", record.clock.remaining_time_in_period,
                                   tempProperties);
                ApplyPropertyValue(true, "Clock_StoppageTime", record.clock.stoppage_time, tempProperties);
                ApplyPropertyValue(true, "Clock_StoppageTimeAnnounced", record.clock.stoppage_time_announced,
                                   tempProperties);
                ApplyPropertyValue(record.clock.stoppedSpecified, "Clock_Stopped", record.clock.stopped,
                                   tempProperties);
            }

            if (record.results != null && record.results.Any())
            {
                var i = 0;
                foreach (var resultType in record.results)
                {
                    i++;
                    ApplyPropertyValue(true, $"Result{i}_HomeScore", resultType.home_score, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_AwayScore", resultType.away_score, tempProperties);
                    ApplyPropertyValue(true, $"Result{i}_MatchStatusCode", resultType.match_status_code,
                                       tempProperties);
                }
            }

            Properties = new ReadOnlyDictionary <string, object>(tempProperties);

            Status = MessageMapperHelper.GetEnumValue(record.status, EventStatus.Unknown);

            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;

            MatchStatusId = record.match_status;

            WinnerId = null;

            if (record.reportingSpecified)
            {
                ReportingStatus = MessageMapperHelper.GetEnumValue(record.reporting, ReportingStatus.Unknown);
            }

            if (record.results != null)
            {
                var eventResults = new List <EventResultDTO>();
                foreach (var result in record.results)
                {
                    eventResults.Add(new EventResultDTO(result));
                }
                EventResults = eventResults;
            }

            if (record.statistics != null)
            {
                SportEventStatistics = new SportEventStatisticsDTO(record.statistics);
            }

            if (record.home_penalty_scoreSpecified)
            {
                HomePenaltyScore = record.home_penalty_score;
            }
            if (record.away_penalty_scoreSpecified)
            {
                AwayPenaltyScore = record.away_penalty_score;
            }
        }
예제 #20
0
        /// <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
                }
            }
        }