Ejemplo n.º 1
0
        /// <summary>
        /// Processes and dispatches the provided <see cref="FeedMessage" /> instance
        /// </summary>
        /// <param name="message">A <see cref="FeedMessage" /> instance to be processed</param>
        /// <param name="interest">A <see cref="MessageInterest"/> specifying the interest of the associated session</param>
        /// <param name="rawMessage">A raw message received from the feed</param>
        public void ProcessMessage(FeedMessage message, MessageInterest interest, byte[] rawMessage)
        {
            Guard.Argument(message, nameof(message)).NotNull();
            Guard.Argument(interest, nameof(interest)).NotNull();

            // process odds_change
            var oddsChange = message as odds_change;

            if (oddsChange?.sport_event_status != null)
            {
                var status = _mapperFactory.CreateMapper(oddsChange.sport_event_status).Map();
                _cacheManager.SaveDto(oddsChange.EventURN, status, CultureInfo.CurrentCulture, DtoType.SportEventStatus, null);
            }

            var betStop = message as bet_stop;

            if (betStop != null)
            {
                // draw event is still removed
                RemoveCacheItem(betStop.EventURN, removeEvent: false, removeSportEventStatus: true);
            }

            var betSettlement = message as bet_settlement;

            if (betSettlement != null)
            {
                // draw event is still removed
                RemoveCacheItem(betSettlement.EventURN, removeEvent: false, removeSportEventStatus: false);
            }

            // process fixtureChange
            var fixtureChange = message as fixture_change;

            if (fixtureChange != null)
            {
                RemoveCacheItem(fixtureChange.EventURN, removeEvent: true, removeSportEventStatus: true);
                _sportEventCache.AddFixtureTimestamp(fixtureChange.EventURN);

                if (fixtureChange.EventURN.TypeGroup == ResourceTypeGroup.TOURNAMENT)
                {
                    HandleTournamentFixtureChange(fixtureChange.EventURN);
                }

                if (_feedMessageHandler.StopProcessingFixtureChange(fixtureChange))
                {
                    // fixtureChange was already dispatched (via another session)
                    return;
                }
            }

            RaiseOnMessageProcessedEvent(new FeedMessageReceivedEventArgs(message, interest, rawMessage));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets a <see cref="!:T" /> instance in language specified by the provided <code>languageCode</code>
        /// </summary>
        /// <param name="languageCode">A two letter language code of the <see cref="T:System.Globalization.CultureInfo" /></param>
        /// <returns>A <see cref="T:System.Threading.Tasks.Task`1" /> representing the async operation</returns>
        public new virtual BookmakerDetailsDTO GetData(string languageCode)
        {
            var uri    = GetRequestUri(languageCode);
            var stream = _fetcher.GetData(uri);
            var bookmakerDetailsDTO = _mapperFactory.CreateMapper(_deserializer.Deserialize(stream)).Map();

            bookmakerDetailsDTO.ServerTimeDifference = TimeSpan.Zero;

            if (_fetcher is HttpDataFetcher httpDataFetcher)
            {
                if (httpDataFetcher.ResponseHeaders != null && httpDataFetcher.ResponseHeaders.TryGetValue("Date", out var x))
                {
                    var date = SdkInfo.ParseDate(x.FirstOrDefault());
                    if (date != null)
                    {
                        bookmakerDetailsDTO.ServerTimeDifference = DateTime.Now - date.Value;
                    }
                }
            }

            return(bookmakerDetailsDTO);
        }