private static async Task RunLoop(IEndpointInstance endpointInstance)
        {
            log.Info("- Press 'P' to place an order");
            log.Info("- Press 'Q' to quit.");

            while (true)
            {
                var key = Console.ReadKey();

                switch (key.Key)
                {
                case ConsoleKey.P:
                    // Instantiate the command
                    var command = new PlaceOrder
                    {
                        CustomerId = rnd.Next(10),
                        OrderId    = Guid.NewGuid().ToString()
                    };

                    // Send the command
                    log.Info(
                        $"Sending PlaceOrder command, CustomerId = {command.CustomerId}, OrderId = {command.OrderId}");
                    await endpointInstance.Send(command);

                    break;

                case ConsoleKey.Q:
                    return;

                default:
                    log.Info("Unknown input. Please try again.");
                    break;
                }
            }
        }
        public async Task <string> Trade(string currency, decimal price, decimal size, bool buy)
        {
            var request = new PlaceOrder
            {
                CancelAfter = "min",
                OrderId     = Guid.NewGuid().ToString("D"),
                Price       = price.ToString("F2", CultureInfo.InvariantCulture),
                ProductId   = $"{currency}-{_fiatCurrency}".ToUpperInvariant(),
                Side        = buy ? "buy" : "sell",
                Size        = size.ToString("F8", CultureInfo.InvariantCulture),
                Stop        = buy ? "loss" : "entry",
                StopPrice   = price.ToString("F2", CultureInfo.InvariantCulture),
                TimeInForce = "GTT",
                Type        = "limit"
            };

            var body = JsonSerializer.Serialize(request);

            var message = new HttpRequestMessage(HttpMethod.Post, "/orders")
            {
                Content = new StringContent(body, Encoding.UTF8, "application/json")
            };

            AddRequestHeaders(message, body);

            var response = await _client.SendAsync(message);

            response.EnsureSuccessStatusCode();

            // TODO: Log response?
            // var stringData = await response.Content.ReadAsStringAsync();

            return(request.OrderId);
        }
Example #3
0
        public void PlaceOrderTest()
        {
            PlaceOrder order = new PlaceOrder(driver);

            order.OrderBook();
            Assert.AreEqual(driver.Url, placeOrder);
        }
Example #4
0
        static async Task SendOrder(IEndpointInstance endpointInstance)
        {
            Console.WriteLine("Digite o nome do produto");

            while (true)
            {
                var nomeProduto = Console.ReadLine();

                var id = Guid.NewGuid();

                var placeOrder = new PlaceOrder
                {
                    Product = nomeProduto,
                    Id      = id
                };

                await endpointInstance.Send("NServiceBus.Server", placeOrder)
                .ConfigureAwait(false);

                Console.WriteLine($"Enviada ordem com id: {id:N}");

                Console.WriteLine("Digite 'S' para sair ou qualquer outra tecla para continuar.");
                var key = Console.ReadKey();

                if (key.Key == ConsoleKey.S)
                {
                    return;
                }

                Console.WriteLine("Digite o nome do produto");
            }
        }
Example #5
0
        static async Task RunLoop(IEndpointInstance instance)
        {
            while (true)
            {
                log.Info("Press 'P' to PlaceOrder or 'Q' to Quit");
                var key = Console.ReadKey();
                Console.WriteLine();
                switch (key.Key)
                {
                case ConsoleKey.P:
                    var command = new PlaceOrder()
                    {
                        OrderId = System.Guid.NewGuid().ToString()
                    };
                    await instance.Send(command).ConfigureAwait(false);

                    break;

                case ConsoleKey.Q:
                    return;

                default:
                    log.Info("Unknow input,Please try again");
                    break;
                }
            }
        }
Example #6
0
        public async Task PlaceCustomerOrder(Customer c)
        {
            // Items are
            ((ICustomerOrder)this).CustomerName = c.FullName;
            ((ICustomerOrder)this).Items        = new[] { "Galaxy S10", "iPhone X  Max", "Huawei Mate 30 Pro" };
            AmazonServices.PlaceOrder order = new PlaceOrder(this);
            await order.ProcessOrder(async orderCallBack =>
            {
                string items = "";
                foreach (var item in orderCallBack.CustomerOrder.Items)
                {
                    items += item + "\n";
                }
                //orderCallBack.CustomerOrder.Items;
                // Create new Email Notification
                INotifier emailNotifier = new EmailNotifier(c.EmailAddress,
                                                            $"Your Order of(NGN {orderCallBack.CustomerOrder.Total:N}) has been Placed Successfully",
                                                            $"Hi {c.FullName}, Thanks for your patronage\n Your Order of NGN {orderCallBack.CustomerOrder.Total:N} was successful\n" +
                                                            $"Order Id :{ orderCallBack.CustomerOrder.OrderId}\n" +
                                                            $"Items Ordered are : \n{items}");
                await emailNotifier.SendNotification();
            });

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("=========== ORDER PLACE, You will Receive Notifications Shortly ================");
            Console.ResetColor();
        }
Example #7
0
        public async Task <IActionResult> PlaceOrder(string orderId, [FromBody] PlaceOrder orderCommand)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var order = await _dbContext.Orders.FirstOrDefaultAsync(o => o.OrderId == orderId);

            if (order == null)
            {
                return(NotFound());
            }

            order.AfterPayment = orderCommand.AfterPayment;

            if (order.AfterPayment)
            {
                order.AddStateChange(OrderState.AWAITINGAFTERPAYMENT);
            }
            else
            {
                order.AddStateChange(OrderState.PAYMENTINPROGRESS);
            }

            await _dbContext.SaveChangesAsync();

            OrderPlaced e = Mapper.Map <OrderPlaced>(order);
            await _messagePublisher.PublishMessageAsync(e.MessageType, e, "");

            return(AcceptedAtRoute("GetByOrderId", new { orderId = order.OrderId }, order));
        }
        public async Task <IActionResult> EditOrderInfo(PlaceOrder placeOrder)
        {
            if (ModelState.IsValid)
            {
                if (CalculateOrder(placeOrder) > getBalanceAmt(placeOrder.CID))
                {
                    var requiredDetails = new List <string> {
                        "Total Order Amount:  Nu." + totalOrder,
                        "Advance Balance: Nu." + Balance,
                        "Required Amount: Nu." + (totalOrder - Balance)
                    };
                    TempData["Required"] = requiredDetails;
                    return(RedirectToAction("ViewPlaceOrder"));
                }
                else
                {
                    //get site details for saving site name
                    var getSiteDetails = await _db.site.FindAsync(placeOrder.SiteID);

                    //update order table
                    placeOrder.PriceAmount     = totalOrder;
                    placeOrder.TransportAmount = (TransportRate * placeOrder.Quantity + Distance);
                    placeOrder.AdvanceBalance  = Balance - totalOrder;
                    placeOrder.SiteName        = getSiteDetails.SiteName;
                    _db.order.Update(placeOrder);
                    await _db.SaveChangesAsync();

                    return(RedirectToAction("OrderDetails"));
                }
            }
            return(View(placeOrder));
        }
        public async Task <IActionResult> ApproveOrder(int OrderID)
        {
            if (ModelState.IsValid)
            {
                //get the order details for approve
                PlaceOrder placeOrder = await _db.order.FindAsync(OrderID);

                //get customer details for updating advance balance
                var getCustomerDetails = await _db.customer.FindAsync(placeOrder.CID);

                //Update the advance balance
                var getDepositAdvanceDetails = await _db.advance.FindAsync(placeOrder.CID);

                getDepositAdvanceDetails.CustomerCID = placeOrder.CID;
                getDepositAdvanceDetails.Amount      = getDepositAdvanceDetails.Amount;
                getDepositAdvanceDetails.Balance     = getDepositAdvanceDetails.Balance - placeOrder.PriceAmount;
                _db.advance.Update(getDepositAdvanceDetails);
                await _db.SaveChangesAsync();

                //save new record to orders table
                placeOrder.AdvanceBalance  = getDepositAdvanceDetails.Balance - placeOrder.PriceAmount;
                placeOrder.OrderStatusID   = (Char)OrderStatus.Delivered;
                placeOrder.OrderStatusName = "Delivered";
                _db.order.Update(placeOrder);
                await _db.SaveChangesAsync();

                //send mail for successful ordered delivered
                string subject = "Your Ordered Is Delivered";
                string body    = "Your Order with order Id:" + placeOrder.OrderID + "is delivered on" + new DateTime() + ".";
                CommonService.SendEmail(getCustomerDetails.EmailAddress, subject, body);
                return(RedirectToAction("OrderDetails"));
                //}
            }
            return(View("OrderDetails"));
        }
        public void PlaceOrderTest()
        {
            PlaceOrder order = new PlaceOrder(driver);

            order.OrderBook();
            Thread.Sleep(6000);
        }
