public static async Task OrderOrchestrator([OrchestrationTrigger] DurableOrchestrationContext context, TraceWriter log) { log.Info($"Starting to wait InstanceId:{context.InstanceId}, Input:{context.GetInput<string>()}"); var orderHeaderDetailsEvent = context.WaitForExternalEvent <string>("OrderHeaderDetails"); var orderLineItemsEvent = context.WaitForExternalEvent <string>("OrderLineItems"); var productInformationEvent = context.WaitForExternalEvent <string>("ProductInformation"); await Task.WhenAll(orderHeaderDetailsEvent, orderLineItemsEvent, productInformationEvent); var orderFiles = new OrderFiles { OrderHeaderDetails = orderHeaderDetailsEvent.Result, OrderLineItems = orderLineItemsEvent.Result, ProductInformation = productInformationEvent.Result }; log.Info($"Received header:{orderFiles.OrderHeaderDetails}, line:{orderFiles.OrderLineItems}, product:{orderFiles.ProductInformation}"); var orders = await context.CallActivityAsync <IEnumerable <Order> >("OrderProcessor", orderFiles); await context.CallActivityAsync("SaveOrders", orders); log.Info("Work done!"); }
public static async Task <IEnumerable <Order> > OrderProcessor([ActivityTrigger] OrderFiles orderFiles, TraceWriter log) { var client = _orderStorageAccount.CreateCloudBlobClient(); using (var orderHeaderReader = await client.GetBlobReferenceFromServerAsync(new Uri(orderFiles.OrderHeaderDetails)).GetCsvReader()) using (var orderLineItemsReader = await client.GetBlobReferenceFromServerAsync(new Uri(orderFiles.OrderLineItems)).GetCsvReader()) using (var productInformationReader = await client.GetBlobReferenceFromServerAsync(new Uri(orderFiles.ProductInformation)).GetCsvReader()) { var orders = orderHeaderReader.GetRecords <dynamic>().ToDictionary(r => (string)r.ponumber, r => new Order { dateTime = r.datetime, locationId = r.locationid, locationName = r.locationname, locationPostCode = r.locationpostcode, poNumber = r.ponumber, totalCost = double.Parse(r.totalcost), totalTax = double.Parse(r.totaltax), lineItems = new List <OrderLineItem>(), id = r.ponumber }); var products = productInformationReader.GetRecords <dynamic>().ToDictionary(r => (string)r.productid, r => r); foreach (var lineItem in orderLineItemsReader.GetRecords <dynamic>()) { var product = products[lineItem.productid]; orders[(string)lineItem.ponumber].lineItems.Add(new OrderLineItem { productId = lineItem.productid, quantity = int.Parse(lineItem.quantity), unitCost = double.Parse(lineItem.unitcost), totalCost = double.Parse(lineItem.totalcost), totalTax = double.Parse(lineItem.totaltax), productDescription = product.productdescription, productName = product.productname }); } return(orders.Values); } }