/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Atom <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 FillAtomResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); AtomFeed atomFeed = resource as AtomFeed; AtomEntry atomEntry = resource as AtomEntry; if (resourceMetadata.Version == new Version("1.0")) { Atom10SyndicationResourceAdapter atom10Adapter = new Atom10SyndicationResourceAdapter(this.Navigator, this.Settings); if (atomFeed != null) { atom10Adapter.Fill(atomFeed); } else if (atomEntry != null) { atom10Adapter.Fill(atomEntry); } } if (resourceMetadata.Version == new Version("0.3")) { Atom03SyndicationResourceAdapter atom03Adapter = new Atom03SyndicationResourceAdapter(this.Navigator, this.Settings); if (atomFeed != null) { atom03Adapter.Fill(atomFeed); } else if (atomEntry != null) { atom03Adapter.Fill(atomEntry); } } }
/// <summary> /// Modifies the <see cref="AtomFeed"/> to match the data source. /// </summary> /// <param name="resource">The <see cref="AtomFeed"/> to be filled.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> public void Fill(AtomFeed resource) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); //------------------------------------------------------------ // Create namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(this.Navigator.NameTable); //------------------------------------------------------------ // Attempt to fill syndication resource //------------------------------------------------------------ XPathNavigator feedNavigator = this.Navigator.SelectSingleNode("atom:feed", manager); if (feedNavigator != null) { AtomUtility.FillCommonObjectAttributes(resource, feedNavigator); XPathNavigator idNavigator = feedNavigator.SelectSingleNode("atom:id", manager); XPathNavigator titleNavigator = feedNavigator.SelectSingleNode("atom:title", manager); XPathNavigator updatedNavigator = feedNavigator.SelectSingleNode("atom:updated", manager); if (idNavigator != null) { resource.Id = new AtomId(); resource.Id.Load(idNavigator, this.Settings); } if (titleNavigator != null) { resource.Title = new AtomTextConstruct(); resource.Title.Load(titleNavigator, this.Settings); } if (updatedNavigator != null) { DateTime updatedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedNavigator.Value, out updatedOn)) { resource.UpdatedOn = updatedOn; } } Atom10SyndicationResourceAdapter.FillFeedOptionals(resource, feedNavigator, manager, this.Settings); Atom10SyndicationResourceAdapter.FillFeedCollections(resource, feedNavigator, manager, this.Settings); SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(feedNavigator, this.Settings); adapter.Fill(resource, manager); } }
/// <summary> /// Modifies the <see cref="AtomEntry"/> to match the data source. /// </summary> /// <param name="resource">The <see cref="AtomEntry"/> to be filled.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> public void Fill(AtomEntry resource) { Guard.ArgumentNotNull(resource, "resource"); XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(this.Navigator.NameTable); XPathNavigator entryNavigator = this.Navigator.SelectSingleNode("atom:entry", manager); if (entryNavigator != null) { Atom10SyndicationResourceAdapter.FillEntry(resource, entryNavigator, manager, this.Settings); } }
//============================================================ // PRIVATE METHODS //============================================================ #region FillEntry(AtomEntry entry, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) /// <summary> /// Modifies the <see cref="AtomEntry"/> to match the supplied <see cref="XPathNavigator"/> data source. /// </summary> /// <param name="entry">The <see cref="AtomEntry"/> to be filled.</param> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomEntry"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillEntry(AtomEntry entry, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(entry, "entry"); Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to fill syndication resource //------------------------------------------------------------ AtomUtility.FillCommonObjectAttributes(entry, source); XPathNavigator idNavigator = source.SelectSingleNode("atom:id", manager); XPathNavigator titleNavigator = source.SelectSingleNode("atom:title", manager); XPathNavigator updatedNavigator = source.SelectSingleNode("atom:updated", manager); if (idNavigator != null) { entry.Id = new AtomId(); entry.Id.Load(idNavigator, settings); } if (titleNavigator != null) { entry.Title = new AtomTextConstruct(); entry.Title.Load(titleNavigator, settings); } if (updatedNavigator != null) { DateTime updatedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedNavigator.Value, out updatedOn)) { entry.UpdatedOn = updatedOn; } } Atom10SyndicationResourceAdapter.FillEntryOptionals(entry, source, manager, settings); Atom10SyndicationResourceAdapter.FillEntryCollections(entry, source, manager, settings); SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings); adapter.Fill(entry, manager); }
//============================================================ // PUBLIC METHODS //============================================================ #region Fill(AtomEntry resource) /// <summary> /// Modifies the <see cref="AtomEntry"/> to match the data source. /// </summary> /// <param name="resource">The <see cref="AtomEntry"/> to be filled.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> public void Fill(AtomEntry resource) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); //------------------------------------------------------------ // Create namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(this.Navigator.NameTable); //------------------------------------------------------------ // Attempt to fill syndication resource //------------------------------------------------------------ XPathNavigator entryNavigator = this.Navigator.SelectSingleNode("atom:entry", manager); if (entryNavigator != null) { Atom10SyndicationResourceAdapter.FillEntry(resource, entryNavigator, manager, this.Settings); } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Atom <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 FillAtomResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ AtomFeed atomFeed = resource as AtomFeed; AtomEntry atomEntry = resource as AtomEntry; if (resourceMetadata.Version == new Version("1.0")) { Atom10SyndicationResourceAdapter atom10Adapter = new Atom10SyndicationResourceAdapter(this.Navigator, this.Settings); if (atomFeed != null) { atom10Adapter.Fill(atomFeed); } else if (atomEntry != null) { atom10Adapter.Fill(atomEntry); } } if (resourceMetadata.Version == new Version("0.3")) { Atom03SyndicationResourceAdapter atom03Adapter = new Atom03SyndicationResourceAdapter(this.Navigator, this.Settings); if (atomFeed != null) { atom03Adapter.Fill(atomFeed); } else if (atomEntry != null) { atom03Adapter.Fill(atomEntry); } } }
/// <summary> /// Modifies the <see cref="AtomFeed"/> collection entities to match the supplied <see cref="XPathNavigator"/> data source. /// </summary> /// <param name="feed">The <see cref="AtomFeed"/> to be filled.</param> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomFeed"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="feed"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillFeedCollections(AtomFeed feed, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { Guard.ArgumentNotNull(feed, "feed"); Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); XPathNodeIterator authorIterator = source.Select("atom:author", manager); XPathNodeIterator categoryIterator = source.Select("atom:category", manager); XPathNodeIterator contributorIterator = source.Select("atom:contributor", manager); XPathNodeIterator linkIterator = source.Select("atom:link", manager); XPathNodeIterator entryIterator = source.Select("atom:entry", manager); if (authorIterator != null && authorIterator.Count > 0) { while (authorIterator.MoveNext()) { AtomPersonConstruct author = new AtomPersonConstruct(); if (author.Load(authorIterator.Current, settings)) { feed.Authors.Add(author); } } } if (categoryIterator != null && categoryIterator.Count > 0) { while (categoryIterator.MoveNext()) { AtomCategory category = new AtomCategory(); if (category.Load(categoryIterator.Current, settings)) { feed.Categories.Add(category); } } } if (contributorIterator != null && contributorIterator.Count > 0) { while (contributorIterator.MoveNext()) { AtomPersonConstruct contributor = new AtomPersonConstruct(); if (contributor.Load(contributorIterator.Current, settings)) { feed.Contributors.Add(contributor); } } } if (entryIterator != null && entryIterator.Count > 0) { int counter = 0; while (entryIterator.MoveNext()) { AtomEntry entry = new AtomEntry(); counter++; Atom10SyndicationResourceAdapter.FillEntry(entry, entryIterator.Current, manager, settings); if (settings.RetrievalLimit != 0 && counter > settings.RetrievalLimit) { break; } ((Collection <AtomEntry>)feed.Entries).Add(entry); } } if (linkIterator != null && linkIterator.Count > 0) { while (linkIterator.MoveNext()) { AtomLink link = new AtomLink(); if (link.Load(linkIterator.Current, settings)) { feed.Links.Add(link); } } } }