private static void HandleBArtistDownload(object sender, DownloadStringCompletedEventArgs e, Badge badge) { try { XDocument xdoc = XDocument.Parse(e.Result); string name = xdoc.Root.Element("{http://www.w3.org/2005/Atom}title").Value; badge.Artist = name; } catch { badge.Artist = string.Empty; } ProfileViewModelLocator.ProfileModel.Badges.Add(badge); }
public static void ParseBadges(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 badge in elements) { Badge b = new Badge(); b.Type = badge.Element("{http://www.w3.org/2005/Atom}title").Value; string imageUrl = (from c in badge.Elements() where c.Name == "{http://www.w3.org/2005/Atom}link" && c.Attribute("rel").Value == "enclosure" select c).FirstOrDefault().Attribute("href").Value; b.Image = new BitmapImage(new Uri(imageUrl, UriKind.Absolute)); string artistID = badge.Element("{http://schemas.zune.net/profiles/2008/01}media") .Element("{http://schemas.zune.net/profiles/2008/01}id").Value; WebClient client = new WebClient(); client.DownloadStringAsync(new Uri("http://catalog.zune.net/v3.2/en-US/music/artist/" + artistID)); client.DownloadStringCompleted += (s, e) => HandleBArtistDownload(s, e, b); } }