Exemple #1
0
        // Create Image
        public static AdaptiveImage CreateImage(IList <MediaUrl> cardImages, AdaptiveImageSize size = AdaptiveImageSize.Medium)
        {
            if (cardImages == null || cardImages.FirstOrDefault() == null)
            {
                return(null);
            }

            var image = cardImages.FirstOrDefault();

            return(CreateImage(image, size));
        }
Exemple #2
0
 // Create Image
 public static AdaptiveImage CreateImage(MediaUrl image, AdaptiveImageSize size = AdaptiveImageSize.Medium, string id = "Image")
 {
     if (image != null)
     {
         return(new AdaptiveImage()
         {
             Id = id ?? string.Empty,
             Url = new Uri(image.Url),
             Size = size
         });
     }
     return(null);
 }
Exemple #3
0
 // Create Image
 public static AdaptiveImage CreateImage(CardImage image, AdaptiveImageSize size = AdaptiveImageSize.Medium, string id = "Image")
 {
     if (image != null)
     {
         return(new AdaptiveImage()
         {
             Id = id ?? string.Empty,
             Url = new Uri(image.Url),
             Size = size,
             AltText = image.Alt,
             SelectAction = CreateAction(image.Tap)
         });
     }
     return(null);
 }
Exemple #4
0
        // Create ImageSet
        public static AdaptiveElement CreateImageSet(IList <CardImage> cardImages, AdaptiveImageSize size = AdaptiveImageSize.Medium)
        {
            var imageSet = new AdaptiveImageSet()
            {
                Id     = "ImageSet",
                Images = new List <AdaptiveImage>()
            };

            if (cardImages == null || cardImages.Count == 0)
            {
                return(null);
            }

            for (var i = 0; i < cardImages.Count; i++)
            {
                var cardImage = cardImages[i];
                imageSet.Images.Add(CreateImage(cardImage, size, $"Image-{i + 1}"));
            }

            return(imageSet);
        }
Exemple #5
0
            bool imageSourceIsLargerThanExpectedRenderingSize(int?imageSourceWidth, int?imageSourceHeight, AdaptiveImageSize imageSize, AdaptiveRenderContext context)
            {
                // No size provided, let's keep previous behaviour
                if (!imageSourceWidth.HasValue || !imageSourceHeight.HasValue)
                {
                    return(false);
                }

                int imageSizeInPixels = int.MaxValue;

                switch (imageSize)
                {
                case AdaptiveImageSize.Small:
                    imageSizeInPixels = context.Config.ImageSizes.Small;
                    break;

                case AdaptiveImageSize.Medium:
                    imageSizeInPixels = context.Config.ImageSizes.Medium;
                    break;

                case AdaptiveImageSize.Large:
                    imageSizeInPixels = context.Config.ImageSizes.Large;
                    break;
                }

                return((imageSourceWidth.Value > imageSizeInPixels) || (imageSourceHeight.Value > imageSizeInPixels));
            }
Exemple #6
0
        private static List <AdaptiveElement> CreateListItems(IList <AdaptiveListCardItem> items, AdaptiveListCardImageLayout imageLayout, AdaptiveImageSize imageSize = AdaptiveImageSize.Small)
        {
            var content = new List <AdaptiveElement>();

            for (int i = 0; i < items.Count; i++)
            {
                var item = items[i];
                content.Add(CreateListItem(item, i + 1, imageLayout, imageSize));
            }

            return(content);
        }
Exemple #7
0
        // 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)
            });
        }
Exemple #8
0
        private static List <AdaptiveElement> CreateReceiptItems(List <ReceiptItem> items, AdaptiveImageSize imageSize = AdaptiveImageSize.Small)
        {
            var content = new List <AdaptiveElement>();

            for (int i = 0; i < items.Count; i++)
            {
                var item = items[i];
                content.Add(CreateReceiptItem(item, i + 1));
            }

            return(content);
        }
Exemple #9
0
        // 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)
            });
        }
Exemple #10
0
        // 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);
        }