Пример #1
0
        private void BetCancel(bet_cancel e, dbEntities db, string routeKey)
        {
            var sectionName = string.Empty;

            using (var dbContextTransaction = db.Database.BeginTransaction())
            {
                try
                {
                    sectionName = "bet_cancel";
                    foreach (var market in e.market)
                    {
                        var specifier = market.specifiers?.Split('=').LastOrDefault().Trim();
                        var spParams  = "EXECUTE PROCEDURE BET_EVENTBETCANCEL_I(";
                        spParams += SourceId + ",";
                        spParams += e.event_id.Split(':').Last() + ",";
                        spParams += e.product + ",";
                        spParams += e.start_time + ",";
                        spParams += e.end_time + ",";
                        spParams += market.id + ",";
                        spParams += "'" + specifier + "',";
                        spParams += market.void_reason + ",";
                        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 IBetCancel <T> MapBetCancel <T>(bet_cancel message, IEnumerable <CultureInfo> cultures, byte[] rawMessage) where T : ISportEvent
        {
            Contract.Requires(message != null);
            Contract.Ensures(Contract.Result <IBetCancel <T> >() != null);

            return(Contract.Result <IBetCancel <T> >());
        }
        /// <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="bet_cancel"/> 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 BetCancelEventArgs(IFeedMessageMapper messageMapper, bet_cancel 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;
        }
Пример #4
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="bet_cancel"/> 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 BetCancelEventArgs(IFeedMessageMapper messageMapper, bet_cancel 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;
        }
Пример #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="bet_cancel"/> 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 BetCancelEventArgs(IFeedMessageMapper messageMapper, bet_cancel 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;

            _betCancel = GetBetCancel();
        }
Пример #6
0
        /// <summary>
        /// Maps (converts) the provided <see cref="bet_cancel"/> instance to the <see cref="IBetCancel{T}"/> instance
        /// </summary>
        /// <param name="message">A <see cref="bet_cancel"/> 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="IBetCancel{T}"/> instance constructed from information in the provided <see cref="bet_cancel"/></returns>
        public IBetCancel <T> MapBetCancel <T>(bet_cancel message, IEnumerable <CultureInfo> cultures, byte[] rawMessage) where T : ISportEvent
        {
            var culturesList = cultures as List <CultureInfo> ?? cultures.ToList();

            return(new BetCancel <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,
                       message.start_timeSpecified ? (long?)message.start_time : null,
                       message.end_timeSpecified ? (long?)message.end_time : null,
                       string.IsNullOrEmpty(message.superceded_by)
                    ? null
                    : URN.Parse(message.superceded_by),
                       message.market.Select(m => GetMarketCancel(GetEventForNameProvider <T>(URN.Parse(message.event_id), message.SportId, culturesList), m, message.ProducerId, message.SportId, culturesList)),
                       rawMessage));
        }
        /// <summary>
        /// Validates the provided <see cref="bet_cancel"/> message
        /// </summary>
        /// <param name="message">The <see cref="bet_cancel" /> message to validate</param>
        /// <returns>The <see cref="ValidationResult" /> specifying the result of validation</returns>
        protected ValidationResult ValidateBetCancel(bet_cancel message)
        {
            ValidateMessageProducer(message);

            var result = ValidateMessageWithMarkets(message, message.market);

            if (!string.IsNullOrEmpty(message.superceded_by) && !URN.TryParse(message.superceded_by, out _))
            {
                //set the value to null so it will not be processed by the message mapper
                message.superceded_by = null;
                LogWarning(message, "superseded_by", message.superceded_by);
                if (result == ValidationResult.SUCCESS)
                {
                    result = ValidationResult.PROBLEMS_DETECTED;
                }
            }
            return(result);
        }
        /// <summary>
        /// Dispatches the <see cref="bet_cancel"/> message
        /// </summary>
        /// <param name="message">The <see cref="bet_cancel"/> message to dispatch</param>
        /// <param name="rawMessage">A raw message received from the feed</param>
        private void DispatchBetCancel(bet_cancel message, byte[] rawMessage)
        {
            var eventArgs = new BetCancelEventArgs <T>(MessageMapper, message, DefaultCultures, rawMessage);

            Dispatch(OnBetCancel, eventArgs, message);
        }