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

RSS Feed Aggregator and Blogging Smart Client

, 16 Aug 2005
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 System.IO;
using System.Collections;
using System.Xml;
using System.Xml.Serialization;
using System.Windows.Forms;

namespace RSSFeeder
{
	using RSSCommon;
	using RSSCommon.Helper;
	using Helpers;
	using RSSBlogAPI;

	/// <summary>
	/// It all starts now...
	/// </summary>
	public class EntryPoint
	{
		[STAThread]
		public static void Main()
		{
			// Single instance allowed to run 
			if( SingleApplication.IsAlreadyRunning() ) 
			{
				EntLibHelper.Debug("Main", "Already running" );

				SingleApplication.SwitchToCurrentInstance();
				return;
			}

			// Now this line takes too much time, MS needs to make it faster
			EntLibHelper.Debug("Main", "Starting..." );

			// Hook all unhandled exception, we won't go down without a fight
			AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
			Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

			// XP visual style, makes it look cooler
			Application.EnableVisualStyles();
			Application.DoEvents();

			// Before launching, we need to ensure configuration, check if first time run, etc
			PrelaunchPreparation();

			// Start the app
			Application.Run( new RSSServer() );

			// Freeup database connection
			DatabaseHelper.Close();

			EntLibHelper.Debug("Main", "The End" );
		}

		#region Prelaunch Preparation

		/// <summary>
		/// Check if the application data directory is created, config files are there, whether
		/// this is the first time being launched etc
		/// </summary>
		private static void PrelaunchPreparation()
		{
			#region Log
			EntLibHelper.Debug("PrelaunchPreparation", "Prelaunch preparation...");
			#endregion

			// Prepare the path where all application specific settings will be stored
			string appDataPath =  Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

			ApplicationSettings.ApplicationDataPath = Path.Combine( appDataPath, ApplicationSettings.MY_FOLDER_NAME );
			//ApplicationSettings.ConfigurationFilePath = Path.Combine( ApplicationSettings.ApplicationDataPath, ApplicationSettings.CONFIG_FILE_NAME );
			ApplicationSettings.DatabaseFilePath = Path.Combine( ApplicationSettings.ApplicationDataPath, ApplicationSettings.DATABASE_NAME );

			// Check if all these paths exist
			if( !Directory.Exists( ApplicationSettings.ApplicationDataPath ) )
			{
				#region Log
				EntLibHelper.Debug("PrelaunchPreparation", "Creating application data directory: " + ApplicationSettings.ApplicationDataPath );
				#endregion
				Directory.CreateDirectory( ApplicationSettings.ApplicationDataPath );
			}

			// Load ocnfiguration
			ConfigurationHelper.LoadGlobalSettings();			
		
			/// If the database does not exist, then we are running for the first time
			if( !File.Exists( ApplicationSettings.DatabaseFilePath ) )
			{
				CreateDatabase( );
	
				// If user alreay using some other RSS aggregators, let's import their
				// setting
				if( Helpers.NewsgatorHelper.IsNewsgatorAround() )
				{
					#region Log
					EntLibHelper.Debug("PrelaunchPreparation", "Newsgator detected");
					#endregion

					using( NewsgatorImport form = new NewsgatorImport() )
					{
						form.ShowDialog();
					}
				}
				
				// Show the statup wizard
				using( StartupWizard form = new StartupWizard() )
				{
					#region Log
					EntLibHelper.Debug("PrelaunchPreparation", "Launching startup wizard");
					#endregion

					form.ShowDialog();
				}
			}
			
			// Copy embedded files
			ConfigurationHelper.CopyFiles();
			
			RegistryHelper.RegisterAtStartup();
		}

		/// <summary>
		/// Create a blank database for storing RSS feed.
		/// </summary>
		private static void CreateDatabase( )
		{
			EntLibHelper.Debug("CreateDatabase", "Creating database: " + ApplicationSettings.DatabaseFilePath );
			SerializationHelper.WriteEmbeddedFile( "RSSFeeder.mdb", ApplicationSettings.DatabaseFilePath );	
		}
		#endregion
		
		#region Main Form Handling

		private static MainForm _MainForm;

		/// <summary>
		/// Closes the mainform 
		/// </summary>
		public static void CloseMainForm()
		{
			if( null != _MainForm )
			{
				_MainForm.Close();
			}
		}
		

		/// <summary>
		/// Show the main form and auto select the specified channel. This function ensures the main
		/// form is displayed only once
		/// </summary>
		/// <param name="channelID"></param>
		public static void ShowMainForm(int channelID)
		{
			if( null != _MainForm )
			{
				_MainForm.Show();
				_MainForm.ShowChannel( channelID );
			}
			else
			{
				_MainForm = new MainForm();
				_MainForm.Show();
				_MainForm.ShowChannel( channelID );
				
				_MainForm.Closed += new EventHandler(_MainForm_Closed);
				_MainForm.Disposed += new EventHandler(_MainForm_Disposed);
			}
		}

		/// <summary>
		/// When the mainform is disposed, detach from it to release it completely
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private static void _MainForm_Disposed(object sender, EventArgs e)
		{
			_MainForm.Disposed -= new EventHandler(_MainForm_Disposed);
			_MainForm = null;

			MemoryHelper.ReduceMemory();
		}

		/// <summary>
		/// When the main form is closed, dispose it
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private static void _MainForm_Closed(object sender, EventArgs e)
		{
			_MainForm.Closed -= new EventHandler(_MainForm_Closed);
			if( !_MainForm.Disposing )
				_MainForm.Dispose();
		}

		#endregion

		#region Web Log Manager Handling

		private static WebLogManager _WebLogManagerForm;

		/// <summary>
		/// Closes the WebLogManagerForm 
		/// </summary>
		public static void CloseWebLogManagerForm()
		{
			if( null != _WebLogManagerForm )
			{
				_WebLogManagerForm.Close();
			}
		}
		

		/// <summary>
		/// Show the main form and auto select the specified channel. This function ensures the main
		/// form is displayed only once
		/// </summary>
		/// <param name="channelID"></param>
		public static void ShowWebLogManagerForm()
		{
			if( null != _WebLogManagerForm )
			{
				_WebLogManagerForm.Show();
			}
			else
			{
				_WebLogManagerForm = new WebLogManager();
				_WebLogManagerForm.Show();
				
				_WebLogManagerForm.SendFeeds += new EventHandler(_WebLogManagerForm_SendFeeds);
				_WebLogManagerForm.Closed += new EventHandler(_WebLogManagerForm_Closed);
				_WebLogManagerForm.Disposed += new EventHandler(_WebLogManagerForm_Disposed);
			}
		}

		/// <summary>
		/// When the WebLogManagerForm is disposed, detach from it to release it completely
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private static void _WebLogManagerForm_Disposed(object sender, EventArgs e)
		{
			_WebLogManagerForm.Disposed -= new EventHandler(_WebLogManagerForm_Disposed);
			_WebLogManagerForm = null;

			MemoryHelper.ReduceMemory();
		}

		/// <summary>
		/// When the main form is closed, dispose it
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private static void _WebLogManagerForm_Closed(object sender, EventArgs e)
		{
			_WebLogManagerForm.SendFeeds -= new EventHandler(_WebLogManagerForm_SendFeeds);
			_WebLogManagerForm.Closed -= new EventHandler(_WebLogManagerForm_Closed);
			if( !_WebLogManagerForm.Disposing )
				_WebLogManagerForm.Dispose();
		}


		private static void _WebLogManagerForm_SendFeeds(object sender, EventArgs e)
		{
			RSSHelper.DownloadChannels( _WebLogManagerForm, new ArrayList(), new EventHandler( _WebLogManagerForm.DownloadCompleteEventHandler ), true );
		}
		#endregion

		#region Blogpaper Handling

		private static Newspaper _NewspaperForm;

		public static void ShowNewspaper( int channelId )
		{
			if( null != _NewspaperForm )
			{
				_NewspaperForm.Show();
				_NewspaperForm.ShowChannel( channelId );
			}
			else
			{
				_NewspaperForm = new Newspaper();
				_NewspaperForm.Show();
				_NewspaperForm.ShowChannel( channelId );
				
				_NewspaperForm.Closed += new EventHandler(_NewspaperForm_Closed);
				_NewspaperForm.Disposed += new EventHandler(_NewspaperForm_Disposed);
			}
		}

		/// <summary>
		/// When the mainform is disposed, detach from it to release it completely
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private static void _NewspaperForm_Disposed(object sender, EventArgs e)
		{
			_NewspaperForm.Disposed -= new EventHandler(_NewspaperForm_Disposed);
			_NewspaperForm = null;

			MemoryHelper.ReduceMemory();
		}

		/// <summary>
		/// When the main form is closed, dispose it
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private static void _NewspaperForm_Closed(object sender, EventArgs e)
		{
			_NewspaperForm.Closed -= new EventHandler(_NewspaperForm_Closed);
			if( !_NewspaperForm.Disposing )
				_NewspaperForm.Dispose();

			MemoryHelper.ReduceMemory();
		}


		public static void CloseNewspaper( )
		{
			if( null != _NewspaperForm )
				_NewspaperForm.Close();
		}

		#endregion

		#region Global Exception handling

		private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
		{
			EntLibHelper.UnhandledException(e.Exception);
		}

		private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
		{
			if( e.ExceptionObject is Exception )
				EntLibHelper.UnhandledException(e.ExceptionObject as Exception);
		}

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

Share

About the Author

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 16 Aug 2005
Article Copyright 2005 by Omar Al Zabir
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid