Click here to Skip to main content
15,885,891 members
Articles / Web Development / ASP.NET

RSS 2.0 Framework

Rate me:
Please Sign up or sign in to vote.
4.92/5 (67 votes)
19 Jan 2013LGPL37 min read 507.2K   15.2K   361  
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.
// 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 Opml.
	/// </summary>
	[NUnit.Framework.TestFixture]
	public class Opml
	{
		public Opml()
		{			
		}

		[NUnit.Framework.Test]
		public void FullDocumentCreateAddBodyNow()
		{
			Raccoom.Xml.OpmlDocument doc = new OpmlDocument();
			doc.Head.DateCreated = DateTime.Now;
			doc.Head.DateModified = DateTime.Now;
			doc.Head.ExpansionState = "ExpansionState";
			doc.Head.OwnerEmail = Rss.EmailAdress;
			doc.Head.OwnerName = "OwnerName";
			doc.Head.Title = "Title";
			doc.Head.VertScrollState = 10;
			doc.Head.WindowBottom = 10;
			doc.Head.WindowLeft = 10;
			doc.Head.WindowRight = 10;
			doc.Head.WindowTop = 10;
			//
			int itemCount = 3;
			for(int i = 0; i<itemCount;i++)
			{
				// root outline
				OpmlOutline outline = CreateOutline();				
				// sub outlines
				for(int j = 0;j<itemCount;j++)
				{
					OpmlOutline o = CreateOutline();
					outline.Items.Add(o);				
					o.Items.Add(CreateOutline());
				}
				//
				doc.Body.Items.Add(outline);
				// single outline
				doc.Body.Items.Add(CreateOutline());
			}
			//
			string filename = System.IO.Path.GetFullPath("opmldocument.xml");
			doc.Save(filename);
			//
			OpmlDocument doc1 = new OpmlDocument(new Uri(filename));
			//
			EqualValues(doc, doc1);
		}

		[NUnit.Framework.Test]
		public void FullDocumentCreateAddBodyAfter()
		{
			Raccoom.Xml.OpmlDocument doc = new OpmlDocument();
			doc.Head.DateCreated = DateTime.Now;
			doc.Head.DateModified = DateTime.Now;
			doc.Head.ExpansionState = "ExpansionState";
			doc.Head.OwnerEmail = Rss.EmailAdress;
			doc.Head.OwnerName = "OwnerName";
			doc.Head.Title = "Title";
			doc.Head.VertScrollState = 10;
			doc.Head.WindowBottom = 10;
			doc.Head.WindowLeft = 10;
			doc.Head.WindowRight = 10;
			doc.Head.WindowTop = 10;
			//
			int itemCount = 3;
			OpmlOutline outlineRoot = CreateOutline();	
			for(int i = 0; i<itemCount;i++)
			{
				// root outline
				OpmlOutline outline = CreateOutline();				
				// sub outlines
				for(int j = 0;j<itemCount;j++)
				{
					OpmlOutline o = CreateOutline();
					outline.Items.Add(o);				
					o.Items.Add(CreateOutline());
				}
				//
				outlineRoot.Items.Add(outline);
				// single outline
				outlineRoot.Items.Add(CreateOutline());
			}
			doc.Body.Items.Add(outlineRoot);
			//
			foreach(OpmlOutline outline in doc.Body.Items)
			{
				outline.IsBreakpoint.CompareTo(null);
			}
			//
			string filename = System.IO.Path.GetFullPath("opmldocument.xml");
			doc.Save(filename);
			//
			OpmlDocument doc1 = new OpmlDocument(new Uri(filename));
			//
			EqualValues(doc, doc1);			
		}

		[NUnit.Framework.Test]
		public void FullDocumentTransform()
		{
			string filename = System.IO.Path.GetFullPath("opmldocument.xml");
			OpmlDocument doc = new OpmlDocument(new Uri(filename));
			//
			using(System.IO.Stream styleSheetStream = this.GetType().Assembly.GetManifestResourceStream("Raccoom.Xml.Test.Resources.opml.xslt"))
			{				
				Helper.TestPersistentManager(doc, styleSheetStream);
			}


		}
		[NUnit.Framework.Test]
		public void CollectionAddRemove()
		{
			// document
			// - outline
			//   - outline
			Raccoom.Xml.OpmlDocument doc = new OpmlDocument();
			// add item
			OpmlOutline item = new OpmlOutline();
			doc.Body.Items.Add(item);			
			NUnit.Framework.Assert.IsNotNull(item.Document);
			NUnit.Framework.Assert.IsNull(item.Parent);
			// add subitem
			OpmlOutline subItem = new OpmlOutline();
			item.Items.Add(subItem);			
			NUnit.Framework.Assert.IsNotNull(subItem.Document);
			NUnit.Framework.Assert.IsNotNull(subItem.Parent);
			NUnit.Framework.Assert.AreEqual(subItem.Document, doc);
			NUnit.Framework.Assert.AreEqual(subItem.Parent, item);
			// remove subitem
			subItem.Remove();
			//item.Items.Remove(subItem);
			NUnit.Framework.Assert.IsNull(subItem.Parent);
			NUnit.Framework.Assert.IsNull(subItem.Document);
			// remove item
			item.Remove();
			//doc.Body.Items.Remove(item);
			NUnit.Framework.Assert.IsNull(item.Document);
			NUnit.Framework.Assert.IsNull(item.Parent);

		}
		[NUnit.Framework.Test]
		public void SamplesFromTheInternet()
		{		
			ConcreteOpmlFactory opmlFactory = new ConcreteOpmlFactory();
			IOpmlDocument document =  opmlFactory.GetDocument(new Uri("http://static.userland.com/gems/radiodiscuss/playlist.opml"));			
			document =  opmlFactory.GetDocument(new Uri("http://static.userland.com/gems/radiodiscuss/specification.opml"));						
			document =  opmlFactory.GetDocument(new Uri("http://static.userland.com/gems/radiodiscuss/presentation.opml"));						
			
		}		
		#region private interface
		private void EqualValues(object obj1, object obj2)
		{
			foreach(System.Reflection.PropertyInfo pi in obj1.GetType().GetProperties())
			{
				if(pi.Name == "Document" || pi.Name == "Parent")
				{
					continue;
				}
				else if(pi.PropertyType.BaseType == typeof(System.Collections.CollectionBase))
				{
					Raccoom.Xml.OpmlOutlineCollection col = pi.GetValue(obj1,null) as Raccoom.Xml.OpmlOutlineCollection;
					Raccoom.Xml.OpmlOutlineCollection col1 = pi.GetValue(obj2,null) as Raccoom.Xml.OpmlOutlineCollection;
					for(int i = 0; i<col.Count;i++)
					{
						EqualValues(col[i], col1[i]);                        
					}
				} 
				else if(pi.PropertyType.Assembly.Equals(typeof(Raccoom.Xml.OpmlDocument).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);
				}
				
			}
		}		
		private OpmlOutline CreateOutline()
		{
			OpmlOutline outline = new OpmlOutline();
			outline.Description = "Description";
			outline.HtmlUrl = Rss.Uri;
			outline.IsBreakpoint = false;
			outline.IsComment = false;
			outline.Text = "Text";
			return outline;
		}		
		#endregion
	}
	public class Helper
	{
		internal static void TestPersistentManager(IPersistentManager manager, System.IO.Stream styleSheetStream)
		{		
			styleSheetStream.Seek(0, System.IO.SeekOrigin.Begin);
			manager.Transform(new System.Xml.XmlTextReader(styleSheetStream));
			//
			using(System.IO.MemoryStream xmlStream = new System.IO.MemoryStream())
			{
				manager.Save(xmlStream);
				xmlStream.Seek(0, System.IO.SeekOrigin.Begin);	
				styleSheetStream.Seek(0, System.IO.SeekOrigin.Begin);					
				manager.Transform(new System.Xml.XmlTextReader(styleSheetStream), xmlStream);
			}
			//
			styleSheetStream.Seek(0, System.IO.SeekOrigin.Begin);
			manager.Transform(new System.Xml.XmlTextReader(styleSheetStream), manager.GetType().Name+".xml", manager.GetType().Name+".html");
		}
	}
}

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)


Written By
Software Developer (Senior)
Switzerland Switzerland
My interest is in the future because I am going to spend the rest of my life there. (Charles Kettering)

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 - 2013 C#, WCF DS (OData), WF, WPF
  • 2014 - 2016 C#, Azure PaaS, Identity, OWIN, OData, Web Api
  • 2017 - now C#, aspnet.core, IdentityServer4, TypeScript & Angular @ Azure IaaS or PaaS

Interests

  • family & friends
  • chilaxing ,)
  • coding

Comments and Discussions