コード例 #1
0
ファイル: WorkerRole.cs プロジェクト: lanicon/BeeHive
        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.TraceInformation("BeeHive.Demo.Worker entry point called", "Information");

            while (true)
            {
                Thread.Sleep(10000);
                Trace.TraceInformation("Working", "Information");
                var order = new Order()
                {
                    CustomerId        = Guid.NewGuid().ToString("N"),
                    Id                = Guid.NewGuid().ToString("N"),
                    PaymentMethod     = "Card/Visa/4444333322221111/123",
                    ShippingAddress   = "Jabolsa",
                    TotalPrice        = 223,
                    ProductQuantities = new Dictionary <string, int>()
                    {
                        { Guid.NewGuid().ToString("N"), 1 },
                        { Guid.NewGuid().ToString("N"), 2 },
                        { Guid.NewGuid().ToString("N"), 3 },
                    }
                };

                var customer = new Customer()
                {
                    Address = "2, Korat Jingala",
                    Email   = "*****@*****.**",
                    Id      = order.CustomerId,
                    Name    = "Natsak Birat"
                };

                _customerStore.InsertAsync(customer).Wait();

                _orderStore.InsertAsync(order).Wait();
                var ev = new Event(new OrderAccepted()
                {
                    OrderId = order.Id
                })
                {
                    EventType = "OrderAccepted"
                };
                _queueOperator.PushAsync(ev).Wait();
            }
        }
コード例 #2
0
        /// <summary>
        /// A simplistic implementation. In reality fulfilment can be an external system/domain
        /// Here we publish
        /// </summary>
        /// <param name="evnt"></param>
        /// <returns></returns>
        public async Task <IEnumerable <Event> > ProcessAsync(Event evnt)
        {
            var orderInventoryCheckCompleted = evnt.GetBody <OrderInventoryCheckCompleted>();
            var order = await _orderStore.GetAsync(orderInventoryCheckCompleted.OrderId);

            if (order.IsCancelled)
            {
                return(new Event[0]);
            }
            else
            {
                await Task.Delay(_random.Next(1000, 5000));

                Trace.TraceInformation("Fulfilment actor - fulfiling : " + order.Id);

                var shipment = new Shipment()
                {
                    OrderId = order.Id,
                    Id      = Guid.NewGuid().ToString("N"),
                    Address = order.ShippingAddress,
                    DeliveryExpectedDate = DateTime.Now.AddDays(_random.Next(1, 5))
                };
                await _shipmentStore.InsertAsync(shipment);

                return(new[]
                {
                    new Event(new OrderShipped()
                    {
                        OrderId = order.Id,
                        ShipmentId = shipment.Id
                    })
                    {
                        QueueName = "OrderShipped",
                        EventType = "OrderShipped"
                    }
                });
            }
        }
コード例 #3
0
ファイル: PaymentActor.cs プロジェクト: orf53975/BeeHive-1
        public async Task <IEnumerable <Event> > ProcessAsync(Event evnt)
        {
            var orderAccepted = evnt.GetBody <OrderAccepted>();
            var order         = await _orderRepo.GetAsync(orderAccepted.OrderId);

            Trace.TraceInformation("PaymentActor received OrderAccepted " + order.Id);

            // if order is cancelled no further processing
            if (order.IsCancelled)
            {
                Trace.TraceInformation("Order was cancelled.");
                return(new Event[0]);
            }

            var payment = new Payment()
            {
                Amount        = order.TotalPrice,
                OrderId       = order.Id,
                PaymentMethod = order.PaymentMethod
            };

            try
            {
                var transactionId = await _paymentGateway.Authorise(payment);

                Trace.TraceInformation("Order transaction authorised: " + transactionId);

                payment.TransactionId = transactionId;
                await _paymentRepo.InsertAsync(payment);

                Trace.TraceInformation("Payment success");

                return(new[]
                {
                    new Event(new PaymentAuthorised()
                    {
                        OrderId = order.Id,
                        PaymentId = payment.Id
                    })
                });
            }
            catch (AggregateException aggregateException)
            {
                var paymentFailureException = aggregateException.InnerExceptions.OfType <PaymentFailureException>()
                                              .FirstOrDefault();
                if (paymentFailureException != null)
                {
                    Trace.TraceInformation("Payment failed");

                    Trace.TraceWarning(paymentFailureException.ToString());
                    return(new[]
                    {
                        new Event(new PaymentFailed()
                        {
                            OrderId = order.Id
                        })
                    });
                }
                else
                {
                    throw;
                }
            }
            catch (PaymentFailureException paymentFailureException)
            {
                Trace.TraceInformation("Payment failed");
                Trace.TraceWarning(paymentFailureException.ToString());
                return(new[]
                {
                    new Event(new PaymentFailed()
                    {
                        OrderId = order.Id
                    })
                });
            }
        }