Ejemplo n.º 1
0
 public LiangcaiReceivingMiddleware(RequestDelegate next, ILogger <LiangcaiReceivingMiddleware> logger, ILotteryNoticingMessagePublisher lotteryNoticingMessagePublisher, IOrderingApplicationService orderingApplicationService, ILotteryMerchanterApplicationService lotteryMerchanterApplicationService)
 {
     _next   = next;
     _logger = logger;
     _lotteryNoticingMessagePublisher     = lotteryNoticingMessagePublisher;
     _orderingApplicationService          = orderingApplicationService;
     _lotteryMerchanterApplicationService = lotteryMerchanterApplicationService;
 }
Ejemplo n.º 2
0
 public SuicaiNoticing(RequestDelegate next, ILogger <SuicaiNoticing> logger, ILotteryNoticingMessagePublisher lotteryNoticingMessagePublisher, IOrderingApplicationService orderingApplicationService, ILotteryMerchanterApplicationService lotteryMerchanterApplicationService)
 {
     _next   = next;
     _logger = logger;
     _lotteryNoticingMessagePublisher     = lotteryNoticingMessagePublisher;
     _orderingApplicationService          = orderingApplicationService;
     _lotteryMerchanterApplicationService = lotteryMerchanterApplicationService;
     _crypter = Tripledescrypt.Create(CipherMode.CBC, PaddingMode.PKCS7);
 }
 protected override Task ExecuteAsync(CancellationToken stoppingToken)
 {
     return(_busClient.SubscribeAsync <NoticeMessage <LotteryTicketed> >(async(message) =>
     {
         try
         {
             if (message.Content.TicketingType == LotteryTicketingTypes.Success)
             {
                 IUnitOfWorkManager unitOfWorkManager = _iocResolver.GetRequiredService <IUnitOfWorkManager>();
                 using (var uow = unitOfWorkManager.Begin())
                 {
                     IOrderingApplicationService orderingApplicationService = _iocResolver.GetRequiredService <IOrderingApplicationService>();
                     var order = await orderingApplicationService.FindOrderAsync(message.LdpOrderId);
                     if (order == null)
                     {
                         return new Ack();
                     }
                     ILotteryMerchanterApplicationService lotteryMerchanterApplicationService = _iocResolver.GetRequiredService <ILotteryMerchanterApplicationService>();
                     await lotteryMerchanterApplicationService.Ticketing(message.LdpMerchanerId, order.Id, order.LotteryId, order.InvestAmount);
                     await lotteryMerchanterApplicationService.Ticketing(order.LvpVenderId, order.Id, order.LotteryId, order.InvestAmount);
                     uow.Complete();
                 }
             }
             _logger.LogInformation("Received ticketing message: {1} {0}", message.LdpMerchanerId, message.LdpOrderId);
             return new Ack();
         }
         catch (Exception ex)
         {
             _logger.LogError(ex, "Received ticketing message: {1} {0}", message.LdpMerchanerId, message.LdpOrderId);
         }
         return new Nack();
     }, context =>
     {
         context.UseSubscribeConfiguration(configuration =>
         {
             configuration.OnDeclaredExchange(exchange =>
             {
                 exchange.WithName("Baibaocp.LotteryNoticing")
                 .WithDurability(true)
                 .WithAutoDelete(false)
                 .WithType(ExchangeType.Topic);
             });
             configuration.FromDeclaredQueue(queue =>
             {
                 queue.WithName("LotteryTrading.TradeLogging.Tickets")
                 .WithAutoDelete(false)
                 .WithDurability(true);
             });
             configuration.Consume(consume =>
             {
                 consume.WithRoutingKey("LotteryOrdering.Ticketed.#");
             });
         });
     }, stoppingToken));
 }
        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            return(_busClient.SubscribeAsync <NoticeMessage <LotteryAwarded> >(async(message) =>
            {
                try
                {
                    _logger.LogInformation("Received awarding message: {0} {1}", message.LdpOrderId, message.LdpMerchanerId);
                    IOrderingApplicationService orderingApplicationService = _iocResolver.GetRequiredService <IOrderingApplicationService>();
                    IUnitOfWorkManager unitOfWorkManager = _iocResolver.GetRequiredService <IUnitOfWorkManager>();
                    using (var uow = unitOfWorkManager.Begin())
                    {
                        if (message.Content.AwardingType == LotteryAwardingTypes.Winning)
                        {
                            await orderingApplicationService.WinningAsync(message.LdpOrderId, message.Content.BonusAmount, message.Content.AftertaxBonusAmount);
                        }
                        else
                        {
                            await orderingApplicationService.LoseingAsync(message.LdpOrderId);
                        }
                        uow.Complete();
                        return new Ack();
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogInformation(ex, "Received awarding message: {0} {1}", message.LdpOrderId, message.LdpMerchanerId);
                }

                return new Nack();
            }, context =>
            {
                context.UseSubscribeConfiguration(configuration =>
                {
                    configuration.OnDeclaredExchange(exchange =>
                    {
                        exchange.WithName("Baibaocp.LotteryNoticing")
                        .WithDurability(true)
                        .WithAutoDelete(false)
                        .WithType(ExchangeType.Topic);
                    });
                    configuration.FromDeclaredQueue(queue =>
                    {
                        queue.WithName("LotteryOrdering.Awards")
                        .WithAutoDelete(false)
                        .WithDurability(true);
                    });
                    configuration.Consume(consume =>
                    {
                        consume.WithRoutingKey("LotteryOrdering.Awarded.#");
                    });
                });
            }, stoppingToken));
        }
