Click here to Skip to main content
15,894,460 members
Articles / Programming Languages / Visual Basic

RSS Feed Aggregator and Blogging Smart Client

Rate me:
Please Sign up or sign in to vote.
4.91/5 (85 votes)
16 Aug 2005CPOL52 min read 1.1M   2.4K   397  
RSS Feed aggregator and blogging Smart Client which uses Enterprise Library, Updater Application Block, lots of XML hacks and desktop tricks. A comprehensive guide to real life hurdles of Smart Client development.
// Copyright � 2005 by Omar Al Zabir. All rights are reserved.
// 
// If you like this code then feel free to go ahead and use it.
// The only thing I ask is that you don't remove or alter my copyright notice.
//
// Your use of this software is entirely at your own risk. I make no claims or
// warrantees about the reliability or fitness of this code for any particular purpose.
// If you make changes or additions to this code please mark your code as being yours.
// 
// website http://www.oazabir.com, email OmarAlZabir@gmail.com, msn oazabir@hotmail.com

using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Reflection;
using System.Collections;

namespace RSSCommon.Helper
{
	/// <summary>
	/// Utility methods
	/// </summary>
	public class SerializationHelper
	{
		public const string RESOURCE_ASSEMBLY_PREFIX = "RSSFeederResources.";

		public static XmlWriter Serialize( Stream stream, object o )
		{
			XmlTextWriter writer = new XmlTextWriter( stream, System.Text.Encoding.UTF8 );
			XmlSerializer serializer = new XmlSerializer( o.GetType() );
			serializer.Serialize( writer, o );
			return writer;
		}
		public static XmlWriter Serialize( Stream stream, ArrayList array, Type type )
		{
			XmlTextWriter writer = new XmlTextWriter( stream, System.Text.Encoding.UTF8 );
			XmlSerializer serializer = new XmlSerializer( typeof(ArrayList), new Type[] { type } );
			serializer.Serialize( writer, array );
			return writer;
		}

		public static object Deserialize( Stream stream, Type t )
		{
			XmlTextReader reader = new XmlTextReader( stream );
			XmlSerializer serializer = new XmlSerializer( t );
			object o =  serializer.Deserialize( reader );
			return o;
		}

		public static ArrayList DeserializeArraylist( Stream stream, Type t )
		{
			XmlTextReader reader = new XmlTextReader( stream );
			XmlSerializer serializer = new XmlSerializer( typeof( ArrayList ), new Type [] { t } );
			ArrayList list = (ArrayList) serializer.Deserialize( reader );
			return list;
		}

		public static Stream GetStream( string name )
		{
			return GetResourceAssembly().GetManifestResourceStream(RESOURCE_ASSEMBLY_PREFIX + name);
		}

		public static System.Drawing.Icon GetIcon( string name )
		{
			using( Stream stream = GetStream( name ) )
			{
				return new System.Drawing.Icon( stream );
			}
		}

		public static Assembly GetResourceAssembly()
		{
			return Assembly.LoadFrom("RSSFeederResources.dll");
		}
		
		public static void WriteEmbeddedFile( string name, string fileName )
		{
			using( Stream stream = GetStream( name ) )
			{
				FileInfo file = new FileInfo( fileName );
				using( FileStream fileStream = file.Create() )
				{
					byte [] buf = new byte[ 1024 ];
					int size;
					while( (size = stream.Read( buf, 0, 1024 )) > 0 )
					{
						fileStream.Write( buf, 0, size );
					}
				}
			}
		}

		public static void CopyProperties( object source, object destination )
		{
			PropertyInfo [] properties = source.GetType().GetProperties();
			foreach( PropertyInfo prop in properties )
			{
				if( prop.CanWrite )
					prop.SetValue( destination, prop.GetValue( source, null ), null );
			}
		}
	}
}

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 Code Project Open License (CPOL)


Written By
Architect BT, UK (ex British Telecom)
United Kingdom United Kingdom

Comments and Discussions