private void FixtureChange(fixture_change e, dbEntities db, string routeKey)
        {
            var sectionName = string.Empty;

            using (var dbContextTransaction = db.Database.BeginTransaction())
            {
                try
                {
                    sectionName = "fixture_change";
                    var spParams = "EXECUTE PROCEDURE BET_EVENTFIXTURECHANGE_I(";
                    spParams += SourceId + ",";
                    spParams += e.event_id.Split(':').Last() + ",";
                    spParams += e.product + ",";
                    spParams += e.change_type + ",";
                    spParams += e.GeneratedAt + ")";
                    db.Database.ExecuteSqlCommand(spParams.Trim());

                    dbContextTransaction.Commit();
                    SerilogHelper.Information(string.Format("{0} {1}", routeKey, UtcHelper.GetDifferenceFromTimestamp(e.timestamp) + "ms"));
                }
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();
                    SerilogHelper.Exception(string.Format("Unknown exception in {0} {1} {2}", routeKey, sectionName, e.event_id), ex);
                }
            }
        }
示例#2
0
        public IFixtureChange <T> MapFixtureChange <T>(fixture_change message, IEnumerable <CultureInfo> cultures, byte[] rawMessage) where T : ISportEvent
        {
            Contract.Requires(message != null);
            Contract.Ensures(Contract.Result <IFixtureChange <T> >() != null);

            return(Contract.Result <IFixtureChange <T> >());
        }
 private ValidationResult ValidateFixtureChangeType(fixture_change message)
 {
     if (message.change_typeSpecified && !MessageMapperHelper.IsEnumMember <FixtureChangeType>(message.change_type))
     {
         return(ValidationResult.PROBLEMS_DETECTED);
     }
     return(ValidationResult.SUCCESS);
 }
 private void TestEntityValues(IFixtureChange <ICompetition> entity, fixture_change record, AssertHelper assertHelper)
 {
     TestEventMessageProperties(assertHelper, entity, record.timestamp, record.product, record.event_id, record.RequestId);;
     assertHelper.AreEqual(() => (int)entity.ChangeType, record.change_typeSpecified
                                                         ? (int?)record.change_type
                                                         : (int)FixtureChangeType.OTHER);
     assertHelper.AreEqual(() => entity.NextLiveTime, record.next_live_timeSpecified
                                                         ? (long?)record.next_live_time
                                                         : null);
     assertHelper.AreEqual(() => entity.StartTime, record.start_time);
 }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OddsChangeEventArgs{T}"/> class
        /// </summary>
        /// <param name="messageMapper">A <see cref="IFeedMessageMapper"/> used to map feed message to the one dispatched to the user</param>
        /// <param name="feedMessage">A <see cref="fixture_change"/> message received from the feed</param>
        /// <param name="cultures">A <see cref="IEnumerable{CultureInfo}"/> specifying the default languages to which the received message is translated</param>
        /// <param name="rawMessage">A raw message received from the feed</param>
        internal FixtureChangeEventArgs(IFeedMessageMapper messageMapper, fixture_change feedMessage, IEnumerable <CultureInfo> cultures, byte[] rawMessage)
        {
            Guard.Argument(messageMapper, nameof(messageMapper)).NotNull();
            Guard.Argument(feedMessage, nameof(feedMessage)).NotNull();
            Guard.Argument(cultures, nameof(cultures)).NotNull().NotEmpty();

            _messageMapper   = messageMapper;
            _feedMessage     = feedMessage;
            _defaultCultures = cultures as IReadOnlyCollection <CultureInfo>;
            _rawMessage      = rawMessage;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OddsChangeEventArgs{T}"/> class
        /// </summary>
        /// <param name="messageMapper">A <see cref="IFeedMessageMapper"/> used to map feed message to the one dispatched to the user</param>
        /// <param name="feedMessage">A <see cref="fixture_change"/> message received from the feed</param>
        /// <param name="cultures">A <see cref="IEnumerable{CultureInfo}"/> specifying the default languages to which the received message is translated</param>
        /// <param name="rawMessage">A raw message received from the feed</param>
        internal FixtureChangeEventArgs(IFeedMessageMapper messageMapper, fixture_change feedMessage, IEnumerable <CultureInfo> cultures, byte[] rawMessage)
        {
            Contract.Requires(messageMapper != null);
            Contract.Requires(feedMessage != null);
            Contract.Requires(cultures != null && cultures.Any());

            _messageMapper   = messageMapper;
            _feedMessage     = feedMessage;
            _defaultCultures = cultures as IReadOnlyCollection <CultureInfo>;
            _rawMessage      = 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="OddsChangeEventArgs{T}"/> class
        /// </summary>
        /// <param name="messageMapper">A <see cref="IFeedMessageMapper"/> used to map feed message to the one dispatched to the user</param>
        /// <param name="feedMessage">A <see cref="fixture_change"/> message received from the feed</param>
        /// <param name="cultures">A <see cref="IEnumerable{CultureInfo}"/> specifying the default languages to which the received message is translated</param>
        /// <param name="rawMessage">A raw message received from the feed</param>
        internal FixtureChangeEventArgs(IFeedMessageMapper messageMapper, fixture_change feedMessage, IEnumerable <CultureInfo> cultures, byte[] rawMessage)
        {
            Guard.Argument(messageMapper, nameof(messageMapper)).NotNull();
            Guard.Argument(feedMessage, nameof(feedMessage)).NotNull();
            if (!cultures.Any())
            {
                throw new ArgumentOutOfRangeException(nameof(cultures));
            }

            _messageMapper   = messageMapper;
            _feedMessage     = feedMessage;
            _defaultCultures = cultures as IReadOnlyCollection <CultureInfo>;
            _rawMessage      = rawMessage;

            _fixtureChange = GetFixtureChange();
        }
示例#9
0
        /// <summary>
        /// Validates the provided <see cref="fixture_change" /> message
        /// </summary>
        /// <param name="message">The <see cref="fixture_change" /> message to validate</param>
        /// <returns>The <see cref="ValidationResult" /> specifying the result of validation</returns>
        protected ValidationResult ValidateFixtureChange(fixture_change message)
        {
            Contract.Requires(message != null);

            ValidateMessageProducer(message);

            if (!ValidateMessage(message))
            {
                return(ValidationResult.FAILURE);
            }

            if (message.change_typeSpecified && !MessageMapperHelper.IsEnumMember <FixtureChangeType>(message.change_type))
            {
                LogWarning(message, "change_type", message.change_type);
                return(ValidationResult.PROBLEMS_DETECTED);
            }
            return(ValidationResult.SUCCESS);
        }
        /// <summary>
        /// Validates the provided <see cref="fixture_change" /> message
        /// </summary>
        /// <param name="message">The <see cref="fixture_change" /> message to validate</param>
        /// <returns>The <see cref="ValidationResult" /> specifying the result of validation</returns>
        protected ValidationResult ValidateFixtureChange(fixture_change message)
        {
            Guard.Argument(message, nameof(message)).NotNull();

            ValidateMessageProducer(message);

            if (!ValidateMessage(message))
            {
                return(ValidationResult.FAILURE);
            }

            if (message.change_typeSpecified && !MessageMapperHelper.IsEnumMember <FixtureChangeType>(message.change_type))
            {
                LogWarning(message, "change_type", message.change_type);
                return(ValidationResult.PROBLEMS_DETECTED);
            }
            return(ValidationResult.SUCCESS);
        }
        /// <summary>
        /// Stops the processing fixture change (so it is not dispatched twice)
        /// </summary>
        /// <param name="fixtureChange">The fixture change</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        public bool StopProcessingFixtureChange(fixture_change fixtureChange)
        {
            if (fixtureChange == null)
            {
                return(false);
            }

            lock (_lock)
            {
                var fixtureCacheId = GenerateFixtureChangeId(fixtureChange);
                if (_fixtureCache.Contains(fixtureCacheId))
                {
                    return(true);
                }

                _fixtureCache.Add(fixtureCacheId, fixtureCacheId, _cacheItemPolicy);
                return(false);
            }
        }
示例#12
0
        /// <summary>
        /// Stops the processing fixture change (so it is not dispatched twice)
        /// </summary>
        /// <param name="fixtureChange">The fixture change</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        public bool StopProcessingFixtureChange(fixture_change fixtureChange)
        {
            if (fixtureChange == null)
            {
                return(false);
            }

            lock (_lock)
            {
                var fixtureCacheId = GenerateFixtureChangeId(fixtureChange);
                if (_fixtureCache.Contains(fixtureCacheId))
                {
                    //ExecutionLog.Debug($"Processing fixtureChange for id={fixtureChange.EventId}, producer={fixtureChange.ProducerId} and timestamp={fixtureChange.GeneratedAt} stopped. Already processed.");
                    return(true);
                }

                _fixtureCache.Add(fixtureCacheId, fixtureCacheId, _cacheItemPolicy);
                //ExecutionLog.Debug($"Processing fixtureChange for id={fixtureChange.EventId}, producer={fixtureChange.ProducerId} and timestamp={fixtureChange.GeneratedAt}.");
                return(false);
            }
        }
        /// <summary>
        /// Dispatches the <see cref="fixture_change"/> message
        /// </summary>
        /// <param name="message">The <see cref="fixture_change"/> message to dispatch</param>
        /// <param name="rawMessage">A raw message received from the feed</param>
        private void DispatchFixtureChange(fixture_change message, byte[] rawMessage)
        {
            var eventArgs = new FixtureChangeEventArgs <T>(MessageMapper, message, DefaultCultures, rawMessage);

            Dispatch(OnFixtureChange, eventArgs, message);
        }
示例#14
0
 private string GenerateFixtureChangeId(fixture_change fixtureChange)
 {
     return($"{fixtureChange.EventId}_{fixtureChange.ProducerId}_{fixtureChange.GeneratedAt}");
 }