Пример #1
0
        public void Update(AdaptiveBlockContent block, AdaptiveBlock sourceBlock, PreviewBlockHostViewModel args)
        {
            TextBlockTitle.Text     = block.Title;
            TextBlockSubtitle.Text  = block.Subtitle ?? sourceBlock.View.Attributes.AttributionText?.Text ?? args.AppName;
            TextBlockTimestamp.Text = "Opened " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();

            var img = block.GetIconImageOrBestFit();

            if (img != null)
            {
                ImageOrIcon.Source = img.CreateImageSource();
            }
            else
            {
                var attrIcon = sourceBlock.View.Attributes.AttributionIcon?.GetIconForTheme(AdaptiveThemes.Dark);
                if (attrIcon != null)
                {
                    ImageOrIcon.Source = attrIcon.CreateImageSource();
                }
                else
                {
                    ImageOrIcon.Source = args.GetAppLogoImageSource();
                }
            }
        }
        public void Update(AdaptiveBlockContent block, AdaptiveBlock sourceBlock, PreviewBlockHostViewModel args)
        {
            TextBlockTitle.Text    = block.Title;
            TextBlockSubtitle.Text = block.Subtitle;

            StackPanelButtons.Children.Clear();
            StackPanelButtons.Visibility = Visibility.Visible;
            QuickReply.Visibility        = Visibility.Collapsed;
            foreach (var a in block.GetSimplifiedActions())
            {
                if (a.Inputs.Count == 0 || (a.Inputs.Count == 1 && a.Inputs[0] is AdaptiveTextInputBlock))
                {
                    var b = new Button()
                    {
                        Content    = a.Title,
                        Padding    = new Thickness(12),
                        Foreground = new SolidColorBrush(Colors.Red),
                        Style      = (Style)Resources["TextBlockButtonStyle"],
                        FontWeight = FontWeights.SemiBold
                    };
                    StackPanelButtons.Children.Add(b);
                    b.Click += delegate
                    {
                        if (a.Inputs.Count > 0)
                        {
                            StackPanelButtons.Visibility      = Visibility.Collapsed;
                            TextBoxQuickReply.PlaceholderText = a.Title;
                            QuickReply.Visibility             = Visibility.Visible;
                        }
                    };
                }
            }
        }
 public void Update(AdaptiveBlockContent block, AdaptiveBlock sourceBlock, PreviewBlockHostViewModel args)
 {
     try
     {
         m_prompts = block.GetSpeechPrompts();
         ItemsControlPrompts.ItemsSource = m_prompts;
     }
     catch { }
 }
Пример #4
0
 public static PreviewTimelineWebFullSizeMessageViewModel Create(AdaptiveBlockContent blockContent)
 {
     return(new PreviewTimelineWebFullSizeMessageViewModel()
     {
         From = blockContent.Title,
         Message = blockContent.Subtitle,
         ProfileImage = blockContent.GetProfileImage()?.Url,
         ImageAttachment = blockContent.GetBackgroundImage()?.Url // TODO: This has risk of same image being used for both
     });
 }
Пример #5
0
        public async void Update(AdaptiveBlockContent block, AdaptiveBlock sourceBlock, PreviewBlockHostViewModel args)
        {
            this.Children.Clear();

            try
            {
                AdaptiveCards.AdaptiveCard card = (await m_renderer.TransformAsync(sourceBlock)).Result;

                this.Children.Add(SharedAdaptiveCardRenderer.RenderFromCard(card));
            }
            catch { }
        }
        public async void Update(AdaptiveBlockContent block, AdaptiveBlock sourceBlock, PreviewBlockHostViewModel args)
        {
            MyPreviewToast.Properties = new PreviewToastProperties()
            {
                DisplayName     = args.AppName,
                Square44x44Logo = args.AppLogo
            };

            ToastContent content = (await new AdaptiveBlockToToastContentTransformer().TransformAsync(sourceBlock)).Result;

            MyPreviewToast.Initialize(content.GetXml());
        }
