/// <summary> /// Copies any parse errors to the channel. /// </summary> /// <param name="channel">The channel being created by this parser.</param> private void SaveParseErrors(PodcastChannel channel) { foreach (string error in ParseErrors) { channel.ParseErrors.Add(error); } }
public static async Task <PodcastChannel> FromPodcastUrl(string url, bool showUnparsedContent) { WebRequest request = WebRequest.Create(url); WebResponse response = request.GetResponse(); Stream s = response.GetResponseStream(); var reader = new StreamReader(s); string xml = await reader.ReadToEndAsync(); reader.Close(); var parser = new PodcastChannelParser(xml); parser.RemoveParsedContent = showUnparsedContent; PodcastChannel channel = await Task.Run(() => parser.Parse()); channel.PodcastXml = xml; return(channel); }
/// <summary> /// Initializes a new instance of the <see cref="PodcastChannelParser"/> class. /// </summary> /// <param name="rssData">The RSS XML document to parse.</param> public PodcastChannelParser(string rssData) : base(rssData) { _channel = new PodcastChannel(); using (var stringWriter = new StringWriter(new StringBuilder(), CultureInfo.InvariantCulture)) { var xmlTextWriter = new XmlTextWriter(stringWriter) { Formatting = Formatting.Indented }; XmlDocument xDoc = new XmlDocument(); using (var r = new StringReader(rssData)) { xDoc.Load(r); xDoc.Save(xmlTextWriter); _channel.PrettyRssData = stringWriter.ToString(); } } }
/// <summary> /// Updates the channel with any new episodes which have been published. /// </summary> /// <returns>Nothing - it's a <see cref="Task"/>.</returns> public async Task UpdateChannel() { PodcastChannel latestChannel = await FromPodcastUrl(RssUrl, false); var episodeGuids = new Collection <string>(); // Get the guids of the episodes we already know about foreach (PodcastEpisode episode in Episodes) { episodeGuids.Add(episode.Guid); } // Add any published episodes that we don't already know about foreach (PodcastEpisode episode in latestChannel.Episodes) { if (!episodeGuids.Contains(episode.Guid)) { Episodes.Add(episode); } } // FIXME: user needs to switch to another channel and back to see the new episodes // TODO: consider updating other channel metadata if different to local copy }