/// <summary> /// Loads the collection elements of this <see cref="RssChannel"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the load operation.</param> /// <returns><b>true</b> if the <see cref="RssChannel"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// <para> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="RssChannel"/>. /// </para> /// <para> /// The number of <see cref="RssChannel.Items"/> that are loaded is limited based on the <see cref="SyndicationResourceLoadSettings.RetrievalLimit"/>. /// </para> /// </remarks> /// <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 bool LoadCollections(XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ XPathNodeIterator categoryIterator = source.Select("category", manager); XPathNodeIterator skipDaysIterator = source.Select("skipDays/day", manager); XPathNodeIterator skipHoursIterator = source.Select("skipHours/hour", manager); XPathNodeIterator itemIterator = source.Select("item", manager); if (categoryIterator != null && categoryIterator.Count > 0) { while (categoryIterator.MoveNext()) { RssCategory category = new RssCategory(); if (category.Load(categoryIterator.Current, settings)) { this.Categories.Add(category); wasLoaded = true; } } } if (skipDaysIterator != null && skipDaysIterator.Count > 0) { while (skipDaysIterator.MoveNext()) { if (!String.IsNullOrEmpty(skipDaysIterator.Current.Value)) { try { DayOfWeek day = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), skipDaysIterator.Current.Value, true); if (!this.SkipDays.Contains(day)) { this.SkipDays.Add(day); wasLoaded = true; } } catch (ArgumentException) { System.Diagnostics.Trace.TraceWarning("RssChannel unable to determine DayOfWeek with a name of {0}.", skipDaysIterator.Current.Value); } } } } if (skipHoursIterator != null && skipHoursIterator.Count > 0) { while (skipHoursIterator.MoveNext()) { int hour; if (Int32.TryParse(skipHoursIterator.Current.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out hour)) { if (!this.SkipHours.Contains(hour) && (hour >= 0 && hour <= 23)) { this.SkipHours.Add(hour); wasLoaded = true; } else { System.Diagnostics.Trace.TraceWarning("RssChannel unable to add duplicate or out-of-range skip hour with a value of {0}.", hour); } } } } if (itemIterator != null && itemIterator.Count > 0) { int counter = 0; while (itemIterator.MoveNext()) { RssItem item = new RssItem(); counter++; if (item.Load(itemIterator.Current, settings)) { if (settings.RetrievalLimit != 0 && counter > settings.RetrievalLimit) { break; } ((Collection<RssItem>)this.Items).Add(item); wasLoaded = true; } } } return wasLoaded; }
/// <summary> /// Loads this <see cref="RssItem"/> 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="RssItem"/> 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="RssItem"/>. /// </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 = new XmlNamespaceManager(source.NameTable); XPathNavigator authorNavigator = source.SelectSingleNode("author", manager); XPathNavigator commentsNavigator = source.SelectSingleNode("comments", manager); XPathNavigator descriptionNavigator = source.SelectSingleNode("description", manager); XPathNavigator guidNavigator = source.SelectSingleNode("guid", manager); XPathNavigator linkNavigator = source.SelectSingleNode("link", manager); XPathNavigator publicationNavigator = source.SelectSingleNode("pubDate", manager); XPathNavigator sourceNavigator = source.SelectSingleNode("source", manager); XPathNavigator titleNavigator = source.SelectSingleNode("title", manager); XPathNodeIterator categoryIterator = source.Select("category", manager); XPathNodeIterator enclosureIterator = source.Select("enclosure", manager); if (titleNavigator != null) { this.Title = titleNavigator.Value; wasLoaded = true; } if (descriptionNavigator != null) { this.Description = descriptionNavigator.Value; wasLoaded = true; } if (linkNavigator != null) { Uri link; if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link)) { this.Link = link; wasLoaded = true; } } if (authorNavigator != null) { this.Author = authorNavigator.Value; wasLoaded = true; } if (commentsNavigator != null) { Uri comments; if (Uri.TryCreate(commentsNavigator.Value, UriKind.RelativeOrAbsolute, out comments)) { this.Comments = comments; wasLoaded = true; } } if (guidNavigator != null) { RssGuid guid = new RssGuid(); if (guid.Load(guidNavigator)) { this.Guid = guid; wasLoaded = true; } } if (publicationNavigator != null) { DateTime publicationDate; if (SyndicationDateTimeUtility.TryParseRfc822DateTime(publicationNavigator.Value, out publicationDate)) { this.PublicationDate = publicationDate; wasLoaded = true; } } if (sourceNavigator != null) { RssSource sourceFeed = new RssSource(); if (sourceFeed.Load(sourceNavigator)) { this.Source = sourceFeed; wasLoaded = true; } } if (categoryIterator != null && categoryIterator.Count > 0) { while (categoryIterator.MoveNext()) { RssCategory category = new RssCategory(); if (category.Load(categoryIterator.Current)) { this.Categories.Add(category); } } } if (enclosureIterator != null && enclosureIterator.Count > 0) { while (enclosureIterator.MoveNext()) { RssEnclosure enclosure = new RssEnclosure(); if (enclosure.Load(enclosureIterator.Current)) { this.Enclosures.Add(enclosure); } } } return(wasLoaded); }
/// <summary> /// Loads this <see cref="RssItem"/> 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="RssItem"/> 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="RssItem"/>. /// </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"); //------------------------------------------------------------ // Create namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = new XmlNamespaceManager(source.NameTable); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ XPathNavigator authorNavigator = source.SelectSingleNode("author", manager); XPathNavigator commentsNavigator = source.SelectSingleNode("comments", manager); XPathNavigator descriptionNavigator = source.SelectSingleNode("description", manager); XPathNavigator guidNavigator = source.SelectSingleNode("guid", manager); XPathNavigator linkNavigator = source.SelectSingleNode("link", manager); XPathNavigator publicationNavigator = source.SelectSingleNode("pubDate", manager); XPathNavigator sourceNavigator = source.SelectSingleNode("source", manager); XPathNavigator titleNavigator = source.SelectSingleNode("title", manager); XPathNodeIterator categoryIterator = source.Select("category", manager); XPathNodeIterator enclosureIterator = source.Select("enclosure", manager); //------------------------------------------------------------ // Load required/common item elements //------------------------------------------------------------ if (titleNavigator != null) { this.Title = titleNavigator.Value; wasLoaded = true; } if (descriptionNavigator != null) { this.Description = descriptionNavigator.Value; wasLoaded = true; } if (linkNavigator != null) { Uri link; if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link)) { this.Link = link; wasLoaded = true; } } //------------------------------------------------------------ // Load optional item elements //------------------------------------------------------------ if (authorNavigator != null) { this.Author = authorNavigator.Value; wasLoaded = true; } if (commentsNavigator != null) { Uri comments; if (Uri.TryCreate(commentsNavigator.Value, UriKind.RelativeOrAbsolute, out comments)) { this.Comments = comments; wasLoaded = true; } } if (guidNavigator != null) { RssGuid guid = new RssGuid(); if (guid.Load(guidNavigator, settings)) { this.Guid = guid; wasLoaded = true; } } if (publicationNavigator != null) { DateTime publicationDate; if (SyndicationDateTimeUtility.TryParseRfc822DateTime(publicationNavigator.Value, out publicationDate)) { this.PublicationDate = publicationDate; wasLoaded = true; } } if (sourceNavigator != null) { RssSource sourceFeed = new RssSource(); if (sourceFeed.Load(sourceNavigator, settings)) { this.Source = sourceFeed; wasLoaded = true; } } //------------------------------------------------------------ // Load item collection elements //------------------------------------------------------------ if (categoryIterator != null && categoryIterator.Count > 0) { while (categoryIterator.MoveNext()) { RssCategory category = new RssCategory(); if (category.Load(categoryIterator.Current, settings)) { this.Categories.Add(category); } } } if (enclosureIterator != null && enclosureIterator.Count > 0) { while (enclosureIterator.MoveNext()) { RssEnclosure enclosure = new RssEnclosure(); if (enclosure.Load(enclosureIterator.Current, settings)) { this.Enclosures.Add(enclosure); } } } //------------------------------------------------------------ // Attempt to extract syndication extension information //------------------------------------------------------------ SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings); adapter.Fill(this); return(wasLoaded); }
/// <summary> /// Loads this <see cref="RssItem"/> 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="RssItem"/> 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="RssItem"/>. /// </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"); //------------------------------------------------------------ // Create namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = new XmlNamespaceManager(source.NameTable); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ XPathNavigator authorNavigator = source.SelectSingleNode("author", manager); XPathNavigator commentsNavigator = source.SelectSingleNode("comments", manager); XPathNavigator descriptionNavigator = source.SelectSingleNode("description", manager); XPathNavigator guidNavigator = source.SelectSingleNode("guid", manager); XPathNavigator linkNavigator = source.SelectSingleNode("link", manager); XPathNavigator publicationNavigator = source.SelectSingleNode("pubDate", manager); XPathNavigator sourceNavigator = source.SelectSingleNode("source", manager); XPathNavigator titleNavigator = source.SelectSingleNode("title", manager); XPathNodeIterator categoryIterator = source.Select("category", manager); XPathNodeIterator enclosureIterator = source.Select("enclosure", manager); //------------------------------------------------------------ // Load required/common item elements //------------------------------------------------------------ if (titleNavigator != null) { this.Title = titleNavigator.Value; wasLoaded = true; } if (descriptionNavigator != null) { this.Description = descriptionNavigator.Value; wasLoaded = true; } if (linkNavigator != null) { Uri link; if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link)) { this.Link = link; wasLoaded = true; } } //------------------------------------------------------------ // Load optional item elements //------------------------------------------------------------ if (authorNavigator != null) { this.Author = authorNavigator.Value; wasLoaded = true; } if (commentsNavigator != null) { Uri comments; if (Uri.TryCreate(commentsNavigator.Value, UriKind.RelativeOrAbsolute, out comments)) { this.Comments = comments; wasLoaded = true; } } if (guidNavigator != null) { RssGuid guid = new RssGuid(); if (guid.Load(guidNavigator, settings)) { this.Guid = guid; wasLoaded = true; } } if (publicationNavigator != null) { DateTime publicationDate; if (SyndicationDateTimeUtility.TryParseRfc822DateTime(publicationNavigator.Value, out publicationDate)) { this.PublicationDate = publicationDate; wasLoaded = true; } } if (sourceNavigator != null) { RssSource sourceFeed = new RssSource(); if (sourceFeed.Load(sourceNavigator, settings)) { this.Source = sourceFeed; wasLoaded = true; } } //------------------------------------------------------------ // Load item collection elements //------------------------------------------------------------ if (categoryIterator != null && categoryIterator.Count > 0) { while (categoryIterator.MoveNext()) { RssCategory category = new RssCategory(); if (category.Load(categoryIterator.Current, settings)) { this.Categories.Add(category); } } } if (enclosureIterator != null && enclosureIterator.Count > 0) { while (enclosureIterator.MoveNext()) { RssEnclosure enclosure = new RssEnclosure(); if (enclosure.Load(enclosureIterator.Current, settings)) { this.Enclosures.Add(enclosure); } } } //------------------------------------------------------------ // Attempt to extract syndication extension information //------------------------------------------------------------ SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings); adapter.Fill(this); return wasLoaded; }