Ejemplo n.º 5
0
        public async Task <ILotteryCalculator> GetLotteryCalculatorAsync(string orderId)
        {
            IOrderingApplicationService orderingApplicationService = _iocResolver.GetRequiredService <IOrderingApplicationService>();
            var lotteryMerchanteOrder = await orderingApplicationService.FindOrderAsync(orderId);

            ObjectFactory objectFactory = _objectFactories.GetOrAdd(lotteryMerchanteOrder.LotteryId, (lotteryId) =>
            {
                if (_lotteryCalculatorImplementationTypes.TryGetValue(lotteryId, out Type implementationType))
                {
                    ObjectFactory factory = ActivatorUtilities.CreateFactory(implementationType, new Type[] { typeof(LotteryMerchanteOrder) });
                    return(factory);
                }
                throw new KeyNotFoundException($"Lottery {nameof(lotteryId)} not implementation ILotteryCalculator");
            });

            ILotteryCalculator lotteryCalculator = objectFactory.Invoke(_iocResolver, new[] { lotteryMerchanteOrder }) as ILotteryCalculator;

            return(lotteryCalculator);
        }
Ejemplo n.º 6
0
 protected override Task ExecuteAsync(CancellationToken stoppingToken)
 {
     return(_busClient.SubscribeAsync <NoticeMessage <LotteryTicketed> >(async(message) =>
     {
         try
         {
             _logger.LogInformation("Received ticketing message: {0} {1} Content:{2}", message.LdpMerchanerId, message.LdpOrderId, message.Content);
             IOrderingApplicationService orderingApplicationService = _iocResolver.GetRequiredService <IOrderingApplicationService>();
             IUnitOfWorkManager unitOfWorkManager = _iocResolver.GetRequiredService <IUnitOfWorkManager>();
             using (var uow = unitOfWorkManager.Begin())
             {
                 if (message.Content.TicketingType == LotteryTicketingTypes.Success)
                 {
                     var order = await orderingApplicationService.TicketedAsync(message.LdpOrderId, message.LdpMerchanerId, message.Content.TicketedNumber, message.Content.TicketedTime, message.Content.TicketedOdds);
                     if (order != null)
                     {
                         await _schedulerManager.EnqueueAsync <ILotteryAwardingScheduler, AwardingScheduleArgs>(new AwardingScheduleArgs
                         {
                             LdpOrderId = message.LdpOrderId,
                             LdpMerchanerId = message.LdpMerchanerId,
                             LvpOrderId = message.Content.LvpOrderId,
                             LvpMerchanerId = message.Content.LvpMerchanerId
                         }, delay: order.ExpectedBonusTime - DateTime.Now);
                     }
                 }
                 else
                 {
                     await orderingApplicationService.RejectedAsync(message.LdpOrderId);
                 }
                 uow.Complete();
                 return new Ack();
             }
         }
         catch (Exception ex)
         {
             _logger.LogInformation(ex, "Received ticketing message: {0} {1} Content:{2}", message.LdpMerchanerId, message.LdpOrderId, message.Content);
         }
         return new Nack();
     }, context =>
     {
         context.UseSubscribeConfiguration(configuration =>
         {
             configuration.OnDeclaredExchange(exchange =>
             {
                 exchange.WithName("Baibaocp.LotteryNoticing")
                 .WithDurability(true)
                 .WithAutoDelete(false)
                 .WithType(ExchangeType.Topic);
             });
             configuration.FromDeclaredQueue(queue =>
             {
                 queue.WithName("LotteryOrdering.Tickets")
                 .WithAutoDelete(false)
                 .WithDurability(true);
             });
             configuration.Consume(consume =>
             {
                 consume.WithRoutingKey("LotteryOrdering.Ticketed.#");
             });
         });
     }, stoppingToken));
 }
        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            return(_busClient.SubscribeAsync <LvpOrderMessage>(async(message) =>
            {
                try
                {
                    ILotteryMerchanterApplicationService lotteryMerchanterApplicationService = _iocResolver.GetRequiredService <ILotteryMerchanterApplicationService>();

                    IUnitOfWorkManager unitOfWorkManager = _iocResolver.GetRequiredService <IUnitOfWorkManager>();
                    using (var uow = unitOfWorkManager.Begin())
                    {
                        /* 此处必须保证投注渠道已经开通相应的彩种和出票渠道*/
                        string ldpVenderId = await lotteryMerchanterApplicationService.FindLdpMerchanterIdAsync(message.LvpVenderId, message.LotteryId);
                        if (string.IsNullOrEmpty(ldpVenderId))
                        {
                            _logger.LogError("当前投注渠道{0}不支持该彩种{1}", message.LvpVenderId, message.LotteryId);
                            return new Nack();
                        }
                        IOrderingApplicationService orderingApplicationService = _iocResolver.GetRequiredService <IOrderingApplicationService>();
                        (LotteryMerchanteOrder order, TimeSpan? delay) = await orderingApplicationService.CreateAsync(message.LvpOrderId, message.LvpUserId, message.LvpVenderId, message.LotteryId, message.LotteryPlayId, message.IssueNumber, message.InvestCode, message.InvestType, message.InvestCount, message.InvestTimes, message.InvestAmount);

                        /* 需要延期投注的票加入计划任务,否则直接分票投注*/
                        if (delay.HasValue)
                        {
                            ISchedulerManager schedulerManager = _iocResolver.GetRequiredService <ISchedulerManager>();
                            await schedulerManager.EnqueueAsync <ILotteryOrderingScheduler, OrderingScheduleArgs>(new OrderingScheduleArgs
                            {
                                LdpOrderId = order.Id,
                                LdpMerchanerId = ldpVenderId,
                                Message = message
                            }, SchedulerPriority.High, delay);
                        }
                        else
                        {
                            await _dispatchOrderingMessageService.PublishAsync(order.Id, ldpVenderId, message);
                        }
                        uow.Complete();
                        return new Ack();
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Error of the ordering :{0}", message.LvpOrderId);
                }
                return new Nack();
            }, context =>
            {
                context.UseSubscribeConfiguration(configuration =>
                {
                    configuration.OnDeclaredExchange(exchange =>
                    {
                        exchange.WithName("Baibaocp.LotteryOrdering")
                        .WithDurability(true)
                        .WithAutoDelete(false)
                        .WithType(ExchangeType.Topic);
                    });
                    configuration.FromDeclaredQueue(queue =>
                    {
                        queue.WithName("LotteryOrdering.Orders")
                        .WithAutoDelete(false)
                        .WithDurability(true);
                    });
                    configuration.Consume(consume =>
                    {
                        consume.WithRoutingKey("LotteryOrdering.Accepted.#");
#if DEBUG
                        consume.WithPrefetchCount(1);
#endif
                    });
                });
            }, stoppingToken));
        }
Ejemplo n.º 8
0
 public AwardingExecuteDispatcher(DispatcherConfiguration options, ILogger <AwardingExecuteDispatcher> logger, IOrderingApplicationService orderingApplicationService) : base(options, "1002", logger)
 {
     _logger = logger;
     _orderingApplicationService = orderingApplicationService;
 }