Example #11
0
        static async Task RunLoop(IEndpointInstance endpointInstance)
        {
            while (true)
            {
                log.Info("Press 'P' to place an order, or 'Q' to quit.");
                var key = Console.ReadKey();
                Console.ReadLine();
                switch (key.Key)
                {
                case ConsoleKey.P:
                    var order = new PlaceOrder {
                        OrderId = Guid.NewGuid().ToString()
                    };
                    log.Info($"Sending PlaceOrder command. OrderId= {order.OrderId}");
                    await endpointInstance.Send(order).ConfigureAwait(false);

                    break;

                case ConsoleKey.Q:
                    return;

                default:
                    log.Info("Unknown input. Please try again.");
                    break;
                }
            }
//            Console.WriteLine("Press Enter to exit ...");
//            Console.ReadLine();
//            await endpointInstance.Stop().ConfigureAwait(false);
        }
        public IEnumerable <dynamic> Handle(PlaceOrder c)
        {
            if (!this.open)
            {
                throw new TabNotOpen();
            }

            var drink = c.Items.Where(i => i.IsDrink).ToList();

            if (drink.Any())
            {
                yield return new DrinksOrdered
                       {
                           Id    = c.Id,
                           Items = drink
                       }
            }
            ;

            var food = c.Items.Where(i => !i.IsDrink).ToList();

            if (food.Any())
            {
                yield return new FoodOrdered
                       {
                           Id    = c.Id,
                           Items = food
                       }
            }
            ;
        }
Example #13
0
    static void SendOrder(IBus bus)
    {
        Console.WriteLine("Press enter to send a message");
        Console.WriteLine("Press any key to exit");

        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();
            Console.WriteLine();

            if (key.Key != ConsoleKey.Enter)
            {
                return;
            }
            Guid id = Guid.NewGuid();

            PlaceOrder placeOrder = new PlaceOrder
            {
                Product = "New shoes",
                Id      = id
            };
            bus.Send("Samples.StepByStep.Server", placeOrder);

            Console.WriteLine("Sent a new PlaceOrder message with id: {0}", id.ToString("N"));
        }
    }
        public async Task <ActionResult> PlaceOrder()
        {
            var orderId = Guid.NewGuid().ToString().Substring(0, 8);

            //anonymous type
            var order = new
            {
                OrderId       = orderId,
                OrderDateTime = DateTime.UtcNow,
                OrderTotal    = 200.00
            };

            var serializedOrder = JsonConvert.SerializeObject(order);
            var command         = new PlaceOrder()
            {
                Payload = serializedOrder, ContentType = "application/json", Schema = ""
            };

            // Send the command
            await _endpointInstance.Send(command)
            .ConfigureAwait(false);

            dynamic model = new ExpandoObject();

            model.OrderId      = orderId;
            model.MessagesSent = Interlocked.Increment(ref messagesSent);

            return(View(model));
        }
Example #15
0
        public async Task then_all_activated_tokens_should_be_deactivated()
        {
            // arrange
            var placeOrder = new PlaceOrder(
                aggregateId: Any.Guid,
                billingAccountId: BillingAccountId,
                catalogId: CatalogId,
                quantity: 5,
                activateImmediately: true,
                idempotencyToken: Any.IdempotencyToken,
                correlationId: ScenarioCorrelationId);

            Clock.AdvanceBy(OneDay);

            // act
            await Bus.Send(placeOrder);

            await Bus.Flush();

            // assert
            Orders.Single().Should().BeEquivalentTo(
                new
            {
                Id               = placeOrder.AggregateId,
                Version          = 1,
                CatalogId        = placeOrder.CatalogId,
                BillingAccountId = placeOrder.BillingAccountId,
                Quantity         = placeOrder.Quantity,
                State            = Canceled,
                Tokens           = new List <string>()
            });
            Tokens.Should().OnlyContain(token => token.State == Circulated);
        }
Example #16
0
    static async Task SendOrder(IEndpointInstance endpointInstance)
    {

        Console.WriteLine("Press enter to send a message");
        Console.WriteLine("Press any key to exit");

        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();
            Console.WriteLine();

            if (key.Key != ConsoleKey.Enter)
            {
                break;
            }
            Guid id = Guid.NewGuid();

            PlaceOrder placeOrder = new PlaceOrder
            {
                Product = "New shoes",
                Id = id
            };
            await endpointInstance.Send("Samples.StepByStep.Server", placeOrder);

            Console.WriteLine("Sent a new PlaceOrder message with id: {0}", id.ToString("N"));

        }

    }
Example #17
0
        static async Task SendOrder()
        {
            var tasks = new List <Task>();

            Console.ForegroundColor = ConsoleColor.White;
            while (true)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Press enter number of messages to be sent");
                Console.ForegroundColor = ConsoleColor.White;
                var number = Convert.ToInt32(Console.ReadLine());
                int a      = 0;

                while (a < number)
                {
                    var id         = Guid.NewGuid();
                    var placeOrder = new PlaceOrder
                    {
                        Product = "New shoes",
                        Id      = id
                    };

                    tasks.Add(_endpoint.SendMessage(placeOrder));


                    a++;
                }

                await Task.WhenAll(tasks)
                .ConfigureAwait(false);

                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Sending complete!");
            }
        }
        private static async Task RunLoop(IEndpointInstance endpointInstance)
        {
            while (true)
            {
                log.Info("Press 'P' to place an order, or 'Q' to quit.");
                var key = Console.ReadKey();
                Console.WriteLine();

                switch (key.Key)
                {
                case ConsoleKey.P:
                    // Instantiate the command
                    var command = new PlaceOrder
                    {
                        OrderId = Guid.NewGuid().ToString()
                    };

                    // Send the command to the local endpoint
                    log.Info($"Sending PlaceOrder command, OrderId = {command.OrderId}");
                    await endpointInstance.SendLocal(command).ConfigureAwait(false);

                    break;

                case ConsoleKey.Q:
                    return;

                default:
                    log.Info("Unknown input. Please try again.");
                    break;
                }
            }
        }
        public IHttpActionResult Post(PlaceOrderCommand cmd)
        {
            if (Guid.Empty.Equals(cmd.Id))
            {
                var response = new HttpResponseMessage(HttpStatusCode.Forbidden)
                {
                    Content      = new StringContent("order information must be supplied in the POST body"),
                    ReasonPhrase = "Missing Order Id"
                };
                throw new HttpResponseException(response);
            }

            var command = new PlaceOrder(cmd.Id, cmd.ProductId, cmd.Quanity);

            try
            {
                ServiceLocator.OrderCommands.Handle(command);

                var link = new Uri(string.Format("http://localhost:8182/api/orders/{0}", command.Id));
                return(Created(link, command));
            }
            catch (ArgumentException argEx)
            {
                return(BadRequest(argEx.Message));
            }
        }
Example #20
0
    static async Task SendOrder(IEndpointInstance endpointInstance)
    {
        Console.WriteLine("Press enter to send a message");
        Console.WriteLine("Press any key to exit");

        while (true)
        {
            var key = Console.ReadKey();
            Console.WriteLine();

            if (key.Key != ConsoleKey.Enter)
            {
                return;
            }
            var id = Guid.NewGuid();

            var placeOrder = new PlaceOrder
            {
                Product = "New shoes",
                Id      = id
            };
            await endpointInstance.Send("Samples.StepByStep.Server", placeOrder)
            .ConfigureAwait(false);

            Console.WriteLine($"Sent a PlaceOrder message with id: {id:N}");
        }
    }
        public async Task <IActionResult> AddOrder([FromBody] PlaceOrder newData)
        {
            try
            {
                using (var context = new MovingCompanyContext())
                {
                    Person newPerson  = context.Person.SingleOrDefault(person => person.Mail == newData.Mail);
                    Person tempPerson = newPerson ?? new Person {
                        Mail = newData.Mail, Name = newData.Name, PhoneNumber = newData.PhoneNumber
                    };
                    if (newPerson == null)
                    {
                        context.Person.Add(tempPerson);
                        context.SaveChanges();
                    }

                    Orders newOrder = new Orders {
                        From = newData.From, Date = newData.Date, Note = newData.Note, PersonId = tempPerson.Id, To = newData.To, WorkType = newData.WorkType
                    };
                    context.Orders.Add(newOrder);
                    context.SaveChanges();
                }
            }
            catch (InvalidCastException e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
            return(Ok());
        }
Example #22
0
        public async Task Given_PlaceOrderCommandWithDiscountCode_When_HandleAsync_Then_DiscountedOrderIsCreatedAndAddedToRepository()
        {
            //Arrange
            var discountCodeGenerator = new DiscountCodeGenerator();
            var sampleDiscount        = discountCodeGenerator.GenerateCodeForSubscriber(_identityProviderMock.Object.Next(), Guid.NewGuid());
            var command = new PlaceOrder
            {
                Id           = Guid.NewGuid(),
                Value        = 100,
                DiscountCode = sampleDiscount.GetCode()
            };
            Order placedOrder = null;

            _discountRepositoryMock.Setup(x => x.FindByCode(It.Is <string>(discountCode => discountCode == sampleDiscount.GetCode()), It.IsAny <CancellationToken>()))
            .ReturnsAsync(sampleDiscount);
            _orderRepositoryMock.Setup(x => x.Add(It.IsAny <Order>(), It.IsAny <CancellationToken>()))
            .Callback <Order, CancellationToken>((order, cancellationToken) => { placedOrder = order; });
            //Act
            await _sut.HandleAsync(command, CancellationToken.None);

            //Assert
            Assert.That(placedOrder.Summary.Value, Is.EqualTo(command.Value));
            Assert.That(placedOrder.Summary.DiscountValue, Is.EqualTo(CalculateDiscount(command.Value, sampleDiscount)));
            Assert.That(placedOrder.Summary.TotalValue, Is.EqualTo(command.Value - CalculateDiscount(command.Value, sampleDiscount)));
        }
Example #23
0
        public IActionResult PDetail(int id)
        {
            PlaceOrder po = new PlaceOrder();

            po = db.PlaceOrder.Single <PlaceOrder>(m => m.ObjId == id);
            return(View(po));
        }
Example #24
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press enter to test ordering");
            while (true)
            {
                MyActorSystem = ActorSystem.Create("MyActorSystem");

                //Props orderProcessorProps = Props.Create<OrderProcessorActor>();
                //IActorRef orderProcessorActor = MyActorSystem.ActorOf(orderProcessorProps, "orderProcessorActor");

                IActorRef orderProcessorActor = MyActorSystem.ActorOf(Props.Create(() => new OrderProcessorActor()));

                var key = Console.ReadLine();

                if (key == "order")
                {
                    var goodMessage = new PlaceOrder(12345, 10, 25, 5000);
                    orderProcessorActor.Tell(goodMessage);
                }
                if (key == "badorder")
                {
                    var badMessage = new PlaceOrder(12345, 10, 25, -5000);
                    orderProcessorActor.Tell(badMessage);
                }
                else if (key == "exit")
                {
                    break;
                }
            }
        }
Example #25
0
        public void Should_not_dispatch_messages_already_dispatched()
        {
            Scenario.Define <Context>()
            .WithEndpoint <OutboxEndpoint>(b => b.When(session =>
            {
                var duplicateMessageId = Guid.NewGuid().ToString();
                var p1   = new PlaceOrder();
                var p2   = new PlaceOrder();
                var dest = Address.Parse("ADuplicateMessageArrives.OutboxEndpoint");

                session.SetMessageHeader(p1, Headers.MessageId, duplicateMessageId);
                session.SetMessageHeader(p2, Headers.MessageId, duplicateMessageId);
                session.Send(dest, p1);
                session.Send(dest, p2);
                session.SendLocal(new PlaceOrder
                {
                    Terminator = true
                });
            }))
            .WithEndpoint <DownstreamEndpoint>()
            .Done(c => c.Done)
            .Repeat(r => r.For <AllOutboxCapableStorages>())
            .Should(context => Assert.AreEqual(2, context.MessagesReceivedByDownstreamEndpoint))
            .Run(TimeSpan.FromMinutes(1));
        }
Example #26
0
    static void SendOrder(IBus bus)
    {

        Console.WriteLine("Press enter to send a message");
        Console.WriteLine("Press any key to exit");

        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();
            Console.WriteLine();

            if (key.Key != ConsoleKey.Enter)
            {
                return;
            }
            Guid id = Guid.NewGuid();

            PlaceOrder placeOrder = new PlaceOrder
            {
                Product = "New shoes",
                Id = id
            };
            bus.Send("Samples.StepByStep.Server", placeOrder);

            Console.WriteLine("Sent a new PlaceOrder message with id: {0}", id.ToString("N"));

        }

    }
Example #27
0
        public Usage()
        {
            PlaceOrder placeOrder = new PlaceOrder();
            IBus bus = null;
            // ReSharper disable once NotAccessedVariable
            PlaceOrderResponse message; // get replied message

            #region CallbackToAccessMessageRegistration

            IAsyncResult sync = bus.Send(placeOrder)
                .Register(ar =>
                {
                    CompletionResult localResult = (CompletionResult) ar.AsyncState;
                    message = (PlaceOrderResponse) localResult.Messages[0];
                }, null);

            sync.AsyncWaitHandle.WaitOne();
            // return message;

            #endregion

            #region TriggerCallback

            bus.Return(Status.OK);

            #endregion

        }
Example #28
0
        public Usage()
        {
            PlaceOrder placeOrder = new PlaceOrder();
            IBus       bus        = null;
            // ReSharper disable once NotAccessedVariable
            PlaceOrderResponse message; // get replied message

            #region CallbackToAccessMessageRegistration

            IAsyncResult sync = bus.Send(placeOrder)
                                .Register(ar =>
            {
                CompletionResult localResult = (CompletionResult)ar.AsyncState;
                message = (PlaceOrderResponse)localResult.Messages[0];
            }, null);

            sync.AsyncWaitHandle.WaitOne();
            // return message;

            #endregion
            #region TriggerCallback

            bus.Return(Status.OK);

            #endregion
        }
Example #29
0
        public async Task <Order> CreateOrder(PlaceOrder order)
        {
            var placedOrder = await _ordersService.CreateOrder(order);

            await _notificationService.SendNotification(order.Email, placedOrder);

            return(placedOrder);
        }
Example #30
0
        public async Task Handle(PlaceOrder message, IMessageHandlerContext context)
        {
            log.Info($"Received PlaceOrder, OrderId = {message.OrderId}");
            Data.OrderId = message.OrderId;

            log.Info($"Starting cool down period for order #{Data.OrderId}.");
            await RequestTimeout(context, TimeSpan.FromSeconds(5), new BuyersRemorseIsOver()); // context, time to delay, actual message that will be sent whe the timeout is over
        }
Example #31
0
        public void Handle(PlaceOrder message)
        {
            Data.OrderId = message.OrderId;
            RequestTimeout <OrderReadyToBePlaced>(TimeSpan.FromSeconds(30));

            LogManager.GetLogger(typeof(OrderPlacementSaga))
            .Info("Place Order request received " + Data.OrderId);
        }
Example #32
0
        public async Task Handle(PlaceOrder message, IMessageHandlerContext context)
        {
            log.Info($"Received PlaceOrder, OrderId = {message.OrderId}");
            Data.OrderId = message.OrderId;

            log.Info($"Starting cool down period for order #{Data.OrderId}.");
            await RequestTimeout(context, TimeSpan.FromSeconds(20), new BuyersRemorseIsOver());
        }
        private async void PlaceOrder_Tapped(object sender, EventArgs e)
        {
            await PlaceOrder.ScaleTo(0.85);

            await PlaceOrder.ScaleTo(1);

            Navigation.PushAsync(new Home.HomePage());
        }
 public void Start()
 {
     Console.WriteLine("Press 'Enter' to send a message. To exit, Ctrl + C");
     var counter = 0;
     while (Console.ReadLine() != null)
     {
         counter++;
         var placeOrder = new PlaceOrder { OrderId = "order" + counter};
         Bus.Send(placeOrder).Register(PlaceOrderReturnCodeHandler, this);
         Console.WriteLine(string.Format("Sent PlacedOrder command with order id [{0}].", placeOrder.OrderId));
     }
 }
Example #35
0
    static void SendMessage(IBus bus)
    {
        #region sender

        PlaceOrder placeOrder = new PlaceOrder
        {
            OrderId = Guid.NewGuid()
        };
        bus.Send(placeOrder);
        Console.WriteLine("Sent PlacedOrder command with order id [{0}].", placeOrder.OrderId);

        #endregion
    }
    static void SendMessage(IBus bus)
    {
        #region sender

        var placeOrder = new PlaceOrder
        {
            OrderId = Guid.NewGuid()
        };
        bus.Send("Samples.Scaleout.Server", placeOrder);
        Console.WriteLine($"Sent PlacedOrder command with order id [{placeOrder.OrderId}].");

        #endregion
    }
Example #37
0
    static async Task SendOrder(IEndpointInstance endpointInstance)
    {

        Console.WriteLine("Press '1' to send PlaceOrder - defer message handling");
        Console.WriteLine("Press '2' to send PlaceDelayedOrder - defer message delivery");
        Console.WriteLine("Press enter key to exit");

        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();
            Console.WriteLine();
            Guid id = Guid.NewGuid();

            switch (key.Key)
            {
                case ConsoleKey.D1:
                    #region SendOrder
                    PlaceOrder placeOrder = new PlaceOrder
                    {
                        Product = "New shoes",
                        Id = id
                    };
                    await endpointInstance.Send("Samples.DelayedDelivery.Server", placeOrder);
                    Console.WriteLine("[Defer Message Handling] Sent a new PlaceOrder message with id: {0}", id.ToString("N"));
                    #endregion
                    continue;
                case ConsoleKey.D2:
                    #region DeferOrder
                    PlaceDelayedOrder placeDelayedOrder = new PlaceDelayedOrder
                    {
                        Product = "New shoes",
                        Id = id
                    };
                    SendOptions options = new SendOptions();

                    options.SetDestination("Samples.DelayedDelivery.Server");
                    options.DelayDeliveryWith(TimeSpan.FromSeconds(5));
                    await endpointInstance.Send(placeDelayedOrder, options);
                    Console.WriteLine("[Defer Message Delivery] Deferred a new PlaceDelayedOrder message with id: {0}", id.ToString("N"));
                    #endregion
                    continue;
                case ConsoleKey.Enter:
                    return;
                default:
                    return;
            }
        }

    }
Example #38
0
    static void SendMessage(IBus bus)
    {
        PlaceOrder placeOrder = new PlaceOrder
        {
            OrderId = Guid.NewGuid()
        };

        #region SenderRouting

        bus.Send("Samples.Scaleout.Distributor", placeOrder);

        #endregion

        Console.WriteLine("Sent PlacedOrder command with order id [{0}].", placeOrder.OrderId);
    }
Example #39
0
    static void SendOrder(IBus bus)
    {

        Console.WriteLine("Press '1' to send PlaceOrder - defer message handling");
        Console.WriteLine("Press '2' to send PlaceDelayedOrder - defer message delivery");
        Console.WriteLine("Press enter key to exit");

        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();
            Console.WriteLine();
            Guid id = Guid.NewGuid();

            switch (key.Key)
            {
                case ConsoleKey.D1:
                    #region SendOrder
                    PlaceOrder placeOrder = new PlaceOrder
                    {
                        Product = "New shoes",
                        Id = id
                    };
                    bus.Send("Samples.DelayedDelivery.Server", placeOrder);
                    Console.WriteLine("[Defer Message Handling] Sent a new PlaceOrder message with id: {0}", id.ToString("N"));
                    #endregion
                    continue;
                case ConsoleKey.D2:
                    #region DeferOrder
                    PlaceDelayedOrder placeDelayedOrder = new PlaceDelayedOrder
                    {
                        Product = "New shoes",
                        Id = id
                    };
                    bus.Defer(TimeSpan.FromSeconds(5), placeDelayedOrder);
                    Console.WriteLine("[Defer Message Delivery] Deferred a new PlaceDelayedOrder message with id: {0}", id.ToString("N"));
                    #endregion
                    continue;
                case ConsoleKey.Enter:
                    return;
                default:
                    return;
            }
        }

    }
Example #40
0
    static void SendOrder(IBus bus)
    {
        Console.WriteLine("Press 'Enter' to send a message. To exit press 'Ctrl + C'");

        while (Console.ReadLine() != null)
        {
            Guid id = Guid.NewGuid();

            PlaceOrder placeOrder = new PlaceOrder
            {
                Product = "New shoes",
                Id = id
            };
            bus.Send("StepByStep.Ordering.Server", placeOrder);

            Console.WriteLine("Sent a new PlaceOrder message with id: {0}", id.ToString("N"));
        }
    }
Example #41
0
 public static PlaceOrder ToPlaceOrderCommand(this OrderViewModel model, ConferenceAlias conferenceAlias, IConferenceQueryService conferenceQueryService)
 {
     var seatTypes = conferenceQueryService.GetPublishedSeatTypes(conferenceAlias.Id);
     var command = new PlaceOrder();
     command.AggregateRootId = GuidUtil.NewSequentialId();
     command.ConferenceId = conferenceAlias.Id;
     command.Seats = model.Seats.Where(x => x.Quantity > 0).Select(x =>
     {
         var seat = seatTypes.Single(y => y.Id == x.SeatType);
         return new SeatInfo
         {
             SeatType = x.SeatType,
             Quantity = x.Quantity,
             SeatName = seat.Name,
             UnitPrice = seat.Price
         };
     }).ToList();
     return command;
 }
        public void Should_provide_orchestration()
        {
            var order = new OrderSlip {
                CustomerId = 432,
                LineItems = new Dictionary<int, int> {
                    { 123, 1 },
                    { 654, 2 }
                }
            };

            //TODO: map orderslip to placeorder
            var orderPlacer = new PlaceOrder();

            var receipt = Interactions.Run<OrderSlip>(orderPlacer, order) as OrderReceipt;

            Assert.That(receipt.OrderNumber, Is.GreaterThan(0));
            Assert.That(receipt.Total, Is.EqualTo(1243.40m));
            Assert.That(receipt.NumberOfItems, Is.EqualTo(2));
        }
 public ActionResult Index(OrderDetails orderDetails)
 {
     var placeOrderCommand = new PlaceOrder(new List<string>{orderDetails.Item1, orderDetails.Item2}, orderDetails.Price, orderDetails.CustomerName);
     _publisher.Publish(placeOrderCommand);
     return View("Placed", placeOrderCommand);
 }