Пример #1
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 { }
        }
        private async void RenderBlock(AdaptiveBlock block)
        {
            var transformer = new AdaptiveBlockToCardTransformer();

            var sharedCard = (await transformer.TransformAsync(block)).Result;

            if (sharedCard != null)
            {
                TextBoxCardPayload.Text = sharedCard.ToJson();
            }

            var uwpCard = SharedAdaptiveCardRenderer.ConvertToUwpCard(sharedCard);

            RenderCard(CardPreview, uwpCard, m_cardRenderer);
            RenderCard(CardPreviewTeams, uwpCard, m_cardRendererTeams);
            RenderCard(CardPreviewCortana, uwpCard, m_cardRendererCortana);
        }
        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 { }
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            AdaptiveAction action = (sender as FrameworkElement).DataContext as AdaptiveAction;

            if (action != null && action.Inputs.Any())
            {
                var transformer = new AdaptiveBlockToCardTransformer();
                var sharedCard  = (await transformer.TransformAsync(new AdaptiveBlock(new AdaptiveBlockContent()
                {
                    Actions =
                    {
                        action
                    }
                }))).Result;

                InputCollectionFields.Child = SharedAdaptiveCardRenderer.RenderFromCard(sharedCard);
                InputCollection.Visibility  = Visibility.Visible;
            }
            else
            {
                await new MessageDialog("Action performed!").ShowAsync();
            }
        }
        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 { }
        }