Пример #7
0
        public void Update(AdaptiveBlockContent block, AdaptiveBlock sourceBlock, PreviewBlockHostViewModel args)
        {
            DataContext = block;

            var icon = block.GetIconImageOrBestFit();

            if (icon?.Url != null)
            {
                IconImageBrush.ImageSource = new BitmapImage(new Uri(icon.Url));
                IconImage.Visibility       = Visibility.Visible;

                IconImage.Margin = new Thickness(icon.Hints.Category.Contains(AdaptiveBlockImageCategoryHints.Icon) ? 8 : 0);

                if (icon.BackgroundColor != null)
                {
                    //IconBackground.Fill = new SolidColorBrush(icon.BackgroundColor);
                }
                else
                {
                    IconBackground.Fill = new SolidColorBrush(Colors.LightGray);
                }
            }
            else
            {
                IconImage.Visibility = Visibility.Collapsed;
            }

            var actions = block.GetSimplifiedActions();

            if (actions.Any())
            {
                Buttons.Visibility = Visibility.Visible;

                FirstButton.Text = actions.First().Title;

                if (actions.Count() > 1)
                {
                    MoreButton.Visibility = Visibility.Visible;
                }
                else
                {
                    MoreButton.Visibility = Visibility.Collapsed;
                }
            }
            else
            {
                Buttons.Visibility = Visibility.Collapsed;
            }
        }
        public void Update(AdaptiveBlockContent block, AdaptiveBlock sourceBlock, PreviewBlockHostViewModel args)
        {
            var viewModel = new PreviewEchoSpotViewModel();

            var consumer = new AdaptiveBlockConsumer(AdaptiveBlock.Parse(sourceBlock.ToJson()).Block, new AdaptiveBlockConsumerProperties());

            if (consumer.ConsumeContent(out var contentConsumer))
            {
                if (contentConsumer.ConsumeText(out var text))
                {
                    viewModel.Title = text.Text;
                }

                if (contentConsumer.ConsumeText(out var textSubtitle))
                {
                    viewModel.Subtitle = textSubtitle.Text;
                }

                // In this case, if we only have a profile image, we'd rather use it as the background image
                // But if we have something to use as both the background and profile, then profile should be used.

                var backgroundImageRequest = AdaptiveBlockContentConsumer.ImageMatchRequest.ForBackgroundImage();

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

                contentConsumer.ConsumeImages(backgroundImageRequest, profileOrIconImageRequest);

                if (backgroundImageRequest.ImageResult != null)
                {
                    viewModel.BackgroundImage = backgroundImageRequest.ImageResult.Url;
                }

                if (profileOrIconImageRequest.ImageResult != null)
                {
                    viewModel.ProfileImage = profileOrIconImageRequest.ImageResult.Url;
                }
            }

            DataContext = viewModel;

            //DataContext = sourceBlock;
        }
        public static void MatchImages(AdaptiveBlockContent content, params ImageMatchRequest[] requests)
        {
            if (content.Images == null)
            {
                return;
            }

            foreach (var img in content.Images)
            {
                PlaceImageMatch(requests, img, new ImageMatchRequest[0]);

                if (requests.All(i => i.ImageResult != null))
                {
                    break;
                }
            }
        }
        public async void Update(AdaptiveBlockContent block, AdaptiveBlock sourceBlock, PreviewBlockHostViewModel args)
        {
            AdaptiveCardContainer.Child = null;
            AdaptiveCards.Rendering.Uwp.AdaptiveCard card = null;

            try
            {
                var cardObj = sourceBlock.View.RichContent.FirstOrDefault(i => i.TargetedExperiences.Contains("Microsoft.Outlook.ActionableMessage") && i.ContentType == "application/vnd.microsoft.card.adaptive")?.Content;
                if (cardObj != null)
                {
                    string cardJson   = cardObj.ToString();
                    var    parsedCard = SharedAdaptiveCardRenderer.Parse(cardJson);
                    if (parsedCard != null)
                    {
                        card = parsedCard;
                    }
                }
            }
            catch { }

            if (card == null)
            {
                try
                {
                    var transformer = new AdaptiveBlockToCardTransformer()
                    {
                        Properties = new AdaptiveBlockToCardTransformerProperties()
                    };
                    var sharedCard = (await transformer.TransformAsync(sourceBlock)).Result;

                    card = SharedAdaptiveCardRenderer.ConvertToUwpCard(sharedCard);
                }
                catch
                {
                }
            }

            try
            {
                if (card != null)
                {
                    AdaptiveCardContainer.Child = _cardRenderer.Value.RenderAdaptiveCard(card).FrameworkElement;
                }
            }
            catch { }
        }
Пример #11
0
        public void Update(AdaptiveBlockContent block, AdaptiveBlock sourceBlock, PreviewBlockHostViewModel args)
        {
            LogoOrAttributionIcon.Source = args.GetAppLogoImageSource();

            TextBlockTitle.Text = block.Text?.FirstOrDefault()?.Text;

            try
            {
                if (sourceBlock.View.Attributes != null)
                {
                    var attrUrl = sourceBlock.View.Attributes.AttributionIcon?.GetIconForTheme(AdaptiveThemes.Dark)?.Url;
                    if (attrUrl != null)
                    {
                        LogoOrAttributionIcon.Source = new BitmapImage(new Uri(attrUrl));
                    }
                }
            }
            catch { }
        }
        public void Update(AdaptiveBlockContent block, AdaptiveBlock sourceBlock, PreviewBlockHostViewModel args)
        {
            DataContext = args;

            RectangleThumbnail.Visibility = Visibility.Collapsed;

            TextBlockTitle.Text = block.Title;

            TextBlockAttributionOrSubtitle.Text = block.Subtitle ?? sourceBlock.View.Attributes?.AttributionText?.Text ?? "";

            if (block.FirstImage?.Url != null)
            {
                try
                {
                    ImageBrushThumbnail.ImageSource = new BitmapImage(new Uri(block.FirstImage.Url));
                    RectangleThumbnail.Visibility   = Visibility.Visible;
                }
                catch { }
            }
        }
        public void Update(AdaptiveBlockContent block, AdaptiveBlock sourceBlock, PreviewBlockHostViewModel args)
        {
            try
            {
                Pages.Children.Clear();

                foreach (var b in block.GetFinalBlocks())
                {
                    Pages.Children.Add(new PreviewRichWatchBlock()
                    {
                        DataContext = b
                    });
                }

                if (block.Actions.Any())
                {
                    Pages.Children.Add(new PreviewRichWatchActionsPage()
                    {
                        DataContext = block.GetSimplifiedActions()
                    });
                }
            }
            catch { }
        }
        public void Update(AdaptiveBlockContent block, AdaptiveBlock sourceBlock, PreviewBlockHostViewModel args)
        {
            TextBlockAppNameOrAttribution.Text = args.AppName;
            LogoOrAttributionIcon.Source       = args.GetAppLogoImageSource();

            TextBlockTitle.Text = block.Text.FirstOrDefault()?.Text;

            try
            {
                if (sourceBlock.View.Attributes != null)
                {
                    if (sourceBlock.View.Attributes.AttributionText?.Text != null)
                    {
                        TextBlockAppNameOrAttribution.Text = sourceBlock.View.Attributes.AttributionText.Text;
                    }

                    if (sourceBlock.View.Attributes.AttributionIcon?.Url != null)
                    {
                        LogoOrAttributionIcon.Source = new BitmapImage(new Uri(sourceBlock.View.Attributes.AttributionIcon?.Url));
                    }
                }
            }
            catch { }
        }
        public async void Update(AdaptiveBlockContent block, AdaptiveBlock sourceBlock, PreviewBlockHostViewModel args)
        {
            try
            {
                m_currSourceBlock   = sourceBlock;
                m_currHostViewModel = args;

                MyPreviewToast.Properties = new PreviewToastProperties()
                {
                    DisplayName     = args.AppName,
                    Square44x44Logo = args.AppLogo
                };



                AdaptiveBlockContent firstFinalBlock;

                if (IsExpanded)
                {
                    firstFinalBlock = sourceBlock.GetFirstFinalBlock().View.Content;
                }
                else
                {
                    firstFinalBlock = block;
                }

                string title    = firstFinalBlock.Title;
                string subtitle = firstFinalBlock.Subtitle;

                var originalText   = firstFinalBlock.Text.ToArray();
                var originalImages = firstFinalBlock.Images.ToArray();

                firstFinalBlock.Text.Clear();

                var firstHeroImg = firstFinalBlock.GetHeroImage();

                var firstProfileImg = firstFinalBlock.GetProfileImage();

                firstFinalBlock.Images.Clear();

                AdaptiveCard card;
                if (IsExpanded)
                {
                    var transformer = new AdaptiveBlockToCardTransformer();
                    card = (await transformer.TransformAsync(sourceBlock)).Result;
                }
                else
                {
                    card = new AdaptiveCard("1.0");
                }

                firstFinalBlock.Text.AddRange(originalText);
                firstFinalBlock.Images.AddRange(originalImages);

                card.AdditionalProperties["title"] = new Dictionary <string, string>()
                {
                    { "text", title }
                };
                if (subtitle != null)
                {
                    card.AdditionalProperties["subtitle"] = new Dictionary <string, string>()
                    {
                        { "text", subtitle }
                    };
                }

                Dictionary <string, Dictionary <string, string> > imagesObject = new Dictionary <string, Dictionary <string, string> >();

                if (firstProfileImg != null)
                {
                    imagesObject["profile"] = new Dictionary <string, string>()
                    {
                        { "url", firstProfileImg.Url },
                        { "style", "person" }
                    };
                }

                if (firstHeroImg != null)
                {
                    imagesObject["card"] = new Dictionary <string, string>()
                    {
                        { "url", firstHeroImg.Url }
                    };
                }

                if (imagesObject.Count > 0)
                {
                    card.AdditionalProperties["images"] = imagesObject;
                }

                MyPreviewToast.InitializeFromJson(card.ToJson(), new NotificationsVisualizerLibrary.PreviewNotificationData());
            }
            catch { }
        }
        public void Update(AdaptiveBlockContent block, AdaptiveBlock sourceBlock, PreviewBlockHostViewModel args)
        {
            DataContext = args;

            GenericContent.Visibility        = Visibility.Collapsed;
            CardContent.Child                = null;
            CardContent.Visibility           = Visibility.Collapsed;
            DocumentContent.Visibility       = Visibility.Collapsed;
            MessageTemplate.Visibility       = Visibility.Collapsed;
            BackgroundImageBrush.ImageSource = null;
            GenericContent.RequestedTheme    = ElementTheme.Light;
            BackgroundOverlay.Visibility     = Visibility.Collapsed;
            TextBlockAttribution.Text        = args.AppName;
            LogoOrAttributionIcon.Source     = args.GetAppLogoImageSource();

            try
            {
                if (sourceBlock.View.Attributes != null)
                {
                    if (sourceBlock.View.Attributes.AttributionText?.Text != null)
                    {
                        TextBlockAttribution.Text = sourceBlock.View.Attributes.AttributionText.Text;
                    }

                    if (sourceBlock.View.Attributes.AttributionIcon?.Url != null)
                    {
                        LogoOrAttributionIcon.Source = new BitmapImage(new Uri(sourceBlock.View.Attributes.AttributionIcon?.Url));
                    }
                }
            }
            catch { }

            try
            {
                var cardObj = sourceBlock.View.RichContent.FirstOrDefault(i => i.TargetedExperiences.Contains("Microsoft.UserActivities.Hero") && i.ContentType == "application/vnd.microsoft.card.adaptive")?.Content;
                if (cardObj != null)
                {
                    string cardJson          = cardObj.ToString();
                    var    cardParseResult   = AdaptiveCards.Rendering.Uwp.AdaptiveCard.FromJsonString(cardJson);
                    string errorsAndWarnings = string.Join("\n", cardParseResult.Errors.Select(i => i.Message));
                    if (cardParseResult.AdaptiveCard != null)
                    {
                        if (!string.IsNullOrWhiteSpace(cardParseResult.AdaptiveCard.BackgroundImage) && Uri.IsWellFormedUriString(cardParseResult.AdaptiveCard.BackgroundImage, UriKind.Absolute))
                        {
                            BackgroundImageBrush.ImageSource             = new BitmapImage(new Uri(cardParseResult.AdaptiveCard.BackgroundImage));
                            cardParseResult.AdaptiveCard.BackgroundImage = "";
                            BackgroundOverlay.Visibility = Visibility.Visible;
                        }

                        var renderedElement = (BackgroundImageBrush.ImageSource != null ? _cardRenderer : _cardRendererLight).Value.RenderAdaptiveCard(cardParseResult.AdaptiveCard).FrameworkElement;
                        CardContent.Child         = renderedElement;
                        CardContent.Visibility    = Visibility.Visible;
                        GenericContent.Visibility = Visibility.Collapsed;
                        return;
                    }
                }
            }
            catch { }

            TextBlockTitle.Text    = block.Title ?? "";
            TextBlockSubtitle.Text = block.Subtitle ?? "";

            var backgroundImg = block.GetBackgroundImage();

            if (backgroundImg?.Url != null)
            {
                try
                {
                    BackgroundImageBrush.ImageSource = new BitmapImage(new Uri(backgroundImg.Url));
                    GenericContent.RequestedTheme    = ElementTheme.Dark;
                    BackgroundOverlay.Visibility     = Visibility.Visible;
                }
                catch { }
            }

            DocumentImageBrush.ImageSource = block.GetHeroImage()?.CreateImageSource();

            if (sourceBlock.Hints.HasCategory("Thing.CreativeWork.DigitalDocument"))
            {
                DocumentContent.Visibility = Visibility.Visible;
            }
            else if (sourceBlock.Hints.HasCategory("Thing.CreativeWork.Message"))
            {
                MessageTemplate.Visibility  = Visibility.Visible;
                MessageTemplate.DataContext = PreviewTimelineWebFullSizeTemplates.PreviewTimelineWebFullSizeMessageViewModel.Create(block);
            }
            else
            {
                GenericContent.Visibility = Visibility.Visible;
            }
        }
 public AdaptiveBlockContentConsumer(AdaptiveBlockContent content, AdaptiveBlockConsumerProperties properties)
 {
     Content    = content;
     Properties = properties;
 }
Пример #18
0
 /// <summary>
 /// Note that the block WILL be modified.
 /// </summary>
 /// <param name="block"></param>
 /// <param name="properties"></param>
 public AdaptiveBlockConsumer(AdaptiveBlock block, AdaptiveBlockConsumerProperties properties)
 {
     Block     = block;
     m_content = block.View?.Content;
 }