コード例 #1
0
ファイル: Parsers.cs プロジェクト: fstn/WindowsPhoneApps
        private static void HandleFDownload(object sender, DownloadStringCompletedEventArgs ev, Favorite fav)
        {
            try
            {
                XDocument xdoc = XDocument.Parse(ev.Result);
                string imageId = xdoc.Root.Element("{http://schemas.zune.net/catalog/music/2007/10}image")
                    .Element("{http://schemas.zune.net/catalog/music/2007/10}id").Value.Remove(0, 9);

                BitmapImage image = new BitmapImage(new Uri(string.Format("http://catalog.zune.net/v3.2/image/{0}?width=100&height=100", imageId)));
                fav.AlbumImage = image;
            }
            catch
            {
                fav.AlbumImage = new BitmapImage(new Uri("Images/unknown.png", UriKind.Relative));
            }

            ProfileViewModelLocator.ProfileModel.Favorites.Add(fav);
        }
コード例 #2
0
ファイル: Parsers.cs プロジェクト: fstn/WindowsPhoneApps
        public static void ParseFavorites(string xml)
        {
            XDocument doc = XDocument.Parse(xml);
            XElement[] elements = (from c in doc.Root.Elements() where c.Name == "{http://www.w3.org/2005/Atom}entry" select c).ToArray();

            foreach (XElement fav in elements)
            {
                XElement trackRoot = fav.Element("{http://schemas.zune.net/catalog/music/2007/10}track");
                Favorite favorite = new Favorite();
                favorite.Title = fav.Element("{http://www.w3.org/2005/Atom}title").Value;
                favorite.Length = trackRoot.Element("{http://schemas.zune.net/catalog/music/2007/10}length").Value.Remove(0, 2)
                    .Replace('H',':').Replace('M',':').Replace("S",string.Empty);
                favorite.IsExplicit = Convert.ToBoolean(trackRoot.Element("{http://schemas.zune.net/catalog/music/2007/10}isExplicit").Value);
                favorite.ArtistName = trackRoot.Element("{http://schemas.zune.net/catalog/music/2007/10}primaryArtist").
                    Element("{http://schemas.zune.net/catalog/music/2007/10}name").Value;
                favorite.ArtistID = trackRoot.Element("{http://schemas.zune.net/catalog/music/2007/10}primaryArtist").
                    Element("{http://schemas.zune.net/catalog/music/2007/10}id").Value.Remove(0,9);
                favorite.AlbumName = trackRoot.Element("{http://schemas.zune.net/catalog/music/2007/10}album").
                    Element("{http://schemas.zune.net/catalog/music/2007/10}title").Value;
                favorite.AlbumID = trackRoot.Element("{http://schemas.zune.net/catalog/music/2007/10}album").
                    Element("{http://schemas.zune.net/catalog/music/2007/10}id").Value.Remove(0,9);

                WebClient client = new WebClient();
                client.DownloadStringAsync(new Uri("http://catalog.zune.net/v3.2/en-US/music/artist/" + favorite.ArtistID));
                client.DownloadStringCompleted += (s, e) => HandleFArtistDownload(s, e, favorite);
            }
        }
コード例 #3
0
ファイル: Parsers.cs プロジェクト: fstn/WindowsPhoneApps
        private static void HandleFArtistDownload(object sender, DownloadStringCompletedEventArgs e, Favorite fav)
        {
            try
            {
                XDocument xdoc = XDocument.Parse(e.Result);
                string imageId = xdoc.Root.Element("{http://schemas.zune.net/catalog/music/2007/10}image")
                    .Element("{http://schemas.zune.net/catalog/music/2007/10}id").Value.Remove(0, 9);

                BitmapImage image = new BitmapImage(new Uri(string.Format("http://catalog.zune.net/v3.2/image/{0}?width=300&height=300", imageId)));

                fav.ArtistImage = image;

            }
            catch
            {
                fav.ArtistImage = new BitmapImage(new Uri("Images/unknown.png", UriKind.Relative));
            }

            WebClient client = new WebClient();
            client.DownloadStringAsync(new Uri("http://catalog.zune.net/v3.2/en-US/music/album/" + fav.AlbumID));
            client.DownloadStringCompleted += (s, ev) => HandleFDownload(s, ev, fav);

        }