//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;

namespace CommunityServer.Components
{
	/// <summary>
	/// Summary description for CSCatastrophicMessageModule.
	/// </summary>
	public class CSCatastrophicExceptionModule : ICSModule	
	{
		public CSCatastrophicExceptionModule()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		#region ICSModule Members

		public void Init(CSApplication csa, System.Xml.XmlNode node)
		{
			csa.CSException +=new CSExceptionHandler(csa_CSException);
		}

		#endregion

		private void csa_CSException(CSException csEx, CSEventArgs e)
		{
			CSContext csContext = CSContext.Current;
			if(csContext.IsWebRequest)
			{
				switch (csEx.ExceptionType) 
				{
					case CSExceptionType.DataProvider:
						CatastrophicMessage.Write(csContext.Context,csEx,"[DATASTOREEXCEPTION]","DataStoreUnavailable.htm");
						break;
					case CSExceptionType.UnRegisteredSite:
						CatastrophicMessage.Write(csContext.Context,csEx,"[MissingSettingsID]","SiteIDUnavailable.htm");
						break;
					case CSExceptionType.SiteUrlDataProvider:
						CatastrophicMessage.Write(csContext.Context,csEx,"[SiteUrlData]","SiteUrlData.htm");
						break;
				}
			}
		}
	}
}
