队列名
|
可见性超时
|
描述
|
POQueue
|
30 秒
|
从分销商发送给制造商的购买订单消息
|
OSQueue
|
30 秒
|
从制造商发送给分销商的订单汇总消息
|
类
|
描述
|
CompanyAddressEntity
|
包含一个客户或业务地址
|
CustomerEntity
|
包含一个客户
|
OrderEntity
|
包含一个客户订单
|
OrderDetailEntity
|
包含客户订单的商品细节
|
InventoryItemEntity
|
包含库存商品
|
PurchaseOrderEntity
|
包含购买订单
|
PurchaseOrderDetailEntity
|
包含购买订单的商品细节
|
public int ProcessPendingOrders() { int itemsProcessed = 0; // get orders not yet shipped CustomerOrderFactory factory = new CustomerOrderFactory(); IList<OrderEntity> orders = factory.GetOrdersNotYetShipped(); // iterate through all orders not processed IEnumerator<OrderEntity> ordersEnum = orders.GetEnumerator(); while (ordersEnum.MoveNext()) { // get next order OrderEntity curOrder = ordersEnum.Current; Console.WriteLine(string.Format("Processing Order '{0}'...", curOrder.Id)); // check if merchandise is available to ship if (this.CanShip(curOrder)) { // process order if (this.ProcessOrder(curOrder)) { itemsProcessed++; } }// if can ship order else if (!curOrder.IsBackordered){ // set order to backordered if (this.ProcessBackorder(curOrder)) { itemsProcessed++; } } // if can't ship order (not enough merchandise) } // while more orders to process return itemsProcessed; } |
private bool CanShip(OrderEntity order) { bool hasMerchandise = true; // get items IEnumerator<OrderDetailEntity> detailEnum = order.GetOrderItems(); // iterate through all items while (detailEnum.MoveNext()) { // get current item OrderDetailEntity detailEntry = detailEnum.Current; InventoryItemEntity inventoryItem = detailEntry.Item; if (detailEntry.Quantity > inventoryItem.Quantity) { Console.WriteLine( string.Format("Order {0} - Insufficient Inventory: {1} ({2})", order.Id, inventoryItem.Name, inventoryItem.Id)); hasMerchandise = false; } // if inventory is sufficient } // while more entries to process Console.WriteLine(string.Format("Order {0} - Can Ship: {1}", order.Id, hasMerchandise)); return hasMerchandise; } |
private bool ProcessBackorder(OrderEntity order) { // set to backordered order.IsBackordered = true; // update order CustomerOrderFactory factory = new CustomerOrderFactory(); bool result = factory.UpdateOrder(order); if (!result) return result; // get purchase order xml string poXml = this.GetPurchaseOrderAsXml(order); // create message queue MessageQueueFactory queueFactory = new MessageQueueFactory(); return queueFactory.CreatePOQueueItem(poXml); } |
private PurchaseOrderEntity GetPurchaseOrder(OrderEntity order) { PurchaseOrderEntity po = new PurchaseOrderEntity(); po.PurchaseDate = DateTime.Now; // set company address of the Purchase Order - the Reseller po.CompanyAddress.CompanyName = "The Widget Factory"; po.CompanyAddress.StreetAddress = "100 Main Street"; po.CompanyAddress.CityName = "Las Vegas"; po.CompanyAddress.StateName = "NV"; po.CompanyAddress.ZipCode = "89044"; // set vendor address of the Purchase Order - the Manufacturer po.VendorAddress.CompanyName = "Widget Supplies"; po.VendorAddress.StreetAddress = "100 Main Street"; po.VendorAddress.CityName = "Orlando"; po.VendorAddress.StateName = "FL"; po.VendorAddress.ZipCode = "32801"; // while more items to process IEnumerator<OrderDetailEntity> orderEnum = order.GetOrderItems(); while (orderEnum.MoveNext()) { OrderDetailEntity orderItem = orderEnum.Current; InventoryItemEntity inventoryItem = orderItem.Item; // if insufficient inventory if (orderItem.Quantity > inventoryItem.Quantity) { // order the number needed plus 100 int quantityToOrder = (orderItem.Quantity - inventoryItem.Quantity) + 100; PurchaseOrderDetailEntity poItem = new PurchaseOrderDetailEntity(); poItem.ItemName = inventoryItem.Name; poItem.ItemId = inventoryItem.Id; poItem.Quantity = quantityToOrder; // add item to po po.AddItem(poItem); } } return po; } |
private string GetPurchaseOrderAsXml(OrderEntity order) { // get purchase order PurchaseOrderEntity po = this.GetPurchaseOrder(order); ; StringBuilder output = new StringBuilder(); // no name space XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); // settings to omit XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; XmlWriter writer = XmlTextWriter.Create(output, settings); XmlSerializer serializer = new XmlSerializer(typeof(PurchaseOrderEntity)); serializer.Serialize(writer, po, ns); Debug.WriteLine(output.ToString()); return output.ToString();} |
public bool CreatePOQueueItem(String poXml) { MessageQueueSQSDataProvider queueFactory = DW4DataContext.MessageQueueData; MessageQueueEntity message = new MessageQueueEntity(); message.MessageBody = poXml; message.MessageType = MessageTypes.PurchaseOrder; return queueFactory.InsertQueueItem(message); } |
public bool InsertQueueItem(MessageQueueEntity message) { String queueName = null; if (message.MessageType == MessageTypes.OrderSummary) { queueName = ConfigurationSettings.AppSettings["OrderSummaryQueue"]; return this.SendMessage(queueName, message.MessageBody); } else if (message.MessageType == MessageTypes.PurchaseOrder) { queueName = ConfigurationSettings.AppSettings["PurchaseOrderQueue"]; return this.SendMessage(queueName, message.MessageBody); } return false; } |
public bool SendMessage(string queueName, string messageBody) { bool result = true; try { String accessKeyId = ConfigurationSettings.AppSettings["AmazonAccessKeyID"]; ; String secretAccessKey = ConfigurationSettings.AppSettings["AmazonSecretAccessKey"]; AmazonSQS service = new AmazonSQSClient(accessKeyId, secretAccessKey); // build request SendMessageRequest request = new SendMessageRequest(); request.QueueName = queueName; request.MessageBody = messageBody; // send message SendMessageResponse response = service.SendMessage(request); if (response.IsSetSendMessageResult()) { Debug.WriteLine("Send Message Result:"); SendMessageResult sendMessageResult = response.SendMessageResult; if (sendMessageResult.IsSetMessageId()) { Debug.WriteLine(String.Format("\tMessageId: {0}", sendMessageResult.MessageId)); } if (sendMessageResult.IsSetMD5OfMessageBody()) { Debug.WriteLine("\tMD5 Of Message Body: ", sendMessageResult.MD5OfMessageBody); } } if (response.IsSetResponseMetadata()) { Debug.WriteLine("Response Metadata:"); ResponseMetadata responseMetadata = response.ResponseMetadata; if (responseMetadata.IsSetRequestId()) { Debug.WriteLine(String.Format("\tRequest Id: {0}", responseMetadata.RequestId)); } } } catch (AmazonSQSException ex) { Debug.WriteLine("Caught Exception: " + ex.Message); Debug.WriteLine("Response Status Code: " + ex.StatusCode); Debug.WriteLine("Error Code: " + ex.ErrorCode); Debug.WriteLine("Error Type: " + ex.ErrorType); Debug.WriteLine("Request ID: " + ex.RequestId); Debug.WriteLine("XML: " + ex.XML); result = false; } return result; } |
public int ProcessIncomingMerchandise() { int itemsProcessed = 0; OrderSummaryFactory osFactory = new OrderSummaryFactory(); IList<OrderSummaryEntity> orders = osFactory.GetOrderSummariesToProcess(); // iterate through all order summaries IEnumerator<OrderSummaryEntity> orderEnum = orders.GetEnumerator(); while (orderEnum.MoveNext()) { // get current order summary OrderSummaryEntity order = orderEnum.Current; // process order summary received if (this.ProcessOrderReceipt(order)) { itemsProcessed++; } } Debug.WriteLine(String.Format("Orders Processed: {0}", itemsProcessed)); return itemsProcessed; } |
private bool ProcessOrderReceipt(OrderSummaryEntity order) { if (order == null) return false; bool result = true; // add to inventory InventoryFactory inventoryFactory = new InventoryFactory(); // iterate through all items in order summary IEnumerator<OrderSummaryDetailEntity> itemsEnum = order.Items.GetEnumerator(); while (itemsEnum.MoveNext()) { // get current item OrderSummaryDetailEntity orderItem = itemsEnum.Current; // get item int itemId = orderItem.ItemId; InventoryItemEntity item = inventoryFactory.GetInventoryItem(itemId); // increase inventory item.Quantity = item.Quantity + orderItem.Quantity; result = inventoryFactory.UpdateInventoryItem(item); if (!result) break; } if (result) { MessageQueueFactory queueFactory = new MessageQueueFactory(); queueFactory.DeleteQueueItem(order.QueueItem); } return result; } |
(责任编辑:)
作为一名运维工程师,工作中最大的希望就是自己运维的网站能够稳定高效运行,但理想很...[详细]
电脑高手们都会尽可能地寻找各种快捷高效的操作方式,譬如很多快速启动类的工具(如Exe...[详细]
全闪存数据中心是个未来概念,同样还有不少方法实现数据中心内服务器或基于阵列的闪存...[详细]
手机九宫格解锁到底安全不?九宫格能画出多少图案啊?我自己设置的九宫格总是被同学分...[详细]
一名黑客生成加密程序的作者竟然没有实现其核心的功能:加密! 这位ID为NinjaDoge24(...[详细]