public ShopSalesOrder GetNAVOrder() { //Retrieves order from the shop center application (specific code goes here... ShopSalesOrder order = new ShopSalesOrder(); order.OrderNo = "OV1"; order.OrderDate = DateTime.Now; order.CustomerNo = "C0001"; List <ShopSalesOrderLine> lines = new List <ShopSalesOrderLine>(); ShopSalesOrderLine line = new ShopSalesOrderLine(); line.RowNo = 1; line.ItemNo = "ITEM1"; line.Quantity = 5; lines.Add(line); line = new ShopSalesOrderLine(); line.RowNo = 2; line.ItemNo = "ITEM2"; line.Quantity = 13; lines.Add(line); order.Lines = lines; return(order); }
//Receives Orders from Azure Service Bus private static void ReceiveOrders() { Console.WriteLine("\nReceiving message from Azure Service Bus Queue…"); try { var client = QueueClient.CreateFromConnectionString(ServiceBusConnectionString, QueueName); while (true) { try { //receive messages from Queue BrokeredMessage message = client.Receive(TimeSpan.FromSeconds(5)); if (message != null) { //Ricezione messaggio di testo //Console.WriteLine(string.Format("Message received: Id = {0}, Body = {1}", message.MessageId, message.GetBody<string>())); //Retrieves the order object Console.WriteLine(string.Format("Message received: Id = {0} ", message.MessageId)); ShopSalesOrder orderReceived = message.GetBody <ShopSalesOrder>(new DataContractSerializer(typeof(ShopSalesOrder))); //Send the order to NAV NAVInterface NAV = new NAVInterface(); NAV.CreateNAVSalesOrder(orderReceived); // Further custom message processing could go here… message.Complete(); } else { //no more messages in the queue break; } } catch (MessagingException e) { if (!e.IsTransient) { Console.WriteLine(e.Message); throw; } else { HandleTransientErrors(e); } } } } catch (Exception ex) { //Handle exception here... } }
//Send Orders to Azure Service Bus private static void SendOrders() { Console.WriteLine("\nSending message to Azure Service Bus Queue…"); try { ShopAppInterface SI = new ShopAppInterface(); ShopSalesOrder order = SI.GetNAVOrder(); var client = QueueClient.CreateFromConnectionString(ServiceBusConnectionString, QueueName); BrokeredMessage message = new BrokeredMessage(order, new DataContractSerializer(typeof(ShopSalesOrder))); client.Send(message); } catch (Exception ex) { //Handle exception here... } }
public void CreateNAVSalesOrder(ShopSalesOrder ExternalOrder) { try { //Here we have to call our NAV web service for creating a Sales Order //Web Service instantiation SalesOrder_Service ws = new SalesOrder_Service(); ws.Url = Properties.Settings.Default.NAVWSURL; ws.UseDefaultCredentials = true; //Create the Sales Header SalesOrder order = new SalesOrder(); ws.Create(ref order); //Here the Sales Order is created and we have the order no. //Update the Sales Header with details order.Sell_to_Customer_No = ExternalOrder.CustomerNo; order.Order_Date = ExternalOrder.OrderDate; order.Activity_Code = "123458"; int _rows = 0; if (ExternalOrder.Lines != null) { _rows = ExternalOrder.Lines.Count(); } if (_rows > 0) { //Create the Sales Lines array and initialize the lines order.SalesLines = new Sales_Order_Line[_rows]; for (int i = 0; i < _rows; i++) { order.SalesLines[i] = new Sales_Order_Line(); } } ws.Update(ref order); //Loads the data into the Lines if (_rows > 0) { int rowindex = 0; foreach (ShopSalesOrderLine _shopOrderLine in ExternalOrder.Lines) { Sales_Order_Line line = order.SalesLines[rowindex]; line.Type = NAVSalesOrderWS.Type.Item; line.No = _shopOrderLine.ItemNo; line.Quantity = _shopOrderLine.Quantity; rowindex++; } //Update the order lines with all the informations ws.Update(ref order); } Console.WriteLine("Order {0} created successfully.", order.No); } catch (Exception) { //Handle exceptions here... } }