示例#1
0
        public async Task Run([ServiceBusTrigger("booking", "booking-flight", Connection = "ServicebusConnectionString")] string mySbMsg, ILogger log)
        {
            log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");

            var bookFlightModel  = JsonConvert.DeserializeObject <BookFlightMessage>(mySbMsg);
            var bookFlightResult = await _bookFlightService.BookFlights(bookFlightModel);

            await _sendGridService.SendEmailWithInformation(bookFlightModel.Email, bookFlightResult, null);
        }
示例#2
0
        public async Task RunOrchestrator(
            [OrchestrationTrigger] DurableOrchestrationContext context)
        {
            var myMsb          = context.GetInput <string>();
            var messageContent = JsonConvert.DeserializeObject <BookCombinationMessage>(myMsb);

            var flightModel = new BookFlightMessage
            {
                Email           = messageContent.Email,
                CurrentCity     = messageContent.CurrentCityCode,
                DestinationCity = messageContent.DestinationCode,
                OutboundDate    = messageContent.OutboundDate,
                ReturnDate      = messageContent.ReturnDate
            };

            var hotelModel = new BookHotelMessage
            {
                Email           = messageContent.Email,
                ArrivalDate     = messageContent.OutboundDate,
                DepartureDate   = messageContent.ReturnDate,
                DestinationCity = messageContent.DestinationCity,
                GuestQty        = messageContent.GuestQty,
                RoomQty         = messageContent.RoomQty,
                TravelPurpose   = messageContent.TravelPurpose
            };

            string flightContent = null;
            string hotelContent  = null;

            var parallelTasks = new List <Task <KeyValuePair <string, string> > >();

            parallelTasks.Add(context.CallActivityAsync <KeyValuePair <string, string> >("BookFlightActivity", flightModel));
            parallelTasks.Add(context.CallActivityAsync <KeyValuePair <string, string> >("BookHotelActivity", hotelModel));

            await Task.WhenAll(parallelTasks);

            parallelTasks.ForEach(t =>
            {
                var result = t.Result;
                if (result.Key.Equals("flight"))
                {
                    flightContent = result.Value;
                }
                else if (result.Key.Equals("hotel"))
                {
                    hotelContent = result.Value;
                }
            });


            await _sendGridService.SendEmailWithInformation(messageContent.Email, flightContent, hotelContent);
        }