using System;
using System.Windows.Forms;
using System.Threading;
using Microsoft.Win32;
using Microsoft.ApplicationBlocks.ExceptionManagement;
using System.Reflection;

namespace Northwind
{
	/// <summary>
	/// Summary description for MainClass.
	/// </summary>
	public class MainClass
	{
		public static void Main(string[] args)
		{
			#region Install ThreadException
			Application.ThreadException += new 
				ThreadExceptionEventHandler(
				MainUIThreadExceptionHandler);
			#endregion
			
			System.Windows.Forms.Application.Run(
				new NorthwindMDIMain());
		}

		#region MainUIThreadExceptionHandler
		public static void MainUIThreadExceptionHandler(
			Exception e)
		{
			MainUIThreadExceptionHandler(null, new System.Threading.
				ThreadExceptionEventArgs(e));
		}

		public static void MainUIThreadExceptionHandler(object
			sender, ThreadExceptionEventArgs t)
		{

			ExceptionManager.Publish(t.Exception);

			//Tell the user a boo-boo occurred...
			MessageBox.Show(
				"Northwind Orders has encountered the following "
				+ " problem:" + (char)13
				+ (char)13 + t.Exception.Message
				+ (char)13 + (char)13 
				+ "Please contact your administrator or the "
				+ "Northwind Help desk at "
				+ (char)13 + (char)13 +"1-855-555-5555."
				+ (char)13 + (char)13 
				+ "We apologize for the inconvenience."
				, "Northwind Orders Encountered a Problem"
				, MessageBoxButtons.OK
				, MessageBoxIcon.Error
				, MessageBoxDefaultButton.Button1 
				, MessageBoxOptions.ServiceNotification);		
		}

		#endregion

		//TODO:  Create a WriteInstalledVersion method
		public static void WriteInstalledVersion()
		{
			RegistryAccess ra = new RegistryAccess();

			ra.WriteRegistryValue("Installed Version"
				, Assembly.GetExecutingAssembly().GetName().
				Version.ToString());
		}
	}
}

