private void InsertIntoCollection(PodcastItemModel Item, ObservableCollection<PodcastItemModel> Collection) { foreach (PodcastItemModel i in Collection) { if (i.EnclosureUrl == Item.EnclosureUrl) { Collection.Remove(i); break; } } Collection.Insert(0, Item); }
void DownloadPodcastInformationCompleted(object sender, DownloadStringCompletedEventArgs e) { LoadEventArgs loadedEventArgs = new LoadEventArgs(); try { var doc = XDocument.Parse(e.Result); var xChannel = doc.Descendants("channel").First(); PodcastInformation.Title = getElementValue(xChannel, "title"); PodcastInformation.Description = getElementValue(xChannel, "description"); PodcastInformation.Copyright = getElementValue(xChannel, "copyright"); PodcastInformation.Rating = getElementValue(xChannel, "rating"); PodcastInformation.WebMaster = getElementValue(xChannel, "webMaster"); PodcastInformation.Link = getElementValue(xChannel, "link"); PodcastInformation.Language = getElementValue(xChannel, "language"); PodcastInformation.ManagingDirector = getElementValue(xChannel, "managingEditor"); PodcastInformation.ImageUrl = Coalesce(Settings.DefaulImage, getElementValue(xChannel, ITUNES + "image", "href")).ToString(); foreach (var item in xChannel.Descendants("item")) { PodcastItemModel pim = new PodcastItemModel() { Title = getElementValue(item, "title").Trim(), Link = getElementValue(item, "link"), Date = RssHelper.ParseRssDate(getElementValue(item, "pubDate")), Description = StripHtmlTags(getElementValue(item, "description")).Trim(), EnclosureUrl = getElementValue(item, "enclosure", "url"), SourceUrl = getElementValue(item, "link"), ImageUrl = Coalesce( ParseImageFromDescription(getElementValue(item, "description")), getElementValue(item, ITUNES + "image", "href"), PodcastInformation.ImageUrl, Settings.DefaulImage ).ToString(), }; // ensure that there is an enclosure. No enclosure == no podcast media :( if (pim.EnclosureUrl.Length == 0) { pim.EnclosureUrl = "no media available"; } // finally, add the item to the collection PodcastInformation.Items.Add(pim); } loadedEventArgs.IsLoaded = true; loadedEventArgs.Message = ""; } catch (Exception ex) { loadedEventArgs.IsLoaded = false; loadedEventArgs.Message = "unable to load data"; } finally { OnPodcastInfoLoaded(loadedEventArgs); } }