/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Really Simple Syndication (RSS) <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillRssResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ RssFeed rssFeed = resource as RssFeed; if (resourceMetadata.Version == new Version("2.0")) { Rss20SyndicationResourceAdapter rss20Adapter = new Rss20SyndicationResourceAdapter(this.Navigator, this.Settings); rss20Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("1.0")) { Rss10SyndicationResourceAdapter rss10Adapter = new Rss10SyndicationResourceAdapter(this.Navigator, this.Settings); rss10Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("0.92")) { Rss092SyndicationResourceAdapter rss092Adapter = new Rss092SyndicationResourceAdapter(this.Navigator, this.Settings); rss092Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("0.91")) { Rss091SyndicationResourceAdapter rss091Adapter = new Rss091SyndicationResourceAdapter(this.Navigator, this.Settings); rss091Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("0.9")) { Rss090SyndicationResourceAdapter rss090Adapter = new Rss090SyndicationResourceAdapter(this.Navigator, this.Settings); rss090Adapter.Fill(rssFeed); } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Really Simple Syndication (RSS) <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillRssResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); RssFeed rssFeed = resource as RssFeed; if (resourceMetadata.Version == new Version("2.0")) { Rss20SyndicationResourceAdapter rss20Adapter = new Rss20SyndicationResourceAdapter(this.Navigator, this.Settings); rss20Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("1.0")) { Rss10SyndicationResourceAdapter rss10Adapter = new Rss10SyndicationResourceAdapter(this.Navigator, this.Settings); rss10Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("0.92")) { Rss092SyndicationResourceAdapter rss092Adapter = new Rss092SyndicationResourceAdapter(this.Navigator, this.Settings); rss092Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("0.91")) { Rss091SyndicationResourceAdapter rss091Adapter = new Rss091SyndicationResourceAdapter(this.Navigator, this.Settings); rss091Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("0.9")) { Rss090SyndicationResourceAdapter rss090Adapter = new Rss090SyndicationResourceAdapter(this.Navigator, this.Settings); rss090Adapter.Fill(rssFeed); } }
//============================================================ // PUBLIC METHODS //============================================================ #region Fill(RssFeed resource) /// <summary> /// Modifies the <see cref="RssFeed"/> to match the data source. /// </summary> /// <param name="resource">The <see cref="RssFeed"/> to be filled.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> public void Fill(RssFeed resource) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); //------------------------------------------------------------ // Create namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = new XmlNamespaceManager(this.Navigator.NameTable); manager.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); manager.AddNamespace("rss", "http://my.netscape.com/rdf/simple/0.9/"); //------------------------------------------------------------ // Attempt to fill syndication resource //------------------------------------------------------------ XPathNavigator channelNavigator = this.Navigator.SelectSingleNode("rdf:RDF/rss:channel", manager); if (channelNavigator != null) { Rss090SyndicationResourceAdapter.FillChannel(resource.Channel, channelNavigator, manager, this.Settings); } XPathNavigator imageNavigator = this.Navigator.SelectSingleNode("rdf:RDF/rss:image", manager); if (imageNavigator != null) { resource.Channel.Image = new RssImage(); Rss090SyndicationResourceAdapter.FillImage(resource.Channel.Image, imageNavigator, manager, this.Settings); } XPathNavigator textInputNavigator = this.Navigator.SelectSingleNode("rdf:RDF/rss:textinput", manager); if (textInputNavigator != null) { resource.Channel.TextInput = new RssTextInput(); Rss090SyndicationResourceAdapter.FillTextInput(resource.Channel.TextInput, textInputNavigator, manager, this.Settings); } XPathNodeIterator itemIterator = this.Navigator.Select("rdf:RDF/rss:item", manager); if (itemIterator != null && itemIterator.Count > 0) { int counter = 0; while (itemIterator.MoveNext()) { RssItem item = new RssItem(); counter++; if (this.Settings.RetrievalLimit != 0 && counter > this.Settings.RetrievalLimit) { break; } XPathNavigator titleNavigator = itemIterator.Current.SelectSingleNode("rss:title", manager); XPathNavigator linkNavigator = itemIterator.Current.SelectSingleNode("rss:link", manager); if (titleNavigator != null) { item.Title = titleNavigator.Value; } if (linkNavigator != null) { Uri link; if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link)) { item.Link = link; } } SyndicationExtensionAdapter itemExtensionAdapter = new SyndicationExtensionAdapter(itemIterator.Current, this.Settings); itemExtensionAdapter.Fill(item, manager); ((Collection <RssItem>)resource.Channel.Items).Add(item); } } SyndicationExtensionAdapter feedExtensionAdapter = new SyndicationExtensionAdapter(this.Navigator.SelectSingleNode("rdf:RDF", manager), this.Settings); feedExtensionAdapter.Fill(resource, manager); }