/// <summary> /// Modifies the <see cref="AtomEntry"/> optional entities 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 an Atom 0.3 element. /// </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> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillEntryOptionals(AtomEntry entry, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { Guard.ArgumentNotNull(entry, "entry"); Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); XPathNavigator contentNavigator = source.SelectSingleNode("atom:content", manager); XPathNavigator createdNavigator = source.SelectSingleNode("atom:created", manager); XPathNavigator summaryNavigator = source.SelectSingleNode("atom:summary", manager); if (contentNavigator != null) { entry.Content = Atom03SyndicationResourceAdapter.CreateContent(contentNavigator, manager, settings); } if (createdNavigator != null) { DateTime publishedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(createdNavigator.Value, out publishedOn)) { entry.PublishedOn = publishedOn; } } if (summaryNavigator != null) { entry.Summary = Atom03SyndicationResourceAdapter.CreateTextContent(summaryNavigator, manager, settings); } }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source, XmlNamespaceManager manager) /// <summary> /// Initializes the syndication extension context using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="AtomPublishingEditedSyndicationExtensionContext"/>.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> object used to resolve prefixed syndication extension elements and attributes.</param> /// <returns><b>true</b> if the <see cref="AtomPublishingEditedSyndicationExtensionContext"/> was able to be initialized using the supplied <paramref name="source"/>; otherwise <b>false</b>.</returns> /// <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> public bool Load(XPathNavigator source, XmlNamespaceManager manager) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); //------------------------------------------------------------ // Attempt to extract syndication extension information //------------------------------------------------------------ if (source.HasChildren) { XPathNavigator editedNavigator = source.SelectSingleNode("app:edited", manager); if (editedNavigator != null && !String.IsNullOrEmpty(editedNavigator.Value)) { DateTime editedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(editedNavigator.Value, out editedOn)) { this.EditedOn = editedOn; wasLoaded = true; } } } return(wasLoaded); }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source) /// <summary> /// Loads this <see cref="ApmlConcept"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="ApmlConcept"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="ApmlConcept"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ if (source.HasAttributes) { string keyAttribute = source.GetAttribute("key", String.Empty); string valueAttribute = source.GetAttribute("value", String.Empty); string fromAttribute = source.GetAttribute("from", String.Empty); string updatedAttribute = source.GetAttribute("updated", String.Empty); if (!String.IsNullOrEmpty(keyAttribute)) { this.Key = keyAttribute; wasLoaded = true; } if (!String.IsNullOrEmpty(valueAttribute)) { decimal value; if (Decimal.TryParse(valueAttribute, System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out value)) { if (value >= Decimal.MinusOne && value <= Decimal.One) { this.Value = value; wasLoaded = true; } } } if (!String.IsNullOrEmpty(fromAttribute)) { this.From = fromAttribute; wasLoaded = true; } if (!String.IsNullOrEmpty(updatedAttribute)) { DateTime updatedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedAttribute, out updatedOn)) { this.UpdatedOn = updatedOn; wasLoaded = true; } } } return(wasLoaded); }
/// <summary> /// Loads this <see cref="FeedSynchronizationSharingInformation"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="FeedSynchronizationSharingInformation"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="FeedSynchronizationSharingInformation"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); FeedSynchronizationSyndicationExtension extension = new FeedSynchronizationSyndicationExtension(); XmlNamespaceManager manager = extension.CreateNamespaceManager(source); if (source.HasAttributes) { string sinceAttribute = source.GetAttribute("since", String.Empty); string untilAttribute = source.GetAttribute("until", String.Empty); string expiresAttribute = source.GetAttribute("expires", String.Empty); if (!String.IsNullOrEmpty(sinceAttribute)) { this.Since = sinceAttribute; wasLoaded = true; } if (!String.IsNullOrEmpty(untilAttribute)) { this.Until = untilAttribute; wasLoaded = true; } if (!String.IsNullOrEmpty(expiresAttribute)) { DateTime expiresOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(expiresAttribute, out expiresOn)) { this.ExpiresOn = expiresOn; wasLoaded = true; } } } if (source.HasChildren) { XPathNodeIterator relatedIterator = source.Select("sx:related", manager); if (relatedIterator != null && relatedIterator.Count > 0) { while (relatedIterator.MoveNext()) { FeedSynchronizationRelatedInformation relation = new FeedSynchronizationRelatedInformation(); if (relation.Load(relatedIterator.Current)) { this.Relations.Add(relation); wasLoaded = true; } } } } return(wasLoaded); }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source, XmlNamespaceManager manager) /// <summary> /// Initializes the syndication extension context using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="SiteSummaryUpdateSyndicationExtensionContext"/>.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> object used to resolve prefixed syndication extension elements and attributes.</param> /// <returns><b>true</b> if the <see cref="SiteSummaryUpdateSyndicationExtensionContext"/> was able to be initialized using the supplied <paramref name="source"/>; otherwise <b>false</b>.</returns> /// <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> public bool Load(XPathNavigator source, XmlNamespaceManager manager) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); //------------------------------------------------------------ // Attempt to extract syndication extension information //------------------------------------------------------------ if (source.HasChildren) { XPathNavigator updatePeriodNavigator = source.SelectSingleNode("sy:updatePeriod", manager); XPathNavigator updateFrequencyNavigator = source.SelectSingleNode("sy:updateFrequency", manager); XPathNavigator updateBaseNavigator = source.SelectSingleNode("sy:updateBase", manager); if (updatePeriodNavigator != null && !String.IsNullOrEmpty(updatePeriodNavigator.Value)) { SiteSummaryUpdatePeriod period = SiteSummaryUpdateSyndicationExtension.PeriodByName(updatePeriodNavigator.Value); if (period != SiteSummaryUpdatePeriod.None) { this.Period = period; wasLoaded = true; } } if (updateFrequencyNavigator != null) { int frequency; if (Int32.TryParse(updateFrequencyNavigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out frequency)) { this.Frequency = frequency; wasLoaded = true; } } if (updateBaseNavigator != null) { DateTime updateBase; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updateBaseNavigator.Value, out updateBase)) { this.Base = updateBase; wasLoaded = true; } } } return(wasLoaded); }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source) /// <summary> /// Loads this <see cref="ApmlHead"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="ApmlHead"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="ApmlHead"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Initialize XML namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = ApmlUtility.CreateNamespaceManager(source.NameTable); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ XPathNavigator titleNavigator = source.SelectSingleNode("apml:Title", manager); XPathNavigator generatorNavigator = source.SelectSingleNode("apml:Generator", manager); XPathNavigator userEmailNavigator = source.SelectSingleNode("apml:UserEmail", manager); XPathNavigator dateCreatedNavigator = source.SelectSingleNode("apml:DateCreated", manager); if (titleNavigator != null) { this.Title = titleNavigator.Value; wasLoaded = true; } if (generatorNavigator != null) { this.Generator = generatorNavigator.Value; wasLoaded = true; } if (userEmailNavigator != null) { this.EmailAddress = userEmailNavigator.Value; wasLoaded = true; } if (dateCreatedNavigator != null) { DateTime createdOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(dateCreatedNavigator.Value, out createdOn)) { this.CreatedOn = createdOn; wasLoaded = true; } } return(wasLoaded); }
/// <summary> /// Loads this <see cref="AtomSource"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="AtomSource"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomSource"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(source.NameTable); if (AtomUtility.FillCommonObjectAttributes(this, source)) { wasLoaded = true; } XPathNavigator idNavigator = source.SelectSingleNode("atom:id", manager); XPathNavigator titleNavigator = source.SelectSingleNode("atom:title", manager); XPathNavigator updatedNavigator = source.SelectSingleNode("atom:updated", manager); if (idNavigator != null) { this.Id = new AtomId(); if (this.Id.Load(idNavigator)) { wasLoaded = true; } } if (titleNavigator != null) { this.Title = new AtomTextConstruct(); if (this.Title.Load(titleNavigator)) { wasLoaded = true; } } if (updatedNavigator != null) { DateTime updatedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedNavigator.Value, out updatedOn)) { this.UpdatedOn = updatedOn; wasLoaded = true; } } if (this.LoadOptionals(source, manager)) { wasLoaded = true; } if (this.LoadCollections(source, manager)) { wasLoaded = true; } return(wasLoaded); }
/// <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"/> optional entities 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> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillEntryOptionals(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 extract syndication information //------------------------------------------------------------ XPathNavigator contentNavigator = source.SelectSingleNode("atom:content", manager); XPathNavigator publishedNavigator = source.SelectSingleNode("atom:published", manager); XPathNavigator rightsNavigator = source.SelectSingleNode("atom:rights", manager); XPathNavigator sourceNavigator = source.SelectSingleNode("atom:source", manager); XPathNavigator summaryNavigator = source.SelectSingleNode("atom:summary", manager); if (contentNavigator != null) { entry.Content = new AtomContent(); entry.Content.Load(contentNavigator, settings); } if (publishedNavigator != null) { DateTime publishedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(publishedNavigator.Value, out publishedOn)) { entry.PublishedOn = publishedOn; } } if (rightsNavigator != null) { entry.Rights = new AtomTextConstruct(); entry.Rights.Load(rightsNavigator, settings); } if (sourceNavigator != null) { entry.Source = new AtomSource(); entry.Source.Load(sourceNavigator, settings); } if (summaryNavigator != null) { entry.Summary = new AtomTextConstruct(); entry.Summary.Load(summaryNavigator, settings); } }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source) /// <summary> /// Loads this <see cref="FeedSynchronizationHistory"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="FeedSynchronizationHistory"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="FeedSynchronizationHistory"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ if (source.HasAttributes) { string sequenceAttribute = source.GetAttribute("sequence", String.Empty); string whenAttribute = source.GetAttribute("when", String.Empty); string byAttribute = source.GetAttribute("by", String.Empty); if (!String.IsNullOrEmpty(sequenceAttribute)) { int sequence; if (Int32.TryParse(sequenceAttribute, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out sequence)) { this.Sequence = sequence; wasLoaded = true; } } if (!String.IsNullOrEmpty(whenAttribute)) { DateTime when; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(whenAttribute, out when)) { this.When = when; wasLoaded = true; } } if (!String.IsNullOrEmpty(byAttribute)) { this.By = byAttribute; wasLoaded = true; } } return(wasLoaded); }
//============================================================ // 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); }
/// <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) { Guard.ArgumentNotNull(resource, "resource"); XmlNamespaceManager manager = Atom03SyndicationResourceAdapter.CreateNamespaceManager(this.Navigator.NameTable); 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 modifiedNavigator = feedNavigator.SelectSingleNode("atom:modified", manager); if (idNavigator != null) { resource.Id = new AtomId(); resource.Id.Load(idNavigator, this.Settings); } if (titleNavigator != null) { resource.Title = Atom03SyndicationResourceAdapter.CreateTextContent(titleNavigator, manager, this.Settings); } if (modifiedNavigator != null) { DateTime updatedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(modifiedNavigator.Value, out updatedOn)) { resource.UpdatedOn = updatedOn; } } Atom03SyndicationResourceAdapter.FillFeedOptionals(resource, feedNavigator, manager, this.Settings); Atom03SyndicationResourceAdapter.FillFeedCollections(resource, feedNavigator, manager, this.Settings); SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(feedNavigator, this.Settings); adapter.Fill(resource, manager); } }
/// <summary> /// Loads this <see cref="ApmlHead"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="ApmlHead"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="ApmlHead"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); XmlNamespaceManager manager = ApmlUtility.CreateNamespaceManager(source.NameTable); XPathNavigator titleNavigator = source.SelectSingleNode("apml:Title", manager); XPathNavigator generatorNavigator = source.SelectSingleNode("apml:Generator", manager); XPathNavigator userEmailNavigator = source.SelectSingleNode("apml:UserEmail", manager); XPathNavigator dateCreatedNavigator = source.SelectSingleNode("apml:DateCreated", manager); if (titleNavigator != null) { this.Title = titleNavigator.Value; wasLoaded = true; } if (generatorNavigator != null) { this.Generator = generatorNavigator.Value; wasLoaded = true; } if (userEmailNavigator != null) { this.EmailAddress = userEmailNavigator.Value; wasLoaded = true; } if (dateCreatedNavigator != null) { DateTime createdOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(dateCreatedNavigator.Value, out createdOn)) { this.CreatedOn = createdOn; wasLoaded = true; } } return(wasLoaded); }
/// <summary> /// Initializes the syndication extension context using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="AtomPublishingEditedSyndicationExtensionContext"/>.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> object used to resolve prefixed syndication extension elements and attributes.</param> /// <returns><b>true</b> if the <see cref="AtomPublishingEditedSyndicationExtensionContext"/> was able to be initialized using the supplied <paramref name="source"/>; otherwise <b>false</b>.</returns> /// <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> public bool Load(XPathNavigator source, XmlNamespaceManager manager) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); if (source.HasChildren) { XPathNavigator editedNavigator = source.SelectSingleNode("app:edited", manager); if (editedNavigator != null && !String.IsNullOrEmpty(editedNavigator.Value)) { DateTime editedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(editedNavigator.Value, out editedOn)) { this.EditedOn = editedOn; wasLoaded = true; } } } return(wasLoaded); }
//============================================================ // PRIVATE METHODS //============================================================ #region LoadCommon(XPathNavigator source, XmlNamespaceManager manager) /// <summary> /// Initializes the syndication extension context common elements using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="DublinCoreElementSetSyndicationExtensionContext"/>.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> object used to resolve prefixed syndication extension elements and attributes.</param> /// <returns><b>true</b> if the <see cref="DublinCoreElementSetSyndicationExtensionContext"/> was able to be initialized using the supplied <paramref name="source"/>; otherwise <b>false</b>.</returns> /// <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 bool LoadCommon(XPathNavigator source, XmlNamespaceManager manager) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); //------------------------------------------------------------ // Attempt to extract syndication extension information //------------------------------------------------------------ XPathNavigator contributorNavigator = source.SelectSingleNode("dc:contributor", manager); XPathNavigator creatorNavigator = source.SelectSingleNode("dc:creator", manager); XPathNavigator dateNavigator = source.SelectSingleNode("dc:date", manager); XPathNavigator descriptionNavigator = source.SelectSingleNode("dc:description", manager); XPathNavigator languageNavigator = source.SelectSingleNode("dc:language", manager); XPathNavigator publisherNavigator = source.SelectSingleNode("dc:publisher", manager); XPathNavigator rightsNavigator = source.SelectSingleNode("dc:rights", manager); XPathNavigator titleNavigator = source.SelectSingleNode("dc:title", manager); if (contributorNavigator != null && !String.IsNullOrEmpty(contributorNavigator.Value)) { this.Contributor = contributorNavigator.Value; wasLoaded = true; } if (creatorNavigator != null && !String.IsNullOrEmpty(creatorNavigator.Value)) { this.Creator = creatorNavigator.Value; wasLoaded = true; } if (dateNavigator != null) { DateTime date; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(dateNavigator.Value, out date)) { this.Date = date; wasLoaded = true; } } if (descriptionNavigator != null && !String.IsNullOrEmpty(descriptionNavigator.Value)) { this.Description = descriptionNavigator.Value; wasLoaded = true; } if (languageNavigator != null && !String.IsNullOrEmpty(languageNavigator.Value)) { try { CultureInfo language = new CultureInfo(languageNavigator.Value); this.Language = language; wasLoaded = true; } catch (ArgumentException) { System.Diagnostics.Trace.TraceWarning("DublinCoreElementSetSyndicationExtensionContext unable to determine CultureInfo with a name of {0}.", languageNavigator.Value); } } if (publisherNavigator != null && !String.IsNullOrEmpty(publisherNavigator.Value)) { this.Publisher = publisherNavigator.Value; wasLoaded = true; } if (rightsNavigator != null && !String.IsNullOrEmpty(rightsNavigator.Value)) { this.Rights = rightsNavigator.Value; wasLoaded = true; } if (titleNavigator != null && !String.IsNullOrEmpty(titleNavigator.Value)) { this.Title = titleNavigator.Value; wasLoaded = true; } return(wasLoaded); }
/// <summary> /// Modifies the <see cref="IBlogMLCommonObject"/> to match the data source. /// </summary> /// <param name="target">The object that implements the <see cref="IBlogMLCommonObject"/> interface to be filled.</param> /// <param name="source">The <see cref="XPathNavigator"/> to extract BlogML common object information from.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param> /// <returns><b>true</b> if the <paramref name="target"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="target"/> 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="settings"/> is a null reference (Nothing in Visual Basic).</exception> public static bool FillCommonObject(IBlogMLCommonObject target, XPathNavigator source, SyndicationResourceLoadSettings settings) { bool wasLoaded = false; Guard.ArgumentNotNull(target, "target"); Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(settings, "settings"); XmlNamespaceManager manager = BlogMLUtility.CreateNamespaceManager(source.NameTable); if (source.HasAttributes) { string idAttribute = source.GetAttribute("id", String.Empty); string dateCreatedAttribute = source.GetAttribute("date-created", String.Empty); string dateModifiedAttribute = source.GetAttribute("date-modified", String.Empty); string approvedAttribute = source.GetAttribute("approved", String.Empty); if (!String.IsNullOrEmpty(idAttribute)) { target.Id = idAttribute; wasLoaded = true; } if (!String.IsNullOrEmpty(dateCreatedAttribute)) { DateTime createdOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(dateCreatedAttribute, out createdOn)) { target.CreatedOn = createdOn; wasLoaded = true; } else if (DateTime.TryParse(dateCreatedAttribute, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out createdOn)) { target.CreatedOn = createdOn; wasLoaded = true; } } if (!String.IsNullOrEmpty(dateModifiedAttribute)) { DateTime modifiedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(dateModifiedAttribute, out modifiedOn)) { target.LastModifiedOn = modifiedOn; wasLoaded = true; } else if (DateTime.TryParse(dateModifiedAttribute, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out modifiedOn)) { target.LastModifiedOn = modifiedOn; wasLoaded = true; } } if (!String.IsNullOrEmpty(approvedAttribute)) { BlogMLApprovalStatus status = BlogMLUtility.ApprovalStatusByValue(approvedAttribute); if (status != BlogMLApprovalStatus.None) { target.ApprovalStatus = status; wasLoaded = true; } } } if (source.HasChildren) { XPathNavigator titleNavigator = source.SelectSingleNode("blog:title", manager); if (titleNavigator != null) { BlogMLTextConstruct title = new BlogMLTextConstruct(); if (title.Load(titleNavigator, settings)) { target.Title = title; wasLoaded = true; } } } return(wasLoaded); }
/// <summary> /// Constructs a new <see cref="IXmlRpcValue"/> object from the specified <see cref="XPathNavigator"/>. /// Parameters specify the XML data source and the variable where the new <see cref="IXmlRpcValue"/> object is returned. /// </summary> /// <param name="source">A <see cref="XPathNavigator"/> that represents the XML data source to be parsed.</param> /// <param name="value"> /// When this method returns, contains an object that represents the <see cref="IXmlRpcValue"/> specified by the <paramref name="source"/>, or <b>null</b> if the conversion failed. /// This parameter is passed uninitialized. /// </param> /// <returns> /// <b>true</b> if <paramref name="source"/> was converted successfully; otherwise, <b>false</b>. /// This operation returns <b>false</b> if the <paramref name="source"/> parameter is a null reference (Nothing in Visual Basic), /// or represents XML data that is not in the expected format. /// </returns> /// <remarks> /// The <paramref name="source"/> is expected to represent an XML-RPC <b>value</b> node. /// </remarks> public static bool TryParseValue(XPathNavigator source, out IXmlRpcValue value) { if (source == null || String.Compare(source.Name, "value", StringComparison.OrdinalIgnoreCase) != 0) { value = null; return(false); } if (source.HasChildren) { XPathNavigator navigator = source.CreateNavigator(); if (navigator.MoveToFirstChild()) { if (String.Compare(navigator.Name, "i4", StringComparison.OrdinalIgnoreCase) == 0) { int scalar; if (Int32.TryParse(navigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out scalar)) { value = new XmlRpcScalarValue(scalar); return(true); } } else if (String.Compare(navigator.Name, "int", StringComparison.OrdinalIgnoreCase) == 0) { int scalar; if (Int32.TryParse(navigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out scalar)) { value = new XmlRpcScalarValue(scalar); return(true); } } else if (String.Compare(navigator.Name, "boolean", StringComparison.OrdinalIgnoreCase) == 0) { bool scalar; if (XmlRpcClient.TryParseBoolean(navigator.Value, out scalar)) { value = new XmlRpcScalarValue(scalar); return(true); } } else if (String.Compare(navigator.Name, "string", StringComparison.OrdinalIgnoreCase) == 0) { value = new XmlRpcScalarValue(navigator.Value); return(true); } else if (String.Compare(navigator.Name, "double", StringComparison.OrdinalIgnoreCase) == 0) { double scalar; if (Double.TryParse(navigator.Value, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out scalar)) { value = new XmlRpcScalarValue(scalar); return(true); } } else if (String.Compare(navigator.Name, "dateTime.iso8601", StringComparison.OrdinalIgnoreCase) == 0) { DateTime scalar; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(navigator.Value, out scalar)) { value = new XmlRpcScalarValue(scalar); return(true); } } else if (String.Compare(navigator.Name, "base64", StringComparison.OrdinalIgnoreCase) == 0) { if (!String.IsNullOrEmpty(navigator.Value)) { try { byte[] data = Convert.FromBase64String(navigator.Value); value = new XmlRpcScalarValue(data); return(true); } catch (FormatException) { value = null; return(false); } } } else if (String.Compare(navigator.Name, "struct", StringComparison.OrdinalIgnoreCase) == 0) { XmlRpcStructureValue structure = new XmlRpcStructureValue(); if (structure.Load(source)) { value = structure; return(true); } } else if (String.Compare(navigator.Name, "array", StringComparison.OrdinalIgnoreCase) == 0) { XmlRpcArrayValue array = new XmlRpcArrayValue(); if (array.Load(source)) { value = array; return(true); } } } } else if (!String.IsNullOrEmpty(source.Value)) { value = new XmlRpcScalarValue(source.Value); return(true); } value = null; return(false); }
//============================================================ // PUBLIC METHODS //============================================================ #region Fill(BlogMLDocument resource) /// <summary> /// Modifies the <see cref="BlogMLDocument"/> to match the data source. /// </summary> /// <param name="resource">The <see cref="BlogMLDocument"/> to be filled.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> public void Fill(BlogMLDocument resource) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); //------------------------------------------------------------ // Create namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = BlogMLUtility.CreateNamespaceManager(this.Navigator.NameTable); //------------------------------------------------------------ // Attempt to fill syndication resource //------------------------------------------------------------ XPathNavigator blogNavigator = this.Navigator.SelectSingleNode("blog:blog", manager); if (blogNavigator != null) { if (blogNavigator.HasAttributes) { string dateCreatedAttribute = blogNavigator.GetAttribute("date-created", String.Empty); string rootUrlAttribute = blogNavigator.GetAttribute("root-url", String.Empty); if (!String.IsNullOrEmpty(dateCreatedAttribute)) { DateTime createdOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(dateCreatedAttribute, out createdOn)) { resource.GeneratedOn = createdOn; } } if (!String.IsNullOrEmpty(rootUrlAttribute)) { Uri rootUrl; if (Uri.TryCreate(rootUrlAttribute, UriKind.RelativeOrAbsolute, out rootUrl)) { resource.RootUrl = rootUrl; } } } if (blogNavigator.HasChildren) { XPathNavigator titleNavigator = blogNavigator.SelectSingleNode("blog:title", manager); XPathNavigator subtitleNavigator = blogNavigator.SelectSingleNode("blog:sub-title", manager); if (titleNavigator != null) { BlogMLTextConstruct title = new BlogMLTextConstruct(); if (title.Load(titleNavigator)) { resource.Title = title; } } if (subtitleNavigator != null) { BlogMLTextConstruct subtitle = new BlogMLTextConstruct(); if (subtitle.Load(subtitleNavigator)) { resource.Subtitle = subtitle; } } BlogML20SyndicationResourceAdapter.FillDocumentCollections(resource, blogNavigator, manager, this.Settings); } SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(blogNavigator, this.Settings); adapter.Fill(resource, manager); } }
/// <summary> /// Loads this <see cref="ApmlSource"/> using the supplied <see cref="XPathNavigator"/> and <see cref="SyndicationResourceLoadSettings"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the load operation.</param> /// <returns><b>true</b> if the <see cref="ApmlSource"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="ApmlSource"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> 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> public bool Load(XPathNavigator source, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Initialize XML namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = ApmlUtility.CreateNamespaceManager(source.NameTable); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ if (source.HasAttributes) { string keyAttribute = source.GetAttribute("key", String.Empty); string nameAttribute = source.GetAttribute("name", String.Empty); string valueAttribute = source.GetAttribute("value", String.Empty); string typeAttribute = source.GetAttribute("type", String.Empty); string fromAttribute = source.GetAttribute("from", String.Empty); string updatedAttribute = source.GetAttribute("updated", String.Empty); if (!String.IsNullOrEmpty(keyAttribute)) { this.Key = keyAttribute; wasLoaded = true; } if (!String.IsNullOrEmpty(nameAttribute)) { this.Name = nameAttribute; wasLoaded = true; } if (!String.IsNullOrEmpty(valueAttribute)) { decimal value; if (Decimal.TryParse(valueAttribute, System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out value)) { if (value >= Decimal.MinusOne && value <= Decimal.One) { this.Value = value; wasLoaded = true; } } } if (!String.IsNullOrEmpty(typeAttribute)) { this.MimeType = typeAttribute; wasLoaded = true; } if (!String.IsNullOrEmpty(fromAttribute)) { this.From = fromAttribute; wasLoaded = true; } if (!String.IsNullOrEmpty(updatedAttribute)) { DateTime updatedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedAttribute, out updatedOn)) { this.UpdatedOn = updatedOn; wasLoaded = true; } } } if (source.HasChildren) { XPathNodeIterator authorIterator = source.Select("apml:Author", manager); if (authorIterator != null && authorIterator.Count > 0) { while (authorIterator.MoveNext()) { ApmlAuthor author = new ApmlAuthor(); if (author.Load(authorIterator.Current, settings)) { this.Authors.Add(author); wasLoaded = true; } } } } //------------------------------------------------------------ // Attempt to extract syndication extension information //------------------------------------------------------------ SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings); adapter.Fill(this); return(wasLoaded); }
/// <summary> /// Loads this <see cref="ApmlSource"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="ApmlSource"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="ApmlSource"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); XmlNamespaceManager manager = ApmlUtility.CreateNamespaceManager(source.NameTable); if (source.HasAttributes) { string keyAttribute = source.GetAttribute("key", String.Empty); string nameAttribute = source.GetAttribute("name", String.Empty); string valueAttribute = source.GetAttribute("value", String.Empty); string typeAttribute = source.GetAttribute("type", String.Empty); string fromAttribute = source.GetAttribute("from", String.Empty); string updatedAttribute = source.GetAttribute("updated", String.Empty); if (!String.IsNullOrEmpty(keyAttribute)) { this.Key = keyAttribute; wasLoaded = true; } if (!String.IsNullOrEmpty(nameAttribute)) { this.Name = nameAttribute; wasLoaded = true; } if (!String.IsNullOrEmpty(valueAttribute)) { decimal value; if (Decimal.TryParse(valueAttribute, System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out value)) { if (value >= Decimal.MinusOne && value <= Decimal.One) { this.Value = value; wasLoaded = true; } } } if (!String.IsNullOrEmpty(typeAttribute)) { this.MimeType = typeAttribute; wasLoaded = true; } if (!String.IsNullOrEmpty(fromAttribute)) { this.From = fromAttribute; wasLoaded = true; } if (!String.IsNullOrEmpty(updatedAttribute)) { DateTime updatedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedAttribute, out updatedOn)) { this.UpdatedOn = updatedOn; wasLoaded = true; } } } if (source.HasChildren) { XPathNodeIterator authorIterator = source.Select("apml:Author", manager); if (authorIterator != null && authorIterator.Count > 0) { while (authorIterator.MoveNext()) { ApmlAuthor author = new ApmlAuthor(); if (author.Load(authorIterator.Current)) { this.Authors.Add(author); wasLoaded = true; } } } } return(wasLoaded); }