// 以Id尋找Adaptive Element,並設定Select Action public AdaptiveCard SetSelectActionById(string id, CardAction tap) { var element = GetCardElementById(id); if (element == null) { return(Card); } var selectAction = AdaptiveElementBuilder.CreateAction(tap); switch (element.Type) { case AdaptiveImage.TypeName: (element as AdaptiveImage).SelectAction = selectAction; break; case AdaptiveContainer.TypeName: (element as AdaptiveContainer).SelectAction = selectAction; break; case AdaptiveColumnSet.TypeName: (element as AdaptiveColumnSet).SelectAction = selectAction; break; case AdaptiveColumn.TypeName: (element as AdaptiveColumn).SelectAction = selectAction; break; } return(Card); }
// Create AdaptiveCard from ThumbnailCard public static AdaptiveCard CreateThumbnailCard(ThumbnailCard card, string version = "1.0") { var adaptiveCard = new AdaptiveCard(); var body = new AdaptiveContainer() { Items = new List <AdaptiveElement>() }; // Add Image var image = AdaptiveElementBuilder.CreateImage(card.Images, AdaptiveImageSize.Medium); if (image != null) { body.Items.Add(image); } // Add Title, SubTitle and Text body.Items.AddRange(AdaptiveElementBuilder.CreateTitle(card.Title, card.Subtitle, card.Text)); // Set Tap Action if (card.Tap != null) { body.SelectAction = AdaptiveElementBuilder.CreateAction(card.Tap); } // Set Body and Actions adaptiveCard.Body = new List <AdaptiveElement>() { body }; adaptiveCard.Actions = AdaptiveElementBuilder.CreateActions(card.Buttons); adaptiveCard.Version = version; return(adaptiveCard); }
// Create List Card public static AdaptiveCard CreateListCard(IList <AdaptiveListCardItem> listItem, string title = null, IList <CardAction> buttons = null, AdaptiveListCardImageLayout imageLayout = AdaptiveListCardImageLayout.Right, AdaptiveImageSize imageSize = AdaptiveImageSize.Small, string version = "1.0") { var adaptiveCard = new AdaptiveCard(); var body = new AdaptiveContainer() { Items = new List <AdaptiveElement>() }; // Add Title if (!string.IsNullOrEmpty(title)) { body.Items.AddRange(AdaptiveElementBuilder.CreateTitle(title, AdaptiveTextSize.Large)); } // Add List Item body.Items.AddRange(CreateListItems(listItem, imageLayout, imageSize)); // Set Body and Actions adaptiveCard.Body = new List <AdaptiveElement>() { body }; adaptiveCard.Actions = AdaptiveElementBuilder.CreateActions(buttons); adaptiveCard.Version = version; return(adaptiveCard); }
// Create Fact Card public static AdaptiveCard CreateFactListCard(string title, IList <Fact> facts, IList <CardAction> buttons = null, CardImage image = null, string version = "1.0") { var adaptiveCard = new AdaptiveCard(); var body = new AdaptiveContainer() { Items = new List <AdaptiveElement>() }; // Add Image if (image != null) { // Add Image body.Items.Add(AdaptiveElementBuilder.CreateImage(image, AdaptiveImageSize.Medium)); } // Add Title body.Items.AddRange(AdaptiveElementBuilder.CreateTitle(title)); // Add FaceSet body.Items.Add(AdaptiveElementBuilder.CreateFactSet(facts)); // Set Body and Actions adaptiveCard.Body = new List <AdaptiveElement>() { body }; adaptiveCard.Actions = AdaptiveElementBuilder.CreateActions(buttons); adaptiveCard.Version = version; return(adaptiveCard); }
// Create Confirm Card public static AdaptiveCard CreateConfirmCard(string title, CardAction yesAction = null, CardAction noAction = null, CardImage image = null, string version = "1.0") { var adaptiveCard = new AdaptiveCard(); var body = new AdaptiveContainer() { Items = new List <AdaptiveElement>() }; // Add Image if (image != null) { // Add Image body.Items.Add(AdaptiveElementBuilder.CreateImage(image, AdaptiveImageSize.Medium)); } // Add Title body.Items.AddRange(AdaptiveElementBuilder.CreateTitle(title)); // Add Action var actions = AdaptiveElementBuilder.CreateActions(new List <CardAction>() { yesAction ?? GetYesAction(), noAction ?? GetNoAction(), }); // Set Body and Actions adaptiveCard.Body = new List <AdaptiveElement>() { body }; adaptiveCard.Actions = actions; adaptiveCard.Version = version; return(adaptiveCard); }
private void SetValue(AdaptiveImageSet imageSet, object value) { if (value is List <AdaptiveImage> ) { imageSet.Images = value as List <AdaptiveImage>; } else if (value is List <CardImage> ) { imageSet = AdaptiveElementBuilder.CreateImageSet(value as List <CardImage>) as AdaptiveImageSet; } else if (value is List <MediaUrl> ) { imageSet = AdaptiveElementBuilder.CreateImageSet(value as List <MediaUrl>) as AdaptiveImageSet; } }
private void SetValue(AdaptiveFactSet factSet, object value) { if (value is List <AdaptiveFact> ) { factSet.Facts = value as List <AdaptiveFact>; } else if (value is List <Fact> ) { factSet = AdaptiveElementBuilder.CreateFactSet(value as List <Fact>) as AdaptiveFactSet; } else if (value is Dictionary <string, object> ) { factSet.Facts = new List <AdaptiveFact>(); var dictionary = value as Dictionary <string, object>; var keys = dictionary.Keys; foreach (var key in keys) { factSet.Facts.Add(new AdaptiveFact(key, Convert.ToString(dictionary[key]))); } } }
// Create AdaptiveCard from SigninCard public static AdaptiveCard CreateSigninCard(SigninCard card, string version = "1.0") { var adaptiveCard = new AdaptiveCard(); var body = new AdaptiveContainer() { Items = new List <AdaptiveElement>() }; // Add Title body.Items.AddRange(AdaptiveElementBuilder.CreateTitle(card.Text)); // Set Body and Actions adaptiveCard.Body = new List <AdaptiveElement>() { body }; adaptiveCard.Actions = AdaptiveElementBuilder.CreateActions(card.Buttons); adaptiveCard.Version = version; return(adaptiveCard); }
// Create ImageSet Card public static AdaptiveCard CreateImageSetCard(IList <CardImage> images, IList <CardAction> buttons = null, string version = "1.0") { var adaptiveCard = new AdaptiveCard(); var body = new AdaptiveContainer() { Items = new List <AdaptiveElement>() }; // Add Image if (images != null) { // Add Image body.Items.Add(AdaptiveElementBuilder.CreateImageSet(images, AdaptiveImageSize.Medium)); } // Set Body and Actions adaptiveCard.Body = new List <AdaptiveElement>() { body }; adaptiveCard.Actions = AdaptiveElementBuilder.CreateActions(buttons); adaptiveCard.Version = version; return(adaptiveCard); }
// Add List Item private static AdaptiveElement CreateListItem(AdaptiveListCardItem item, int itemIndex, AdaptiveListCardImageLayout imageLayout, AdaptiveImageSize imageSize = AdaptiveImageSize.Small) { var columns = new List <AdaptiveColumn>(); // Add Title, subtitile, text var itemContent = new AdaptiveColumn(); if (!string.IsNullOrEmpty(item.Title)) { itemContent.Items.Add(new AdaptiveTextBlock() { Text = item.Title, Id = $"Item-{itemIndex}-Title", Size = AdaptiveTextSize.Medium, Weight = AdaptiveTextWeight.Bolder, Spacing = AdaptiveSpacing.None, HorizontalAlignment = AdaptiveHorizontalAlignment.Left }); } if (!string.IsNullOrEmpty(item.Subtitle)) { itemContent.Items.Add(new AdaptiveTextBlock() { Text = item.Subtitle, Id = $"Item-{itemIndex}-Subtitle", Size = AdaptiveTextSize.Default, Spacing = AdaptiveSpacing.None, IsSubtle = true, HorizontalAlignment = AdaptiveHorizontalAlignment.Left }); } if (!string.IsNullOrEmpty(item.Text)) { itemContent.Items.Add(new AdaptiveTextBlock() { Text = item.Text, Id = $"Item-{itemIndex}-Text", Size = AdaptiveTextSize.Small, Spacing = AdaptiveSpacing.None, Weight = AdaptiveTextWeight.Lighter, IsSubtle = true, HorizontalAlignment = AdaptiveHorizontalAlignment.Left }); } // Add List Image var itemImage = new AdaptiveColumn() { Items = new List <AdaptiveElement>(), Width = AdaptiveColumnWidth.Auto.ToLower() }; if (item.Image != null && !string.IsNullOrEmpty(item.Image.Url)) { itemImage.Items.Add(AdaptiveElementBuilder.CreateImage(item.Image, imageSize)); } // Set List Item switch (imageLayout) { case AdaptiveListCardImageLayout.Right: columns.Add(itemContent); columns.Add(itemImage); break; case AdaptiveListCardImageLayout.Left: columns.Add(itemImage); columns.Add(itemContent); break; case AdaptiveListCardImageLayout.None: default: columns.Add(itemContent); break; } return(new AdaptiveColumnSet() { Separator = true, Columns = columns, SelectAction = AdaptiveElementBuilder.CreateAction(item.Tap) }); }
// Add Receipt Items private static AdaptiveElement CreateReceiptItem(ReceiptItem item, int itemIndex, AdaptiveImageSize imageSize = AdaptiveImageSize.Small) { var columns = new List <AdaptiveColumn>(); // Add Receipt Item Image if (item.Image != null && item.Image.Url != null) { columns.Add(new AdaptiveColumn() { Width = AdaptiveColumnWidth.Auto.ToLower(), Items = new List <AdaptiveElement>() { AdaptiveElementBuilder.CreateImage(item.Image, imageSize, id: $"Item-{itemIndex}-Image") } }); } // Add Receipt Item Title and Subtitle if (!string.IsNullOrEmpty(item.Title) || !string.IsNullOrEmpty(item.Subtitle)) { var title = (!string.IsNullOrEmpty(item.Title)) ? item.Title : string.Empty; var subtitle = (!string.IsNullOrEmpty(item.Subtitle)) ? item.Subtitle : string.Empty; columns.Add(new AdaptiveColumn() { Width = AdaptiveColumnWidth.Auto.ToLower(), Items = new List <AdaptiveElement>() { new AdaptiveTextBlock() { Text = title, Id = $"Item-{itemIndex}-Title", Size = AdaptiveTextSize.Medium, Spacing = AdaptiveSpacing.None, HorizontalAlignment = AdaptiveHorizontalAlignment.Left }, new AdaptiveTextBlock() { Text = subtitle, Id = $"Item-{itemIndex}-Subtitle", Size = AdaptiveTextSize.Default, Spacing = AdaptiveSpacing.None, HorizontalAlignment = AdaptiveHorizontalAlignment.Left } } }); } // Add Price if (!string.IsNullOrEmpty(item.Price)) { columns.Add(new AdaptiveColumn() { Width = AdaptiveColumnWidth.Stretch.ToLower(), Items = new List <AdaptiveElement>() { new AdaptiveTextBlock() { Text = item.Price, Id = $"Item-{itemIndex}-Price", Size = AdaptiveTextSize.Medium, HorizontalAlignment = AdaptiveHorizontalAlignment.Right } } }); } return(new AdaptiveColumnSet() { Columns = columns, SelectAction = AdaptiveElementBuilder.CreateAction(item.Tap) }); }
// Create AdaptiveCard from ReceiptCard public static AdaptiveCard CreateReceiptCard(ReceiptCard card, string totalTitle = "Total", string vatTitle = "VAT", string taxTitle = "Tax", string version = "1.0") { var adaptiveCard = new AdaptiveCard(); var body = new AdaptiveContainer() { Items = new List <AdaptiveElement>() }; // Add Title body.Items.AddRange(AdaptiveElementBuilder.CreateTitle(card.Title)); // Add Receipt Fact if (card.Facts != null && card.Facts.Count != 0) { body.Items.AddRange(CreateReceiptFactSet(card.Facts)); } // Add Separator body.Items.Add(CreateReceiptSeparator()); // Add Receipt Item if (card.Items != null && card.Items.Count != 0) { body.Items.AddRange(CreateReceiptItems(card.Items.ToList())); } // Add Separator body.Items.Add(CreateReceiptSeparator()); // Add VAT if (!string.IsNullOrEmpty(card.Vat)) { body.Items.Add(CreateReceiptOtherInfo(vatTitle, card.Vat, "Vat")); } // Add Tax if (!string.IsNullOrEmpty(card.Tax)) { body.Items.Add(CreateReceiptOtherInfo(taxTitle, card.Tax, "Tax")); } // Add Total if (!string.IsNullOrEmpty(card.Total)) { body.Items.Add(CreateReceiptTotalInfo(totalTitle, card.Total)); } // Set Tap Action if (card.Tap != null) { body.SelectAction = AdaptiveElementBuilder.CreateAction(card.Tap); } // Set Body and Actions adaptiveCard.Body = new List <AdaptiveElement>() { body }; adaptiveCard.Actions = AdaptiveElementBuilder.CreateActions(card.Buttons); adaptiveCard.Version = version; return(adaptiveCard); }