protected override DataTemplate OnSelectTemplate(object item, BindableObject container) { ChatItem chatItem = item as ChatItem; FlightChatContext context = chatItem?.Data as FlightChatContext; if (context != null) { return(this.FlightTemplate); } Summary summary = chatItem?.Data as Summary; if (summary != null) { return(this.SummaryTemplate); } string text = chatItem?.Data as string; if (text == TravelBotViewModel.WaitingForBot) { return(this.WaitingForBotTemplate); } return(base.OnSelectTemplate(item, container)); }
private void RenderAdaptiveCard(Attachment attachment) { JsonSerializerSettings settings = new JsonSerializerSettings(); settings.Converters.Add(new JsonAdaptiveElementToObjectConverter()); AdaptiveCard adaptiveCard = JsonConvert.DeserializeObject <AdaptiveCard>(attachment.Content.ToString(), settings); if (adaptiveCard.TType == "Flight") { string passengerName = ((AdaptiveTextBlock)adaptiveCard.Body[1]).Text; string outDepartureCity = ((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[3]).Columns[0].Items[0]).Text; string outDepartureAirport = ((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[3]).Columns[0].Items[1]).Text; DateTime outDepartureDateTime = DateTime.ParseExact(((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[3]).Columns[0].Items[2]).Text + " " + ((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[3]).Columns[0].Items[3]).Text, "d MMM yyyy hh:mm tt", CultureInfo.InvariantCulture); string outArrivalCity = ((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[3]).Columns[2].Items[0]).Text; string outArrivalAirport = ((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[3]).Columns[2].Items[1]).Text; DateTime outArrivalDateTime = DateTime.ParseExact(((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[3]).Columns[2].Items[2]).Text + " " + ((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[3]).Columns[2].Items[3]).Text, "d MMM yyyy hh:mm tt", CultureInfo.InvariantCulture); string inDepartureCity = ((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[4]).Columns[0].Items[0]).Text; string inDepartureAirport = ((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[4]).Columns[0].Items[1]).Text; DateTime inDepartureDateTime = DateTime.ParseExact(((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[4]).Columns[0].Items[2]).Text + " " + ((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[4]).Columns[0].Items[3]).Text, "d MMM yyyy hh:mm tt", CultureInfo.InvariantCulture); string inArrivalCity = ((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[4]).Columns[2].Items[0]).Text; string inArrivalAirport = ((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[4]).Columns[2].Items[1]).Text; DateTime inArrivalDateTime = DateTime.ParseExact(((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[4]).Columns[2].Items[2]).Text + " " + ((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[4]).Columns[2].Items[3]).Text, "d MMM yyyy hh:mm tt", CultureInfo.InvariantCulture); string planeImage = ((AdaptiveImage)((AdaptiveColumnSet)adaptiveCard.Body[3]).Columns[1].Items[0]).Url.OriginalString; string total = ((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[5]).Columns[1].Items[0]).Text; List <FlightInfo> flights = new List <FlightInfo>() { new FlightInfo() { DepartureCity = outDepartureCity, DepartureAirport = outDepartureAirport, DepartureDate = outDepartureDateTime, ArrivalCity = outArrivalCity, ArrivalAirport = outArrivalAirport, ArrivalDate = outArrivalDateTime, PlaneImageUrl = planeImage }, new FlightInfo() { DepartureCity = inDepartureCity, DepartureAirport = inDepartureAirport, DepartureDate = inDepartureDateTime, ArrivalCity = inArrivalCity, ArrivalAirport = inArrivalAirport, ArrivalDate = inArrivalDateTime, PlaneImageUrl = planeImage } }; FlightChatContext context = new FlightChatContext() { Flights = flights, PassangerName = passengerName, TotalTicketPrice = total }; ChatItem flightItem = new ChatItem(); flightItem.Data = context; this.Items.Add(flightItem); } else if (adaptiveCard.TType == "Summary") { Summary summary = new Summary(); summary.Image = ((AdaptiveImage)adaptiveCard.Body[0]).Url.OriginalString; summary.Title = ((AdaptiveTextBlock)adaptiveCard.Body[1]).Text; summary.Hotel = ((AdaptiveTextBlock)adaptiveCard.Body[3]).Text; if (adaptiveCard.Body.Count > 6) { summary.Flights = new List <string>() { ((AdaptiveTextBlock)adaptiveCard.Body[5]).Text, ((AdaptiveTextBlock)adaptiveCard.Body[6]).Text }; } summary.TotalPrice = ((AdaptiveTextBlock)((AdaptiveColumnSet)adaptiveCard.Body[adaptiveCard.Body.Count - 1]).Columns[1].Items[0]).Text; ChatItem pickerItem = new ChatItem { Data = summary }; this.Items.Add(pickerItem); } }