protected override async Task TransformAsync(AdaptiveBlock block, AdaptiveBlockTransformResult <WebNotification> result)
        {
            var content = block?.View?.Content;

            if (content?.Title != null)
            {
                WebNotification notification = new WebNotification()
                {
                    Title = content.Title,
                    Body  = content.Subtitle,
                    Image = content.Images?.FirstOrDefault()?.Url
                };

                foreach (var action in content.GetSimplifiedActions())
                {
                    if (action.Inputs.Count == 0 && action.Command != null)
                    {
                        notification.Actions.Add(new WebNotificationAction()
                        {
                            Title  = action.Title,
                            Action = JsonConvert.SerializeObject(action.Command)
                        });
                    }
                }

                result.Result = notification;
            }
            else
            {
                result.Errors.Add("There wasn't a title");
            }
        }
コード例 #2
0
 protected override Task TransformAsync(AdaptiveBlock block, AdaptiveBlockTransformResult <AdaptiveCard> result)
 {
     try
     {
         result.Result = TransformToCard(block);
     }
     catch (Exception ex)
     {
         result.Errors.Add(ex.ToString());
     }
     return(Task.CompletedTask);
 }
        protected override Task TransformAsync(AdaptiveBlock block, AdaptiveBlockTransformResult <ToastContent> result)
        {
            ToastContent content = new ToastContent()
            {
                Visual = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                }
            };

            var finalBlocks = block.GetFinalBlocks();
            var firstBlock  = finalBlocks.First();


            var firstBlockContent = firstBlock.View?.Content;

            if (firstBlockContent != null)
            {
                foreach (var t in firstBlockContent.Text.Take(3))
                {
                    content.Visual.BindingGeneric.Children.Add(new AdaptiveText()
                    {
                        Text = t.Text
                    });
                }

                var profileOrIconImageRequest = new AdaptiveBlockContentConsumer.ImageMatchRequest()
                {
                    RequiredHint =
                    {
                        AdaptiveBlockImageCategoryHints.Profile,
                        AdaptiveBlockImageCategoryHints.Icon
                    }
                };

                var heroImageRequest = new AdaptiveBlockContentConsumer.ImageMatchRequest()
                {
                    HintsToAvoid =
                    {
                        AdaptiveBlockImageCategoryHints.Icon
                    }
                };

                AdaptiveBlockContentConsumer.MatchImages(firstBlockContent, profileOrIconImageRequest, heroImageRequest);

                if (heroImageRequest.ImageResult != null)
                {
                    content.Visual.BindingGeneric.HeroImage = new ToastGenericHeroImage()
                    {
                        Source = heroImageRequest.ImageResult.Url
                    };
                }

                if (profileOrIconImageRequest.ImageResult != null)
                {
                    content.Visual.BindingGeneric.AppLogoOverride = new ToastGenericAppLogo()
                    {
                        Source   = profileOrIconImageRequest.ImageResult.Url,
                        HintCrop = profileOrIconImageRequest.ImageResult.Hints.Category.Contains(AdaptiveBlockImageCategoryHints.Profile) ? ToastGenericAppLogoCrop.Circle : ToastGenericAppLogoCrop.Default
                    };
                }

                if (finalBlocks.Count() > 1)
                {
                    foreach (var extraBlock in finalBlocks.Skip(1))
                    {
                        if (extraBlock.View?.Content != null)
                        {
                            content.Visual.BindingGeneric.Children.Add(CreateGroup(extraBlock.View.Content));
                        }
                    }
                }

                if (block.View.Attributes?.AttributionText?.Text != null)
                {
                    content.Visual.BindingGeneric.Attribution = new ToastGenericAttributionText()
                    {
                        Text = block.View.Attributes?.AttributionText?.Text
                    };
                }

                if (firstBlockContent.Actions.Any())
                {
                    content.Actions = new ToastActionsCustom();
                    var toastActions = content.Actions as ToastActionsCustom;

                    foreach (var a in firstBlockContent.Actions)
                    {
                        // Quick reply style
                        if (a is AdaptiveAction singleFinalAction && a.Inputs.Count == 1 && a.Inputs.First() is AdaptiveTextInputBlock singleTextInput)
                        {
                            toastActions.Inputs.Add(new ToastTextBox(singleTextInput.Id)
                            {
                                PlaceholderContent = singleTextInput.Placeholder
                            });
                            var button = CreateButton(singleFinalAction);
                            button.TextBoxId = singleTextInput.Id;
                            toastActions.Buttons.Add(button);
                        }
                        else
                        {
                            foreach (var input in a.Inputs)
                            {
                                if (input is AdaptiveTextInputBlock textInput)
                                {
                                    toastActions.Inputs.Add(new ToastTextBox(textInput.Id)
                                    {
                                        PlaceholderContent = textInput.Placeholder,
                                        Title = textInput.Title
                                    });
                                }

                                else if (input is AdaptiveChoiceSetInputBlock choiceInput)
                                {
                                    var selectionBox = new ToastSelectionBox(choiceInput.Id)
                                    {
                                        Title = choiceInput.Title
                                    };
                                    foreach (var val in choiceInput.Choices)
                                    {
                                        selectionBox.Items.Add(new ToastSelectionBoxItem(val.Value, val.Title));
                                    }
                                    toastActions.Inputs.Add(selectionBox);
                                }
                            }

                            List <AdaptiveAction> finalActions;
                            if (a is AdaptiveSharedInputActions sharedActions)
                            {
                                finalActions = sharedActions.Actions;
                            }
                            else if (a is AdaptiveAction finalAction)
                            {
                                finalActions = new List <AdaptiveAction>()
                                {
                                    finalAction
                                };
                            }
                            else
                            {
                                finalActions = new List <AdaptiveAction>();
                            }

                            foreach (var finalAction in finalActions)
                            {
                                toastActions.Buttons.Add(CreateButton(finalAction));
                            }
                        }
                    }
                }
コード例 #4
0
        protected override Task TransformAsync(AdaptiveBlock block, AdaptiveBlockTransformResult <UserActivity> result)
        {
            var content = block.View?.Content;

            if (content != null)
            {
                if (content.Title != null)
                {
                    m_activity.VisualElements.DisplayText = content.Title;
                }

                if (content.Subtitle != null)
                {
                    m_activity.VisualElements.Description = content.Subtitle;
                }
            }

            var cardContent = block.View?.RichContent?.FirstOrDefault(i => i.ContentType == "application/vnd.microsoft.card.adaptive" && i.TargetedExperiences != null && i.TargetedExperiences.Contains("Microsoft.UserActivities.Hero"))?.Content;

            if (cardContent != null)
            {
                m_activity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(cardContent.ToString());
            }
            else if (content != null)
            {
                var backgroundImageRequest = AdaptiveBlockContentConsumer.ImageMatchRequest.ForBackgroundImage();

                AdaptiveBlockContentConsumer.MatchImages(content, backgroundImageRequest);

                if (backgroundImageRequest.ImageResult != null)
                {
                    var adaptiveCard = new AdaptiveCard("1.0");
                    adaptiveCard.BackgroundImage = new Uri(backgroundImageRequest.ImageResult.Url);

                    if (content.Title != null)
                    {
                        adaptiveCard.Body.Add(new AdaptiveTextBlock()
                        {
                            Text     = content.Title,
                            Size     = AdaptiveTextSize.Large,
                            Weight   = AdaptiveTextWeight.Bolder,
                            Wrap     = true,
                            MaxLines = 3
                        });
                    }

                    if (content.Subtitle != null)
                    {
                        adaptiveCard.Body.Add(new AdaptiveTextBlock()
                        {
                            Text     = content.Subtitle,
                            Wrap     = true,
                            MaxLines = 3
                        });
                    }

                    m_activity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(adaptiveCard.ToJson());
                }
            }

            if (block.View?.Attributes != null)
            {
                var attributes = block.View.Attributes;

                if (attributes.AttributionText != null)
                {
                    m_activity.VisualElements.AttributionDisplayText = attributes.AttributionText.Text;
                }

                var attrIcon = attributes.AttributionIcon?.GetIconForTheme(AdaptiveThemes.Dark);
                if (attrIcon != null)
                {
                    m_activity.VisualElements.Attribution = new UserActivityAttribution(new Uri(attrIcon.Url));
                }
            }

            result.Result = m_activity;
            return(Task.CompletedTask);
        }