Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

RSS Feed Aggregator and Blogging Smart Client

, 16 Aug 2005 CPOL
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.
rssfeeder_src.zip
RSSFeeder
RSSBlogAPI
RSSBlogAPI.csproj.user
Web References
CommunityServer
blogservice.disco
blogservice.wsdl
Reference.map
DotText
Reference.map
simpleblogservice.disco
simpleblogservice.wsdl
RSSCommon
Helper
PropertyEditor
RSSCommon.csproj.user
RSSFeeder
Controls
docs
dropshadow.png
My Pic 7.jpg
WIndows98.jpg
Helpers
Resources
E-mail.ico
rss.ico
RSSFeeder.mdb
RSSFeeder.csproj.user
RSSStarter.exe
RSSFeederResources
PublicQueue.ico
RSSFeeder.mdb
RSSFeederResources.csproj.user
RSSFeederSetup
Messages.ico
RSSFeederSetup.vdproj
Test
RSSStarter
DummyForm.frm
DummyForm.frx
MainModule.bas
RSSStarter.exe
RSSStarter.vbp
RSSStarter.vbw
RSSTests
App.ico
RSSTests.csproj.user
Thirdparty
AxInterop.DHTMLEDLib.dll
AxInterop.SHDocVw.dll
Eyefinder.dll
GotDotNet.Exslt.dll
HttpDownloader.dll
Interop.DHTMLEDLib.dll
Interop.SHDocVw.dll
Interop.WindowsInstaller.dll
Microsoft.ApplicationBlocks.Updater.ActivationProcessors.dll
Microsoft.ApplicationBlocks.Updater.dll
Microsoft.ApplicationBlocks.Updater.Downloaders.dll
Microsoft.Practices.EnterpriseLibrary.Caching.dll
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Configuration.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cache.CachingStore.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
Microsoft.Practices.EnterpriseLibrary.Security.dll
NotifyIconBalloon.dll
SandBar.dll
SandDock.dll
SgmlReaderDll.dll
// 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 Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using Microsoft.Practices.EnterpriseLibrary.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Caching;
using Microsoft.Practices.EnterpriseLibrary.Security.Cryptography;

namespace RSSFeeder.Helpers
{

	/// <summary>
	/// Helper class for dealing with enterprise library
	/// </summary>
	public class EntLibHelper : RSSCommon.PropertyEditor.IPasswordProvider
	{
		private const string CONFIGURATION_SECTION_NAME = "globalConfiguration";
		private const string INFO_CATEGORY = "Info";
		private const string WARN_CATEGORY = "Warn";
		private const string ERROR_CATEGORY = "Error";
		private const string DEBUG_CATEGORY = "Debug";

		private const int INFO_PRIORITY = 4;
		private const int INFO_EVENTID = 0;

		private const int ERROR_PRIORITY = 3;
		private const int ERROR_EVENTID = 0;

		private const int WARN_PRIORITY = 2;
		private const int WARN_EVENTID = 0;

		private const int DEBUG_PRIORITY = 1;
		private const int DEBUG_EVENTID = 0;

		private const string EXCEPTION_POLICY_NAME = "General Policy";
		private const string SYMMETRIC_INSTANCE = "DPAPI";
		private const string HASH_INSTANCE = "MD5CryptoServiceProvider";

		public const string XSL_CACHE_MANAGER = "XSL Cache";

		/*
		Category - used to determine the routing of the LogEntry; 
		Priority - used to filter Log Entries, only those above the �Minimum Priority� are processed (defaults to -1 which indicates that the Minimum Priority should be used); 
		EventId - a value you can use to further categorise Log Entries (defaults to 0 for a LogEntry and to 1 for a LogEntry implicitly created by Logger.Write); 
		Severity - indicates the severity of the Log Entry, e.g., Information, Warning, Error etc. 
		Title - a summary of the LogEntry.Message. 
		*/
		
		private static CacheManager manager = CacheFactory.GetCacheManager(XSL_CACHE_MANAGER);

