/// <summary> /// Loads the generic syndication item using the supplied <see cref="AtomEntry"/>. /// </summary> /// <param name="entry">The <see cref="AtomEntry"/> to build an abstraction against.</param> /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception> private void LoadFrom(AtomEntry entry) { Guard.ArgumentNotNull(entry, "entry"); if (entry.Title != null && !String.IsNullOrEmpty(entry.Title.Content)) { itemTitle = entry.Title.Content.Trim(); } if (entry.PublishedOn != DateTime.MinValue) { itemPublishedOn = entry.PublishedOn; } else if (entry.UpdatedOn != DateTime.MinValue) { itemPublishedOn = entry.UpdatedOn; } if (entry.Summary != null && !String.IsNullOrEmpty(entry.Summary.Content)) { itemSummary = entry.Summary.Content.Trim(); } else if (entry.Content != null && !String.IsNullOrEmpty(entry.Content.Content)) { itemSummary = entry.Content.Content.Trim(); } foreach (AtomCategory category in entry.Categories) { GenericSyndicationCategory genericCategory = new GenericSyndicationCategory(category); itemCategories.Add(genericCategory); } }
/// <summary> /// Loads the generic syndication item using the supplied <see cref="RssItem"/>. /// </summary> /// <param name="item">The <see cref="RssItem"/> to build an abstraction against.</param> /// <exception cref="ArgumentNullException">The <paramref name="item"/> is a null reference (Nothing in Visual Basic).</exception> private void LoadFrom(RssItem item) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(item, "item"); //------------------------------------------------------------ // Initialize generic item //------------------------------------------------------------ if (!String.IsNullOrEmpty(item.Title)) { itemTitle = item.Title.Trim(); } if (item.PublicationDate != DateTime.MinValue) { itemPublishedOn = item.PublicationDate; } if (!String.IsNullOrEmpty(item.Description)) { itemSummary = item.Description.Trim(); } foreach (RssCategory category in item.Categories) { GenericSyndicationCategory genericCategory = new GenericSyndicationCategory(category); itemCategories.Add(genericCategory); } }
//============================================================ // ICOMPARABLE IMPLEMENTATION //============================================================ #region CompareTo(object obj) /// <summary> /// Compares the current instance with another object of the same type. /// </summary> /// <param name="obj">An object to compare with this instance.</param> /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns> /// <exception cref="ArgumentException">The <paramref name="obj"/> is not the expected <see cref="Type"/>.</exception> public int CompareTo(object obj) { //------------------------------------------------------------ // If target is a null reference, instance is greater //------------------------------------------------------------ if (obj == null) { return(1); } //------------------------------------------------------------ // Determine comparison result using property state of objects //------------------------------------------------------------ GenericSyndicationCategory value = obj as GenericSyndicationCategory; if (value != null) { int result = String.Compare(this.Scheme, value.Scheme, StringComparison.Ordinal); result = result | String.Compare(this.Term, value.Term, StringComparison.OrdinalIgnoreCase); return(result); } else { throw new ArgumentException(String.Format(null, "obj is not of type {0}, type was found to be '{1}'.", this.GetType().FullName, obj.GetType().FullName), "obj"); } }
/// <summary> /// Compares the current instance with another object of the same type. /// </summary> /// <param name="obj">An object to compare with this instance.</param> /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns> /// <exception cref="ArgumentException">The <paramref name="obj"/> is not the expected <see cref="Type"/>.</exception> public int CompareTo(object obj) { if (obj == null) { return(1); } GenericSyndicationCategory value = obj as GenericSyndicationCategory; if (value != null) { int result = String.Compare(this.Scheme, value.Scheme, StringComparison.Ordinal); result = result | String.Compare(this.Term, value.Term, StringComparison.OrdinalIgnoreCase); return(result); } else { throw new ArgumentException(String.Format(null, "obj is not of type {0}, type was found to be '{1}'.", this.GetType().FullName, obj.GetType().FullName), "obj"); } }
/// <summary> /// Loads the generic syndication item using the supplied <see cref="RssItem"/>. /// </summary> /// <param name="item">The <see cref="RssItem"/> to build an abstraction against.</param> /// <exception cref="ArgumentNullException">The <paramref name="item"/> is a null reference (Nothing in Visual Basic).</exception> private void LoadFrom(RssItem item) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(item, "item"); //------------------------------------------------------------ // Initialize generic item //------------------------------------------------------------ if (!String.IsNullOrEmpty(item.Title)) { itemTitle = item.Title.Trim(); } if (item.PublicationDate != DateTime.MinValue) { itemPublishedOn = item.PublicationDate; } if (!String.IsNullOrEmpty(item.Description)) { itemSummary = item.Description.Trim(); } foreach (RssCategory category in item.Categories) { GenericSyndicationCategory genericCategory = new GenericSyndicationCategory(category); itemCategories.Add(genericCategory); } }
/// <summary> /// Loads the generic syndication item using the supplied <see cref="AtomEntry"/>. /// </summary> /// <param name="entry">The <see cref="AtomEntry"/> to build an abstraction against.</param> /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception> private void LoadFrom(AtomEntry entry) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(entry, "entry"); //------------------------------------------------------------ // Initialize generic item //------------------------------------------------------------ if (entry.Title != null && !String.IsNullOrEmpty(entry.Title.Content)) { itemTitle = entry.Title.Content.Trim(); } if (entry.PublishedOn != DateTime.MinValue) { itemPublishedOn = entry.PublishedOn; } else if (entry.UpdatedOn != DateTime.MinValue) { itemPublishedOn = entry.UpdatedOn; } if (entry.Summary != null && !String.IsNullOrEmpty(entry.Summary.Content)) { itemSummary = entry.Summary.Content.Trim(); } else if (entry.Content != null && !String.IsNullOrEmpty(entry.Content.Content)) { itemSummary = entry.Content.Content.Trim(); } foreach (AtomCategory category in entry.Categories) { GenericSyndicationCategory genericCategory = new GenericSyndicationCategory(category); itemCategories.Add(genericCategory); } }
/// <summary> /// Initializes the generic syndication feed using the supplied <see cref="AtomFeed"/>. /// </summary> /// <param name="feed">The <see cref="AtomFeed"/> to build an abstraction against.</param> /// <exception cref="ArgumentNullException">The <paramref name="feed"/> is a null reference (Nothing in Visual Basic).</exception> public void Parse(AtomFeed feed) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(feed, "feed"); //------------------------------------------------------------ // Initialize generic feed //------------------------------------------------------------ feedResource = feed; feedFormat = SyndicationContentFormat.Atom; if (feed.Title != null && !String.IsNullOrEmpty(feed.Title.Content)) { feedTitle = feed.Title.Content; } if (feed.Subtitle != null && !String.IsNullOrEmpty(feed.Title.Content)) { feedDescription = feed.Subtitle.Content; } if (feed.UpdatedOn != DateTime.MinValue) { feedLastUpdatedOn = feed.UpdatedOn; } if(feed.Language != null) { feedLanguage = feed.Language; } foreach(AtomCategory category in feed.Categories) { GenericSyndicationCategory genericCategory = new GenericSyndicationCategory(category); feedCategories.Add(genericCategory); } foreach(AtomEntry entry in feed.Entries) { GenericSyndicationItem genericItem = new GenericSyndicationItem(entry); ((Collection<GenericSyndicationItem>)feedItems).Add(genericItem); } }
/// <summary> /// Initializes the generic syndication feed using the supplied <see cref="RssFeed"/>. /// </summary> /// <param name="feed">The <see cref="RssFeed"/> to build an abstraction against.</param> /// <exception cref="ArgumentNullException">The <paramref name="feed"/> is a null reference (Nothing in Visual Basic).</exception> public void Parse(RssFeed feed) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(feed, "feed"); //------------------------------------------------------------ // Initialize generic feed //------------------------------------------------------------ feedResource = feed; feedFormat = SyndicationContentFormat.Rss; if (!String.IsNullOrEmpty(feed.Channel.Title)) { feedTitle = feed.Channel.Title; } if (!String.IsNullOrEmpty(feed.Channel.Description)) { feedDescription = feed.Channel.Description; } if (feed.Channel.LastBuildDate != DateTime.MinValue) { feedLastUpdatedOn = feed.Channel.LastBuildDate; } if (feed.Channel.Language != null) { feedLanguage = feed.Channel.Language; } foreach (RssCategory category in feed.Channel.Categories) { GenericSyndicationCategory genericCategory = new GenericSyndicationCategory(category); feedCategories.Add(genericCategory); } foreach (RssItem item in feed.Channel.Items) { GenericSyndicationItem genericItem = new GenericSyndicationItem(item); ((Collection<GenericSyndicationItem>)feedItems).Add(genericItem); } }