Пример #1
0
        private void EndUpdate(string serverData)
        {
            LiveTileData data = ParseXML(serverData);

            UpdateTile(data);

            ExecuteCallback();
        }
Пример #2
0
        private LiveTileData ParseXML(string input)
        {
            if (!String.IsNullOrWhiteSpace(input))
            {
                XDocument doc = XDocument.Parse(input);

                if (doc != null)
                {
                    XElement root = doc.Element("LiveTile");

                    if (root != null)
                    {
                        LiveTileData res = new LiveTileData();

                        // tile title
                        XElement title = root.Element("Title");

                        if (title != null)
                        {
                            res.Title = title.Value;
                        }

                        // tile background
                        XElement image = root.Element("Image");

                        if (image != null)
                        {
                            res.Image = image.Value;
                        }

                        // tile count
                        XElement count = root.Element("Count");

                        if (count != null)
                        {
                            res.Count = count.Value;
                        }

                        // tile back title
                        XElement backTitle = root.Element("BackTitle");

                        if (backTitle != null)
                        {
                            res.BackTitle = backTitle.Value;
                        }

                        // tile back background
                        XElement backImage = root.Element("BackImage");

                        if (backImage != null)
                        {
                            res.BackImage = backImage.Value;
                        }

                        // tile back text
                        XElement backText = root.Element("BackText");

                        if (backText != null)
                        {
                            res.BackText = backText.Value;
                        }

                        return(res);
                    }
                }
            }

            return(null);
        }
Пример #3
0
        private void UpdateTile(LiveTileData data)
        {
            if (data != null)
            {
                ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault();

                if (tile != null)
                {
                    StandardTileData updatedTileData = new StandardTileData();

                    updatedTileData.Title = data.Title;

                    if (!String.IsNullOrWhiteSpace(data.Count))
                    {
                        int count = 0;

                        Int32.TryParse(data.Count, out count);

                        updatedTileData.Count = count;
                    }
                    else
                    {
                        updatedTileData.Count = 0;
                    }

                    if (!String.IsNullOrWhiteSpace(data.Image))
                    {
                        if (data.Image.StartsWith("http://"))
                        {
                            updatedTileData.BackgroundImage = new Uri(data.Image);
                        }
                        else
                        {
                            updatedTileData.BackgroundImage = new Uri(String.Format(BackgroundFormat, data.Image));
                        }
                    }
                    else
                    {
                        updatedTileData.BackgroundImage = null;
                    }

                    updatedTileData.BackTitle = data.BackTitle;

                    if (!String.IsNullOrWhiteSpace(data.BackImage))
                    {
                        if (data.BackImage.StartsWith("http://"))
                        {
                            updatedTileData.BackBackgroundImage = new Uri(data.BackImage);
                        }
                        else
                        {
                            updatedTileData.BackBackgroundImage = new Uri(String.Format(BackgroundFormat, data.BackImage));
                        }
                    }
                    else
                    {
                        updatedTileData.BackBackgroundImage = null;
                    }

                    updatedTileData.BackContent = data.BackText;

                    tile.Update(updatedTileData);
                }
            }
        }