		public static void Info( string title, object message )
		{
			Logger.Write( "Log message", "Debug" );
			Logger.Write( message, INFO_CATEGORY, INFO_PRIORITY, INFO_EVENTID, Microsoft.Practices.EnterpriseLibrary.Logging.Severity.Information, title );
		}
		public static void Error( string title, object message )
		{
			Logger.Write( message, ERROR_CATEGORY, ERROR_PRIORITY, ERROR_EVENTID, Microsoft.Practices.EnterpriseLibrary.Logging.Severity.Error, title );
		}
		public static void Warn( string title, object message )
		{
			Logger.Write( message, WARN_CATEGORY, WARN_PRIORITY, WARN_EVENTID, Microsoft.Practices.EnterpriseLibrary.Logging.Severity.Warning, title );
		}
		public static void Debug( string title, object message )
		{
			Logger.Write( message, DEBUG_CATEGORY, DEBUG_PRIORITY, DEBUG_EVENTID, Microsoft.Practices.EnterpriseLibrary.Logging.Severity.Unspecified, title );
		}

		public static void Exception( string title, Exception x )
		{
			ApplicationException wrapped = new ApplicationException( "title", x );
			bool rethrow = ExceptionPolicy.HandleException( wrapped, EXCEPTION_POLICY_NAME );
			if( rethrow )
			{
				throw x;
			}
		}

		internal static void UnhandledException(Exception x)
		{
			// An unhandled exception occured somewhere in our application. Let
			// the 'Global Policy' handler have a try at handling it.
			try
			{
				bool rethrow = ExceptionPolicy.HandleException(x, "Unhandled Exception");
				if (rethrow)
				{
					// Something has gone very wrong - exit the application.
					System.Windows.Forms.Application.Exit();
				}
				else
				{
					ErrorReportForm.QueueErrorReport( new ErrorReportItem( x.Message, x.ToString() ) );
				}
			}
			catch
			{
				// Something has gone wrong during HandleException (e.g. incorrect configuration of the block).
				// Exit the application
				string errorMsg = "An unexpected exception occured while calling HandleException with policy 'Global Policy'. "; 
				errorMsg += "Please check the event log for details about the exception." + Environment.NewLine + Environment.NewLine;

				System.Windows.Forms.MessageBox.Show(errorMsg, "Application Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Stop);        
        
				System.Windows.Forms.Application.Exit();
			}
		}

		/// <summary>
		/// Load configuration from configuration Xml file. If the configuration does not exist, it returns false.
		/// </summary>
		/// <returns>True if configuration exists and loaded</returns>
		public static bool LoadConfiguration()
		{
			try
			{
				RSSCommon.Configuration existing = ConfigurationManager.GetConfiguration( CONFIGURATION_SECTION_NAME ) as RSSCommon.Configuration;
				if( null != existing )
				{
					RSSCommon.Configuration.Instance = existing;
					return true;
				}
				else
				{
					return false;
				}
			}
			catch
			{
				return false;
			}
			
		}

		public static void SaveConfiguration()
		{
			ConfigurationManager.WriteConfiguration( CONFIGURATION_SECTION_NAME, RSSCommon.Configuration.Instance );
		}

		public static void StoreInCache( string key, object data )
		{
			manager.Add( key, data );			
		}

		public static object GetCachedObject( string key )
		{

			if( manager.Contains( key ) )
				return manager.GetData( key );
			else 
				return null;			
		}

		string RSSCommon.PropertyEditor.IPasswordProvider.Encrypt( string data )
		{
			if( 0 == data.Length ) return string.Empty;
			return Encrypt( data );
		}

		string RSSCommon.PropertyEditor.IPasswordProvider.Decrypt( string data )
		{
			return Decrypt( data );
		}
		string RSSCommon.PropertyEditor.IPasswordProvider.Hash( string data )
		{
			return Hash( data );
		}

		public static string Encrypt( string data )
		{
			if( 0 == data.Trim().Length ) return string.Empty;
			return Cryptographer.EncryptSymmetric( SYMMETRIC_INSTANCE, data );
		}

		public static string Decrypt( string data )
		{
			if( 0 == data.Trim().Length ) return string.Empty;
			try
			{
				return Cryptographer.DecryptSymmetric( SYMMETRIC_INSTANCE, data );
			}
			catch
			{
				throw new ApplicationException( "Cannot decrypt password. Make sure you are not manually typing the password. Click the '...' button and set password from the dialog." );
			}
		}

		public static string Hash( string data )
		{
			if( 0 == data.Length ) return string.Empty;
			
			return Cryptographer.CreateHash( HASH_INSTANCE, data );
		}
	}
}

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)

Share

About the Author

Omar Al Zabir
Architect BT, UK (ex British Telecom)
United Kingdom United Kingdom

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150123.1 | Last Updated 16 Aug 2005
Article Copyright 2005 by Omar Al Zabir
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid