Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » Samples » Downloads
 
Add your own
alternative version

RSS 2.0 Framework

, 19 Jan 2013
RSS 2.0 framework implements the RSS 2.0 specification in strongly typed classes. The framework enables you to create and consume valid RSS 2.0 feeds in your code in just a few minutes.
rssframework_bin.zip
rssframework_demo.zip
Raccoom.Bin
DockingManagerExtender.dll
MagicLibrary.DLL
nunit.framework.dll
Raccoom.Windows.Forms
Windows
Forms
Design
Raccoom.Xml
Properties
Raccoom.Xml.csproj.user
Xml
atom.xsx
Raccoom.Xml.Editors
ActionList
Actions
Design
App.ico
Raccoom.Xml.Editors.csproj.user
Windows
Forms
Raccoom.Xml.Test
Resources
rsschannel.rss
bin
rssframework_help.zip
rssframework_src.zip
rsschannel.rss
Raccoom.Xml.csproj.user
atom.xsx
setup.zip
// Copyright � 2006 by Christoph Richner. All rights are reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//
// website http://www.raccoom.net, email support@raccoom.net, msn chrisdarebell@msn.com

using System;

namespace Raccoom.Xml.Test
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	[NUnit.Framework.TestFixture]
	public class Rss
	{
		#region fields
		public const string Uri = "http://www.mydomain.com";
		public const string EmailAdress = "someone@somewhere.com";
		public const string RFCDateTime = "Mon, 03 Nov 2003 14:00:00 GMT";		
		#endregion
		public Rss()
		{			
		}
		/// <summary>
		/// Create a new channel instance and fill all properties with data
		/// </summary>
		[NUnit.Framework.Test]
		public void FullChannelCreate()
		{
			Raccoom.Xml.RssChannel channel = new RssChannel();
			channel.Category = "Category";
			channel.Cloud.Domain = Uri;
			channel.Cloud.Path = "mypath/doc";
			channel.Cloud.Port = 80;
			channel.Cloud.Protocol = CloudProtocol.HttpPost;
			channel.Cloud.RegisterProcedure = "myprocedure";
			channel.Copyright = "Copyright";
			channel.Description = "Description";
			channel.Docs = Uri;
			channel.Generator = "Generator";
			channel.Image.Description = "Description";
			channel.Image.Height = 30;
			channel.Image.Link = Uri;
			channel.Image.Title = "Title";
			channel.Image.Url = Uri;
			channel.Image.Width = 80;
			channel.Language = System.Globalization.CultureInfo.CurrentCulture;
			channel.LastBuildDate = DateTime.Now;			
			channel.Link = Uri;
			channel.ManagingEditor = EmailAdress;
			//channel.PubDate = RFCDateTime;
			channel.PubDate = DateTime.Now;
			channel.Rating = "Rating";
			channel.SkipDays = SkipDays.Monday | SkipDays.Tuesday;
			channel.SkipHours = new int[] {1,2,3,4,5,6};
			channel.TextInput.Description = "Description";
			channel.TextInput.Link = Uri;
			channel.TextInput.Name = "Name";
			channel.TextInput.Title = "Title";
			channel.Title = "Title";
			channel.Ttl = 10;
			channel.WebMaster = EmailAdress;
			//
			Raccoom.Xml.RssItem item  = new RssItem();
			item.Author = EmailAdress;
			item.Category = "Category";
			item.Comments = "Comments";
			item.Description = "Description";
			item.Enclosure.Length = 100;
			item.Enclosure.Type = "text/xml";
			item.Enclosure.Url = Uri;
			item.Guid.Value = Uri;
			item.Link = Uri;
			item.PubDate = DateTime.Now;
			item.Source.Url = Uri;
			item.Source.Value = "Source";
			item.Title = "Title";			
			channel.Items.Add(item);
			// save channel
			string filename = System.IO.Path.GetFullPath("channelfull.xml");
			channel.Save(filename);
			// load channel
			Raccoom.Xml.RssChannel channel1 = new RssChannel(new Uri(filename));
			// compare
			EqualValues(channel, channel1);
		}		
		/// <summary>
		/// Transforms the channel 
		/// </summary>
		[NUnit.Framework.Test]
		public void FullChannelTransform()
		{
			string filename = System.IO.Path.GetFullPath("channelfull.xml");
			Raccoom.Xml.RssChannel channel = new RssChannel(new Uri(filename));
			using(System.IO.Stream styleSheetStream = this.GetType().Assembly.GetManifestResourceStream("Raccoom.Xml.Test.Resources.rss.xslt"))
			{				
				Helper.TestPersistentManager(channel, styleSheetStream);
			}
		}
		/// <summary>
		/// Creates a new channel with only a few properties set
		/// </summary>
		[NUnit.Framework.Test]
		public void EmptyElementChannelBuild()
		{
			Raccoom.Xml.RssChannel channel = new RssChannel();
			channel.Category = "Category";
			channel.Copyright = "Copyright";
			channel.Description = "Description";
			channel.Docs = Uri;
			channel.Generator = "Generator";
			channel.Language = System.Globalization.CultureInfo.CurrentCulture;
			channel.LastBuildDate = DateTime.Now;
			channel.Link = Uri;
			channel.ManagingEditor = EmailAdress;						
			channel.PubDate = DateTime.Now;
			channel.Rating = "Rating";
			channel.SkipDays = SkipDays.Monday;
			//channel.SkipHours = "2";
			channel.Title = "Title";
			channel.Ttl = 10;
			channel.WebMaster = EmailAdress;
			//
			Raccoom.Xml.RssItem item  = new RssItem();
			item.Author = EmailAdress;
			item.Category = "Category";
			item.Comments = "Comments";
			item.Description = "Description";
			//item.Guid.Value = Uri;
			item.Guid.IsPermaLink = false;
			item.Link = Uri;
			item.PubDate = DateTime.Now;
			//item.Source.Value = "Source";
			item.Source.Url = Uri;
			item.Title = "Title";			
			channel.Items.Add(item);
			//
			string filename = System.IO.Path.GetFullPath("channelEmtpyElements.xml");
			channel.Save(filename);		
			//
			Raccoom.Xml.RssChannel channel1 = new RssChannel(new Uri(filename));
			//
			this.EqualValues(channel, channel1);
			
		}
		/// <summary>
		/// Loads and parse a embedded xml resource (feed) that contains empty elements
		/// </summary>
		[NUnit.Framework.Test]
		public void EmptyElementChannel()
		{
			Raccoom.Xml.RssChannel channel = null;
			using(System.IO.Stream stream = this.GetType().Assembly.GetManifestResourceStream("Raccoom.Xml.Test.Resources.rsschannel.rss"))
			{
				channel = new RssChannel(stream);
			}
			NUnit.Framework.Assert.IsNotNull(channel.Image.Url);
			NUnit.Framework.Assert.IsNotNull(channel.Description);
			NUnit.Framework.Assert.IsNotNull(channel.Items[0].PubDate);
			NUnit.Framework.Assert.IsNotNull(channel.Items[1].PubDate);
			NUnit.Framework.Assert.IsNotNull(channel.Items[2].PubDate);
			NUnit.Framework.Assert.IsNotNull(channel.Items[3].Description);
			NUnit.Framework.Assert.IsNotNull(channel.Items[4].Description);
			NUnit.Framework.Assert.IsNotNull(channel.Items[4].PubDate);
			NUnit.Framework.Assert.IsNotNull(channel.Items[5].Link);
			NUnit.Framework.Assert.IsNotNull(channel.Items[5].PubDate);
		}

		/// <summary>
		/// Get feeds from the internet
		/// </summary>
		[NUnit.Framework.Test]
		public void SamplesFromTheInternet()
		{			
			Raccoom.Xml.ConcreteRssFactory rssFactory = new ConcreteRssFactory();
			Raccoom.Xml.IRssChannel channel =  rssFactory.GetFeed(new Uri("http://cyber.law.harvard.edu/blogs/gems/tech/sampleRss20.xml"));
			channel = rssFactory.GetFeed(new Uri("http://cyber.law.harvard.edu/blogs/gems/tech/sampleRss091.xml"));						
			channel = rssFactory.GetFeed(new Uri("http://cyber.law.harvard.edu/blogs/gems/tech/sampleRss092.xml"));						
			channel = rssFactory.GetFeed(new Uri("http://express.xstreamsoft.com/rss/rssGenerator.aspx?id=5&dt=Cat24"));
			
		}		
		/// <summary>
		/// RssItem knows his RssChannel, after adding, when removing the RssItem.Channel property have to be null
		/// </summary>
		[NUnit.Framework.Test]
		public void CollectionAddRemove()
		{
			Raccoom.Xml.RssChannel channel = new RssChannel();
			RssItem item = new RssItem();
			channel.Items.Add(item);
			// must be equal
			NUnit.Framework.Assert.AreSame(channel.Items[0].Channel, channel);
			item.Remove();			
			// must be null
			NUnit.Framework.Assert.IsNull(item.Channel);
		}
		#region private interface
		private void EqualValues(object obj1, object obj2)
		{
			foreach(System.Reflection.PropertyInfo pi in obj1.GetType().GetProperties())
			{
				if(pi.Name == "Channel")
				{
					continue;
				}
				else if(pi.PropertyType.BaseType == typeof(System.Collections.CollectionBase))
				{
					Raccoom.Xml.RssItemCollection col = pi.GetValue(obj1,null) as Raccoom.Xml.RssItemCollection;
					Raccoom.Xml.RssItemCollection col1 = pi.GetValue(obj2,null) as Raccoom.Xml.RssItemCollection;
					for(int i = 0; i<col.Count;i++)
					{
						EqualValues(col[i], col1[i]);                        
					}
				} 
				else if(pi.PropertyType.Assembly.Equals(typeof(Raccoom.Xml.RssChannel).Assembly))
				{
					EqualValues(pi.GetValue(obj1,null), pi.GetValue(obj2,null));
				}
				else if(pi.PropertyType == typeof(string))
				{
					NUnit.Framework.Assert.AreEqual(pi.GetValue(obj1,null), pi.GetValue(obj2,null), pi.ReflectedType.Name + " "+ pi.Name);
				}
				
			}
		}
		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)

Share

About the Author

Chris Richner
Software Developer (Senior) Zeit AG
Switzerland Switzerland
Biography
  • 1996 - 1998 PC Board PPL, HTML, DHTML, Javascript and ASP
  • 1999 - 2001 coding Centura against Sql Database (SqlBase,MSSQL,Oracle)
  • 2002 - 2004 C# Windows Forms
  • 2005 - 2006 C# ASP.NET, Windows Forms
  • 2006 - 2009 C#, WCF, WF, WPF
  • 2010 - 2012 C#, Dynamics CRM, Sharepoint, Silverlight
  • 2013 - now C#, WCF DS (OData), WF, WPF
Interests
  • family & friends
  • chilaxing ,)
  • coding
Follow on   Twitter   Google+   LinkedIn

| Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 20 Jan 2013
Article Copyright 2003 by Chris Richner
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid