Click here to Skip to main content
13,191,400 members (77,090 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads

Stats

73.6K views
40 bookmarked
Posted 25 Jul 2003

FrameControl - Framework for creating web applications

, 25 Jul 2003
FrameControl is a framework that contains the code common for most of the web applications.
FrameControl1.dll
doc
banner.jpg
darkcorner.jpg
FrameControl1
gradleft.jpg
gradtop.jpg
graycorner.jpg
minus.jpg
plus.jpg
titletile.jpg
banner.jpg
darkcorner.jpg
gradleft.jpg
gradtop.jpg
graycorner.jpg
minus.jpg
plus.jpg
titletile.jpg
obj
Debug
temp
TempPE
Release
FrameControl1.dll
FrameControl1.projdata
temp
TempPE
FrameControl1.csproj.user
FrameControl_install.zip
using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.Xml;
using System.Globalization;
using System.Threading;
using System.Configuration;
using System.Net;

namespace JobMorning
{
	/// <summary>
	/// The base class for the global.asax web application using the FrameControl framework
	/// component. The methods of the global.asax file should call the base class while giving
	/// the same parameters.
	/// </summary>
	public class Global : System.Web.HttpApplication
	{
		public Global()
		{
			InitializeComponent();
		}	
		
		private ActionClassContainer theContainer;

		/// <summary>
		/// The Application_Start method will look for the keys defined in the appSettings node of the 
		/// web.config file using the FrameControl framework. The keys that is needed for this function is
		/// APP_ALLPATHS. 
		/// </summary>
		public void ApplicationStart(Object sender, EventArgs e)
		{
			
			
			
			theContainer = new ActionClassContainer();
			Application.Add("ActionClasses",theContainer);
			
			bool isAllKeysDefined = true;
			// First thing to do: test if the good variables have been defined in 
			// Web.config. 
			// The variables to store the results are the following ones:
			ArrayList configKeys = new ArrayList();
			configKeys.Add("APP_ALLPATHS");
			configKeys.Add("APP_STOREDPROCEDURES");
			configKeys.Add("APP_SAVEPOINTS");
			configKeys.Add("APP_PAGECONTROLS");
        
			//display
			string strKey;
			string strKeyDefined;
			foreach(object item in configKeys) 
			{
				strKey = item.ToString(); 
				strKeyDefined = strKey+"_DEFINED";
				if ((ConfigurationSettings.AppSettings[strKey]!="")
					&&(ConfigurationSettings.AppSettings[strKey]!=null))
				{
					Application[strKeyDefined]="TRUE";
				}
				else
				{
					Application[strKeyDefined]="Please add a key "+strKey+" with value set to your XML document path in Web.Config";
					isAllKeysDefined = false;
				}
			}

			if (isAllKeysDefined)
			{
				Application["ERROR"]="FALSE";
				// Stores the UserPaths description in the application context
				string strFileName = ConfigurationSettings.AppSettings["APP_ALLPATHS"];
				string strXmlUserPathDoc = Server.MapPath(strFileName);
				XmlDocument docUserPaths= new XmlDocument();
				try
				{
					docUserPaths.Load(strXmlUserPathDoc);
					Application["userPaths"]=docUserPaths;
					// In the application, we need to know how many paths have been 
					// defined
					XmlNodeList allPaths = docUserPaths.DocumentElement.SelectNodes("//Path");
				

					//Creates the ApplicationTransit object and stores it in the 
					// application context
					JobMorning.ApplicationTransit apptt = new JobMorning.ApplicationTransit(allPaths.Count);
					Application.Add("ApplicationTransit",apptt);
				} 
				catch (System.IO.FileNotFoundException ex)
				{
					Session["ERROR"]="The file defined in APP_SAVEPOINTS was not found.";
				}
				catch (System.Xml.XmlException ex)
				{
					Application["ERROR"]="Error while loading the XML file defined in APP_ALLPATHS.";
					Application["ERROR"]+= @"<BR/>";
					Application["ERROR"]+= @"The XML document should have the following structure:";
					Application["ERROR"]+= @"<BR/>";
					Application["ERROR"]+= @"&#0060;AllPaths&#0062;";
					Application["ERROR"]+= @"<BR/>";
					Application["ERROR"]+= @"   &#0060;Path number=""0"" Name=""default""&#0062;";
					Application["ERROR"]+= @"<BR/>";
					Application["ERROR"]+= @"       &#0060;Page Name=""firstpage""/&#0062;";
					Application["ERROR"]+= @"<BR/>";
					Application["ERROR"]+= @"   &#0060;/Path&#0062;";
					Application["ERROR"]+= @"<BR/>";
					Application["ERROR"]+= @"&#0060;/AllPaths&#0062;";
				}
			
				strFileName = ConfigurationSettings.AppSettings["APP_STOREDPROCEDURES"];
				string strXmlDoc = Server.MapPath(strFileName);			
				XmlDocument doc = new XmlDocument();
				doc.Load(strXmlDoc);
				XmlNodeList listStoredProc = doc.SelectNodes("//sproc");

				Application.Add("SprocParameters",doc);
				Application.Add("SprocParametersFile",strXmlDoc);
			} // if (isAllKeysDefined)
		}

		/// <summary>
		/// The Session_Start method will look for the keys defined in the appSettings node of the 
		/// web.config file using the FrameControl framework. The keys that are needed for this function are:
		/// APP_REDIRECTERROR, APP_STOREDPROCEDURES, APP_SAVEPOINTS, APP_PAGECONTROLS,
		/// APP_DEFAULTPAGE.
		/// </summary>
		public void SessionStart(Object sender, EventArgs e)
		{

			// Load the XML files SprocsParameters and PageControl 
			// in the Session object
			// Load the sprocParameters xml file in session
			
			Session["ERROR"]="FALSE";
			
			string strFileName = ConfigurationSettings.AppSettings["APP_SAVEPOINTS"];
			string strXmlDBSavePoints = Server.MapPath(strFileName);
			try
			{
				XmlDocument doc3 = new XmlDocument();
				doc3.Load(strXmlDBSavePoints);
				XmlNodeList listSavePoints = doc3.SelectNodes("//SavePoint");
			
				Session["DBSavePoints"]=doc3;
			}
			catch (System.IO.FileNotFoundException ex)
			{
				Session["ERROR"]="The file defined in APP_SAVEPOINTS was not found.";
			}
			catch (System.Xml.XmlException ex)
			{
				Session["ERROR"]="Error while loading the XML file defined in APP_SAVEPOINTS.";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"The XML document should have the following structure:";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&#0060;DBSavePoints&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&nbsp;&#0060;SavePoint Name=""signup""&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&nbsp;&nbsp;&#0060;Procedure&#0062;CreateUserOnline&#0060;/Procedure&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&nbsp;&nbsp;&nbsp;&#0060;InputParams&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&nbsp;&nbsp;&nbsp;&nbsp;&#0060;Param&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#0060;DBControl&#0062;registrationJS.login&#0060;/DBControl&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#0060;DBParam&#0062;@login&#0060;/DBParam&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&nbsp;&nbsp;&nbsp;&nbsp;&#0060;/Param&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&nbsp;&nbsp;&nbsp;&#0060;/InputParams&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&nbsp;&nbsp;&#0060;/SavePoint&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&#0060;/DBSavePoints&#0062;";

			}
			// Load the PageControl XML file into the Session object
			strFileName = ConfigurationSettings.AppSettings["APP_PAGECONTROLS"];
			string strXmlDoc2 = Server.MapPath(strFileName);
			XmlDocument doc2= new XmlDocument();
			try
			{
				doc2.Load(strXmlDoc2);
				XmlNodeList listPages = doc2.SelectNodes("//Page");
				Session["PageControls"]=doc2;
			}
			catch (System.IO.FileNotFoundException ex)
			{
				Session["ERROR"]="The file defined in APP_SAVEPOINTS was not found.";
			}
			catch (System.Xml.XmlException ex)
			{
				Session["ERROR"]="Error while loading the XML file defined in APP_PAGECONTROLS.";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"The XML document should have the following structure:";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&#0060;PageControls&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&nbsp;&#0060;menuControl&#0062;myMenu&#0060;/menuControl&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&nbsp;&#0060;Page Name=""firstpage""&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&nbsp;&nbsp;&#0060;PlaceHolderArray&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @" &nbsp;&nbsp;&nbsp;&#0060;tr&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&nbsp;&nbsp;&nbsp;&nbsp;&#0060;td align=""center""&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#0060;name&#0062;UserControl name&#0060;/name&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&nbsp;&nbsp;&nbsp;&nbsp;&#0060;/td&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&nbsp;&nbsp;&nbsp;&#0060;/tr&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&nbsp;&nbsp;&#0060;/PlaceHolderArray&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @" &nbsp;&#0060;/Page&#0062;";
				Session["ERROR"]+= @"<BR/>";
				Session["ERROR"]+= @"&#0060;/PageControls&#0062;";

			}
			// Store all the pages the user viewed when he browse
			Session["UserTrack"]="";

			// Instantiate the SessionTransit object
			JobMorning.SessionTransit mySessionTransit = new JobMorning.SessionTransit();
			Session.Add("SessionTransit", mySessionTransit);

			//Initialize the page number to the first page
			string strFirstPage = ConfigurationSettings.AppSettings["APP_DEFAULTPAGE"];
			
			Session["CurrentPage"]=strFirstPage;
			
			//Initialize the Cu

			// Defines the path variable to switch paths using the menu
			Session["pathRequest"] = "";

			// Defines the page variable for switching to another page
			Session["pageRequest"] = "";

			// Define the treeConfig XML string by default
			string strDefaultTree = "";
			strDefaultTree += "<root></root>";
		}
		
		/// <summary>
		/// The Application_BeginRequest sets the CurrentCulture for the user local settings.
		/// (examples of CurrentCultures are English-UK - English-US - French-FR - Japanese-JP).
		/// The Culture Preference should be set in a cookie named "CulturePref".
		/// If no Coookie has been set, the CurrentCulture is set by default to en-GB
		/// </summary>
		public void ApplicationBeginRequest(Object sender, EventArgs e)
		{
			string culturePref ="en-GB";
			if (Request.Cookies["CulturePref"] != null)
			{
				culturePref = Request.Cookies["CulturePref"].Value;
			}
			try
			{
				Thread.CurrentThread.CurrentCulture = 
					CultureInfo.CreateSpecificCulture
					(culturePref);
			}
			catch
			{
				Thread.CurrentThread.CurrentCulture = 
					new CultureInfo("en-GB");
			}
			Thread.CurrentThread.CurrentUICulture = 
				Thread.CurrentThread.CurrentCulture;

		}
		#region Web Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
		}
		#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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

S. Jehan
Japan Japan
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171017.1 | Last Updated 26 Jul 2003
Article Copyright 2003 by S. Jehan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid