private static void HandleWarehouseReply(OrderReplyMessage replyMessage) { if (replyMessage.ItemsInStock > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(string.Format("Answer from warehouse: \n" + "Warehouse id: {0} " + "Items in stock: {1} " + "Days for delivery: {2} " + "Shipping charge: {3}", replyMessage.WarehouseId, replyMessage.ItemsInStock, replyMessage.DaysForDelivery, replyMessage.ShippingCharge)); if (outstandingOrders.Contains(replyMessage.CustomerId)) { bus.Publish <OrderReplyMessage>(replyMessage, replyMessage.CustomerId + ""); outstandingOrders.Remove(replyMessage.CustomerId); } } else if (replyMessage.DaysForDelivery == 2) { if (replyMessage.ItemsInStock == 0) { Console.WriteLine("No product in stock in local warehouse - Publishing to all warehouses"); OrderBroadcastRequestMessage e = new OrderBroadcastRequestMessage(); e.CustomerId = replyMessage.CustomerId; e.OrderId = replyMessage.OrderId; e.ProductId = replyMessage.ProductId; bus.Publish <OrderBroadcastRequestMessage>(e); } } }
private void HandleOrderEvent(RetailerOrderRequestMessage message) { SynchronizedWriteLine("Order request received: (" + "Product Id: " + message.ProductId + " Country: " + message.CountryCode + ")" ); int daysForDelivery = country == message.CountryCode ? 2 : 10; decimal shippingCharge = country == message.CountryCode ? 5 : 10; Product requestedProduct = products.FirstOrDefault(p => p.ProductId == message.ProductId); int itemsInStock = requestedProduct != null ? requestedProduct.ItemsInStock : 0; SynchronizedWriteLine("In stock: " + itemsInStock); OrderReplyMessage replyMessage = new OrderReplyMessage { WarehouseId = this.id, ProductId = message.ProductId, CustomerId = message.CustomerId, ItemsInStock = itemsInStock, DaysForDelivery = daysForDelivery, ShippingCharge = shippingCharge }; bus.Send <OrderReplyMessage>("ReplyQueueWarehouse", replyMessage); SynchronizedWriteLine("Reply sent back to retailer"); }
//public void SendRequest() //{ // CustomerOrderRequestMessage request = new CustomerOrderRequestMessage // { // CustomerId = customerID, // ProductId = productID, // Country = country // }; //} public void Start() { SynchronizedWriteLine("Customer running. Waiting for a reply.\n"); CustomerOrderRequestMessages request = new CustomerOrderRequestMessages { CustomerId = customerID, ProductId = productID, Country = country }; MessagingGatway gateway = new MessagingGatway(customerID); try { OrderReplyMessage message = gateway.PlaceOrder(request); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Order reply received by customer:" + customerID); Console.WriteLine("Warehouse Id: " + message.WarehouseId); Console.WriteLine("Order Id: " + message.OrderId); Console.WriteLine("Items in stock: " + message.ItemsInStock); Console.WriteLine("Shipping charge: " + message.ShippingCharge); Console.WriteLine("Days for delivery: " + message.DaysForDelivery); Console.ResetColor(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
void HandleOrderRequestMessage(OrderRequestMessage message) { lock (this) { Console.WriteLine("Warehouse " + id + ": Order request received for order " + message.OrderId + "."); } int daysForDelivery = country == message.Country ? 2 : 10; decimal shippingCharge = country == message.Country ? 5 : 10; Product requestedProduct = products.FirstOrDefault(p => p.ProductId == message.ProductId); if (requestedProduct != null) { OrderReplyMessage replyMessage = new OrderReplyMessage { WarehouseId = id, OrderId = message.OrderId, ItemsInStock = requestedProduct.ItemsInStock, DaysForDelivery = daysForDelivery, ShippingCharge = shippingCharge }; // Send the reply message to the Retailer. bus.SendReceive.Send("warehouseToRetailerQueue", replyMessage); lock (this) { Console.WriteLine("Warehouse " + id + ": Reply for order " + message.OrderId + " sent back to retailer."); } } }
public NewReply GetRelevantData(OrderReplyMessage message) { return(new NewReply() { DaysForDelivery = message.DaysForDelivery, ItemsInStock = message.ItemsInStock, ShippingCharge = message.ShippingCharge }); }
private void HandleOrderEvent(RetailerOrderRequestMessage message) { SynchronizedWriteLine("Order request received:\n" + "Order Id: " + message.OrderId + "\n" + "Product Id: " + message.ProductId + "\n" + "Country: " + message.Country ); int daysForDelivery = country == message.Country ? 2 : 10; decimal shippingCharge = country == message.Country ? 5 : 10; Product requestedProduct = products.FirstOrDefault(p => p.ProductId == message.ProductId); int itemsInStock = requestedProduct != null ? requestedProduct.ItemsInStock : 0; OrderReplyMessage replyMessage = new OrderReplyMessage { WarehouseId = this.id, OrderId = message.OrderId, ProductId = message.ProductId, CustomerId = message.CustomerId, ItemsInStock = itemsInStock, DaysForDelivery = daysForDelivery, ShippingCharge = shippingCharge }; // Send the reply message to the Retailer bus.Send(message.ReplyTo, replyMessage); SynchronizedWriteLine("Reply sent back to retailer"); }
static void HandleOrderReply(OrderReplyMessage message) { lock (lockObject) { // Add the order reply message the list of all replies. allReplies.Add(message); } }
public static void PrintData(OrderReplyMessage mes) { var temp = new ContentFilter().GetRelevantData(mes); Console.WriteLine("Items in stock:" + temp.ItemsInStock); Console.WriteLine($"Days to deliver:" + temp.DaysForDelivery); Console.WriteLine($"Shipping cost:" + temp.ShippingCharge); Console.WriteLine(); }
private void HandleOrderEvent(OrderReplyMessage message) { replyMessage = message; lock (this) { // Wake up the blocked Customer thread Monitor.Pulse(this); } }
private void HandleOrderEvent(OrderReplyMessage message) { _replyMessages = new CustomerReply() { Message = "reply received", ReplyMessage = message }; lock (this) { Monitor.Pulse(this); } }
//move to customer private void HandleRetailerResponse(OrderReplyMessage replyMessage) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(string.Format("Answer from retailer: \n" + " Warehouse with id: {0} has {1} items in stock with the shipping charge of {2}" , replyMessage.WarehouseId, replyMessage.ItemsInStock, replyMessage.ShippingCharge )); reply = replyMessage; lock (this) { // Wake up the blocked thread which sent the order request message // so that it can return the reply message to the application. Monitor.Pulse(this); } }
private void HandleOrderEvent(OrderReplyMessage message) { StringBuilder reply = new StringBuilder(); reply.Append("Order reply received by customer:" + customerID + "\n"); reply.Append("Warehouse Id: " + message.WarehouseId + "\n"); reply.Append("Order Id: " + message.OrderId + "\n"); reply.Append("Items in stock: " + message.ItemsInStock + "\n"); reply.Append("Shipping charge: " + message.ShippingCharge + "\n"); reply.Append("Days for delivery: " + message.DaysForDelivery + "\n"); lock (this) { Console.WriteLine(reply.ToString()); } }
static void Timeout_Elapsed(object message) { OrderRequestMessage m = message as OrderRequestMessage; lock (lockObject) { Console.WriteLine("Processing replies for request from customer " + m.CustomerId + "."); // Get all replies from warehouses for this specific order. var repliesForThisOrder = allReplies.FindAll(r => r.OrderId == m.OrderId); if (repliesForThisOrder.Count > 0) { // Get a reply from a local warehouse (DaysForDelivery == 2) if possible. var reply = repliesForThisOrder.FirstOrDefault(r => r.DaysForDelivery == 2); if (reply == null) { // Otherwise, accept the first reply from one of the other warehouses. reply = repliesForThisOrder.First(); } // Remove the replies for this specific order from the "allReplies" list, // because they have already been processed. allReplies.RemoveAll(r => r.OrderId == m.OrderId); // Uses Topic Based Routing to send the reply to a customer. // The topic ís the CustomerId for the outstanding request. bus.PubSub.Publish <OrderReplyMessage>(reply, m.CustomerId.ToString()); Console.WriteLine("Order: " + reply.OrderId); Console.WriteLine("Warehouse: " + reply.WarehouseId); Console.WriteLine("Items: " + reply.ItemsInStock); Console.WriteLine("Shipping charge: " + reply.ShippingCharge); Console.WriteLine("Days for delivery: " + reply.DaysForDelivery); } else // if there was no reply from any warehouse { Console.WriteLine("No items in stock for this product."); OrderReplyMessage replyNoItems = new OrderReplyMessage(); replyNoItems.OrderId = m.OrderId; bus.PubSub.Publish <OrderReplyMessage>(replyNoItems, m.CustomerId.ToString()); } } }
public void Start() { SynchronizedWriteLine("Customer running. Waiting for a reply.\n"); OrderReplyMessage message = this.gateway.SendRequest(this.gateway.CreateRequestMessage(this.customerID, this.productID, this.country)); StringBuilder reply = new StringBuilder(); reply.Append("Order reply received by customer:" + customerID + "\n"); reply.Append("Warehouse Id: " + message.WarehouseId + "\n"); reply.Append("Order Id: " + message.OrderId + "\n"); reply.Append("Items in stock: " + message.ItemsInStock + "\n"); reply.Append("Shipping charge: " + message.ShippingCharge + "\n"); reply.Append("Days for delivery: " + message.DaysForDelivery + "\n"); SynchronizedWriteLine(reply.ToString()); }
private void HandleOrderEvent(OrderReplyMessage message) { StringBuilder reply = new StringBuilder(); reply.Append("Order reply received by customer:" + customerID + "\n"); reply.Append("Warehouse Id: " + message.WarehouseId + "\n"); reply.Append("Order Id: " + message.OrderId + "\n"); reply.Append("Items in stock: " + message.ItemsInStock + "\n"); reply.Append("Shipping charge: " + message.ShippingCharge + "\n"); reply.Append("Days for delivery: " + message.DaysForDelivery + "\n"); replyMessage = reply.ToString(); lock (this) { // Wake up the blocked Customer thread Monitor.Pulse(this); } }
private void HandleOrderEvent(OrderReplyMessage message) { reply = new OrderReplyMessage { //CustomerId = message.CustomerId, WarehouseId = message.WarehouseId, OrderId = message.OrderId, ItemsInStock = message.ItemsInStock, ShippingCharge = message.ShippingCharge, DaysForDelivery = message.DaysForDelivery }; lock (this) { // Wake up the blocked thread which sent the order request message // so that it can return the reply message to the application. Monitor.Pulse(this); } }
private void HandleOrderReplyMessage(OrderReplyMessage message) { Console.WriteLine("Reply received"); if (message.ItemsInStock > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Reply received from warehouse" + message.WarehouseId); Console.WriteLine("Order Id: " + message.OrderId); Console.WriteLine("Items in stock: " + message.ItemsInStock); Console.WriteLine("Days for delivery: " + message.DaysForDelivery); Console.WriteLine("Shipping charge: " + message.ShippingCharge); Console.ResetColor(); // Uses Topic Based Routing to send the reply to a customer. // The topic ís the customerId from the reply message. bus.Publish <OrderReplyMessage>(message, message.CustomerId.ToString()); } else if (message.DaysForDelivery == 2) { // Publish the message again to all warehouses, if the reply // was from a local warehouse (DaysForDelivery = 2) with no // items in stock. Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Publishing to all warehouses"); Console.ResetColor(); OrderBroadcastRequestMessage broadcastRequestMessage = new OrderBroadcastRequestMessage { OrderId = message.OrderId, ProductId = message.ProductId, CustomerId = message.CustomerId, ReplyTo = replyQueueName, Country = "" }; bus.Publish <EnvelopeRequestMessage>(wrapper.WrapMessage(broadcastRequestMessage)); } }
void HandleAction(OrderReplyMessage obj) { }