GetContent() публичный Метод

Retrieves the notification XML content as a string, so that it can be sent with a HTTP POST in a push notification.
public GetContent ( ) : string
Результат string
        private void ButtonSendTileNotification_Click(object sender, RoutedEventArgs e)
        {
            TileBindingContentAdaptive bindingContent = new TileBindingContentAdaptive()
            {
            Children =
            {
            GenerateEmailGroup("Jennifer Parker", "Photos from our trip"),
            GenerateEmailGroup("Steve Bosniak", "Want to go out for dinner after Build tonight?")
            }
            };

            TileBinding binding = new TileBinding()
            {
            Content = bindingContent
            };

            TileContent content = new TileContent()
            {
            Visual = new TileVisual()
            {
            TileMedium = binding
            }
            };

            DataPackage dp = new DataPackage();
            dp.SetText(content.GetContent());
            Clipboard.SetContent(dp);
            return;

            string xmlAsString = content.GetContent();
            TileNotification notification = new TileNotification(content.GetXml());

            content.Visual.TileMedium = new TileBinding()
            {
                Branding = TileBranding.Logo,

                Content = new TileBindingContentAdaptive()
            };

            ComboBox comboBox = new ComboBox();
            //var tileContent = NotificationsExtensions.GenerateTileContent();
            //TileNotification notif = new TileNotification(null);
            //ITileSquareText01 tileContent = TileContentFactory.CreateTileSquareText01();
        }
        public void TestWeatherTile()
        {
            TileImageSource backgroundImage = new TileImageSource(BACKGROUND_IMAGE_MOSTLY_CLOUDY);
            int overlay = 30;

            TileBindingContentAdaptive smallContent = new TileBindingContentAdaptive()
            {
                TextStacking = TileTextStacking.Center,
                BackgroundImage = new TileBackgroundImage() { Source = backgroundImage, Overlay = overlay },
                Children =
                {
                    new TileText()
                    {
                        Text = "Mon",
                        Style = TileTextStyle.Body,
                        Align = TileTextAlign.Center
                    },

                    new TileText()
                    {
                        Text = "63°",
                        Style = TileTextStyle.Base,
                        Align = TileTextAlign.Center
                    }
                }
            };


            TileBindingContentAdaptive mediumContent = new TileBindingContentAdaptive()
            {
                BackgroundImage = new TileBackgroundImage() { Source = backgroundImage, Overlay = overlay },
                Children =
                {
                    new TileGroup()
                    {
                        Children =
                        {
                            GenerateMediumSubgroup("Mon", IMAGE_MOSTLY_CLOUDY, 63, 42),

                            GenerateMediumSubgroup("Tue", IMAGE_CLOUDY, 57, 38)
                        }
                    }
                }
            };



            TileBindingContentAdaptive wideContent = new TileBindingContentAdaptive()
            {
                BackgroundImage = new TileBackgroundImage() { Source = backgroundImage, Overlay = overlay },
                Children =
                {
                    new TileGroup()
                    {
                        Children =
                        {
                            GenerateWideSubgroup("Mon", IMAGE_MOSTLY_CLOUDY, 63, 42),

                            GenerateWideSubgroup("Tue", IMAGE_CLOUDY, 57, 38),

                            GenerateWideSubgroup("Wed", IMAGE_SUNNY, 59, 43),

                            GenerateWideSubgroup("Thu", IMAGE_SUNNY, 62, 42),

                            GenerateWideSubgroup("Fri", IMAGE_SUNNY, 71, 66)
                        }
                    }
                }
            };




            TileBindingContentAdaptive largeContent = new TileBindingContentAdaptive()
            {
                BackgroundImage = new TileBackgroundImage() { Source = backgroundImage, Overlay = overlay },
                Children =
                {
                    new TileGroup()
                    {
                        Children =
                        {
                            new TileSubgroup()
                            {
                                Weight = 30,
                                Children =
                                {
                                    new TileImage() { Source = new TileImageSource(IMAGE_MOSTLY_CLOUDY) }
                                }
                            },

                            new TileSubgroup()
                            {
                                Children =
                                {
                                    new TileText()
                                    {
                                        Text = "Monday",
                                        Style = TileTextStyle.Base
                                    },

                                    new TileText()
                                    {
                                        Text = "63° / 42°"
                                    },

                                    new TileText()
                                    {
                                        Text = "20% chance of rain",
                                        Style = TileTextStyle.CaptionSubtle
                                    },

                                    new TileText()
                                    {
                                        Text = "Winds 5 mph NE",
                                        Style = TileTextStyle.CaptionSubtle
                                    }
                                }
                            }
                        }
                    },

                    // For spacing
                    new TileText(),

                    new TileGroup()
                    {
                        Children =
                        {
                            GenerateLargeSubgroup("Tue", IMAGE_CLOUDY, 57, 38),

                            GenerateLargeSubgroup("Wed", IMAGE_SUNNY, 59, 43),

                            GenerateLargeSubgroup("Thu", IMAGE_SUNNY, 62, 42),

                            GenerateLargeSubgroup("Fri", IMAGE_SUNNY, 71, 66)
                        }
                    }
                }
            };




            TileContent content = new TileContent()
            {
                Visual = new TileVisual()
                {
                    DisplayName = "Seattle",

                    TileSmall = new TileBinding()
                    {
                        Content = smallContent
                    },

                    TileMedium = new TileBinding()
                    {
                        Content = mediumContent,
                        Branding = TileBranding.Name
                    },

                    TileWide = new TileBinding()
                    {
                        Content = wideContent,
                        Branding = TileBranding.NameAndLogo
                    },

                    TileLarge = new TileBinding()
                    {
                        Content = largeContent,
                        Branding = TileBranding.NameAndLogo
                    }
                }
            };



            string expectedPayload = $@"<?xml version=""1.0"" encoding=""utf-8""?><tile><visual displayName=""Seattle""><binding template=""TileSmall"" hint-overlay=""30"" hint-textStacking=""center"">{GenerateStringBackgroundImage()}<text hint-align=""center"" hint-style=""body"">Mon</text><text hint-align=""center"" hint-style=""base"">63°</text></binding><binding template=""TileMedium"" branding=""name"" hint-overlay=""30"">{GenerateStringBackgroundImage()}<group>";

            // Medium tile subgroups
            expectedPayload += GenerateStringMediumSubgroup("Mon", IMAGE_MOSTLY_CLOUDY, 63, 42);
            expectedPayload += GenerateStringMediumSubgroup("Tue", IMAGE_CLOUDY, 57, 38);

            expectedPayload += "</group></binding>";


            // Wide tile
            expectedPayload += @"<binding template=""TileWide"" branding=""nameAndLogo"" hint-overlay=""30"">";
            expectedPayload += GenerateStringBackgroundImage();
            expectedPayload += "<group>";

            // Wide tile subgroups
            expectedPayload += GenerateStringWideSubgroup("Mon", IMAGE_MOSTLY_CLOUDY, 63, 42);
            expectedPayload += GenerateStringWideSubgroup("Tue", IMAGE_CLOUDY, 57, 38);
            expectedPayload += GenerateStringWideSubgroup("Wed", IMAGE_SUNNY, 59, 43);
            expectedPayload += GenerateStringWideSubgroup("Thu", IMAGE_SUNNY, 62, 42);
            expectedPayload += GenerateStringWideSubgroup("Fri", IMAGE_SUNNY, 71, 66);

            expectedPayload += "</group></binding>";



            // Large tile
            expectedPayload += @"<binding template=""TileLarge"" branding=""nameAndLogo"" hint-overlay=""30"">";
            expectedPayload += GenerateStringBackgroundImage();
            expectedPayload += $@"<group><subgroup hint-weight=""30""><image src=""{IMAGE_MOSTLY_CLOUDY}"" /></subgroup><subgroup><text hint-style=""base"">Monday</text><text>63° / 42°</text><text hint-style=""captionSubtle"">20% chance of rain</text><text hint-style=""captionSubtle"">Winds 5 mph NE</text></subgroup></group>";

            expectedPayload += "<text />";
            expectedPayload += "<group>";

            // Large tile subgroups
            expectedPayload += GenerateStringLargeSubgroup("Tue", IMAGE_CLOUDY, 57, 38);
            expectedPayload += GenerateStringLargeSubgroup("Wed", IMAGE_SUNNY, 59, 43);
            expectedPayload += GenerateStringLargeSubgroup("Thu", IMAGE_SUNNY, 62, 42);
            expectedPayload += GenerateStringLargeSubgroup("Fri", IMAGE_SUNNY, 71, 66);

            expectedPayload += "</group></binding></visual></tile>";


            string actualPayload = content.GetContent();

            AssertHelper.AssertXml(expectedPayload, actualPayload);
            //Assert.AreEqual(expectedPayload, actualPayload);
        }
        public void TestMailTile()
        {
            TileBinding small = new TileBinding()
            {
                Content = new TileBindingContentIconic()
                {
                    Icon = new TileImageSource("Assets\\Mail.png")
                }
            };

            TileBinding medium = new TileBinding()
            {
                Branding = TileBranding.Logo,

                Content = new TileBindingContentAdaptive()
                {
                    Children =
                    {
                        GenerateFirstMessage(false),
                        GenerateSpacer(),
                        GenerateSecondMessage(false)
                    }
                }
            };

            TileBinding wideAndLarge = new TileBinding()
            {
                Branding = TileBranding.NameAndLogo,

                Content = new TileBindingContentAdaptive()
                {
                    Children =
                    {
                        GenerateFirstMessage(true),
                        GenerateSpacer(),
                        GenerateSecondMessage(true)
                    }
                }
            };

            TileContent content = new TileContent()
            {
                Visual = new TileVisual()
                {
                    TileSmall = small,
                    TileMedium = medium,
                    TileWide = wideAndLarge,
                    TileLarge = wideAndLarge
                }
            };

            string expectedXml = $@"<?xml version=""1.0"" encoding=""utf-8""?><tile><visual><binding template=""TileSquare71x71IconWithBadge""><image id=""1"" src=""Assets\Mail.png"" /></binding>";

            // Medium
            expectedXml += @"<binding template=""TileMedium"" branding=""logo"">";
            expectedXml += GenerateXmlGroups(false);
            expectedXml += "</binding>";

            // Wide
            expectedXml += @"<binding template=""TileWide"" branding=""nameAndLogo"">";
            expectedXml += GenerateXmlGroups(true);
            expectedXml += "</binding>";

            // Large
            expectedXml += @"<binding template=""TileLarge"" branding=""nameAndLogo"">";
            expectedXml += GenerateXmlGroups(true);
            expectedXml += "</binding>";

            expectedXml += "</visual></tile>";

            string actualXml = content.GetContent();

            AssertHelper.AssertXml(expectedXml, actualXml);
            //Assert.AreEqual(expectedXml, actualXml);
        }
        public void TestXboxModernTile()
        {
            TileBinding medium = new TileBinding()
            {
                Content = new TileBindingContentAdaptive()
                {
                    TextStacking = TileTextStacking.Center,

                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text = "Hi,",
                            HintStyle = AdaptiveTextStyle.Base,
                            HintAlign = AdaptiveTextAlign.Center
                        },

                        new AdaptiveText()
                        {
                            Text = "MasterHip",
                            HintStyle = AdaptiveTextStyle.CaptionSubtle,
                            HintAlign = AdaptiveTextAlign.Center
                        }
                    }
                }
            };

            TileBinding wide = new TileBinding()
            {
                Content = new TileBindingContentAdaptive()
                {
                    Children =
                    {
                        new AdaptiveGroup()
                        {
                            Children =
                            {
                                new AdaptiveSubgroup()
                                {
                                    HintWeight = 33,
                                    Children =
                                    {
                                        new AdaptiveImage()
                                        {
                                            Source = "http://xbox.com/MasterHip/profile.jpg",
                                            HintCrop = AdaptiveImageCrop.Circle
                                        }
                                    }
                                },

                                new AdaptiveSubgroup()
                                {
                                    HintTextStacking = AdaptiveSubgroupTextStacking.Center,
                                    Children =
                                    {
                                        new AdaptiveText()
                                        {
                                            Text = "Hi,",
                                            HintStyle = AdaptiveTextStyle.Title
                                        },

                                        new AdaptiveText()
                                        {
                                            Text = "MasterHip",
                                            HintStyle = AdaptiveTextStyle.SubtitleSubtle
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            TileBinding large = new TileBinding()
            {
                Content = new TileBindingContentAdaptive()
                {
                    TextStacking = TileTextStacking.Center,
                    Children =
                    {
                        new AdaptiveGroup()
                        {
                            Children =
                            {
                                new AdaptiveSubgroup() { HintWeight = 1 },
                                new AdaptiveSubgroup()
                                {
                                    HintWeight = 2,
                                    Children =
                                    {
                                        new AdaptiveImage()
                                        {
                                            Source = "http://xbox.com/MasterHip/profile.jpg",
                                            HintCrop = AdaptiveImageCrop.Circle
                                        }
                                    }
                                },
                                new AdaptiveSubgroup() { HintWeight = 1 }
                            }
                        },

                        new AdaptiveText()
                        {
                            Text = "Hi,",
                            HintStyle = AdaptiveTextStyle.Title,
                            HintAlign = AdaptiveTextAlign.Center
                        },

                        new AdaptiveText()
                        {
                            Text = "MasterHip",
                            HintStyle = AdaptiveTextStyle.SubtitleSubtle,
                            HintAlign = AdaptiveTextAlign.Center
                        }
                    }
                }
            };

            TileContent content = new TileContent()
            {
                Visual = new TileVisual()
                {
                    Branding = TileBranding.NameAndLogo,

                    TileMedium = medium,
                    TileWide = wide,
                    TileLarge = large
                }
            };

            string expectedXml = $@"<?xml version=""1.0"" encoding=""utf-8""?><tile><visual branding=""nameAndLogo"">";

            // Medium
            expectedXml += @"<binding template=""TileMedium"" hint-textStacking=""center""><text hint-align=""center"" hint-style=""base"">Hi,</text><text hint-align=""center"" hint-style=""captionSubtle"">MasterHip</text></binding>";

            // Wide
            expectedXml += @"<binding template=""TileWide""><group><subgroup hint-weight=""33""><image src=""http://xbox.com/MasterHip/profile.jpg"" hint-crop=""circle"" /></subgroup><subgroup hint-textStacking=""center""><text hint-style=""title"">Hi,</text><text hint-style=""subtitleSubtle"">MasterHip</text></subgroup></group></binding>";

            // Large
            expectedXml += @"<binding template=""TileLarge"" hint-textStacking=""center""><group><subgroup hint-weight=""1"" /><subgroup hint-weight=""2""><image src=""http://xbox.com/MasterHip/profile.jpg"" hint-crop=""circle"" /></subgroup><subgroup hint-weight=""1"" /></group><text hint-align=""center"" hint-style=""title"">Hi,</text><text hint-align=""center"" hint-style=""subtitleSubtle"">MasterHip</text></binding>";

            expectedXml += "</visual></tile>";

            string actualXml = content.GetContent();

            AssertHelper.AssertXml(expectedXml, actualXml);
            //Assert.AreEqual(expectedXml, actualXml);
        }
 private static void AssertPayload(string expectedXml, TileContent tile)
 {
     AssertHelper.AssertXml(expectedXml, tile.GetContent());
 }
        public void Test_Tile_Xml_Adaptive_PeekImage_NoImageSource()
        {
            try
            {
                TileContent c = new TileContent()
                {
                    Visual = new TileVisual()
                    {
                        TileMedium = new TileBinding()
                        {
                            Content = new TileBindingContentAdaptive()
                            {
                                PeekImage = new TilePeekImage()
                                {
                                    // No source, which should throw exception when content retrieved
                                }
                            }
                        }
                    }
                };

                c.GetContent();
            }

            catch (NullReferenceException)
            {
                return;
            }

            Assert.Fail("Exception should have been thrown");
        }
        private static void AssertAdaptiveChildInTile(string expectedAdaptiveChildXml, IAdaptiveChild child)
        {
            var content = new TileContent()
            {
                Visual = new TileVisual()
                {
                    TileMedium = new TileBinding()
                    {
                        Content = new TileBindingContentAdaptive()
                        {
                            Children =
                            {
                                child
                            }
                        }
                    }
                }
            };

            AssertHelper.AssertXml(
                "<tile><visual><binding template='TileMedium'>" + expectedAdaptiveChildXml + "</binding></visual></tile>",
                content.GetContent());
        }
        /// <summary>
        /// Generates tile notification of gold notification using the receiver's picture
        /// </summary>
        /// <param name="thumbnailUrl">Image that received gold.</param>
        /// <returns>String representation of tile object.</returns>
        private string GenerateTileNotification(string thumbnailUrl)
        {
            var content = new TileContent()
            {
                Visual = new TileVisual()
                {
                    TileSmall = new TileBinding()
                    {
                        Content = new TileBindingContentAdaptive()
                        {
                            BackgroundImage = new TileBackgroundImage()
                            {
                                Source = thumbnailUrl
                            }
                        }
                    },

                    TileMedium = new TileBinding()
                    {
                        Content = new TileBindingContentAdaptive()
                        {
                            BackgroundImage = new TileBackgroundImage()
                            {
                                Source = thumbnailUrl
                            }
                        }
                    },

                    TileLarge = new TileBinding()
                    {
                        Content = new TileBindingContentAdaptive()
                        {
                            BackgroundImage = new TileBackgroundImage()
                            {
                                Source = thumbnailUrl
                            }
                        }
                    },

                    TileWide = new TileBinding()
                    {
                        Content = new TileBindingContentAdaptive()
                        {
                            BackgroundImage = new TileBackgroundImage
                            {
                                Source = thumbnailUrl
                            }
                        }
                    }
                }
            };

            return content.GetContent();
        }