Click here to Skip to main content
11,438,226 members (55,037 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
Add your own
alternative version

FrameControl - Framework for creating web applications

, 25 Jul 2003
FrameControl is a framework that contains the code common for most of the web applications.
FrameControl_demo.zip
FrameControl1.dll
doc
banner.jpg
darkcorner.jpg
FrameControl1
gradleft.jpg
gradtop.jpg
graycorner.jpg
minus.jpg
plus.jpg
titletile.jpg
FrameControl_src.zip
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.Reflection;
using System.Xml;

namespace JobMorning
{
	/// <summary>
	/// ActionClassContainer deals with the collection of objects of type ActionClass during the application 
	/// life. It is also a wrapper for all ActionClass functions that can call the methods of a specific 
	/// ActionClass using its page name reference.
	/// </summary>
	public class ActionClassContainer
	{
		// contains all instantiated children of the base class ActionClass.
		private Hashtable actionClassObjects;
		// contains the type of all ActionClass objects.
		private Hashtable actionClassTypes;

		// reference to the current Session Object
		private System.Web.SessionState.HttpSessionState sessionObject;
		
		public ActionClassContainer()
		{
			actionClassObjects = new Hashtable();
			actionClassTypes = new Hashtable();
		}
		
		/// <summary>
		/// Instatiate a class inheriting the base class ActionClass using the class name.
		/// Associates this new created class with an a page name.
		/// </summary>
		/// <param name="strActionClassName"></param>
		/// <returns>returns true if the class inheriting from ActionClass could be created successfully.</returns>
		public bool InstantiateActionClass(string strActionClassName, string strPage)
		{
			if (actionClassObjects[strPage]==null)
			{
				// object anActionClass;
				// anActionClass = Activator.CreateInstance(strActionClassName, "JobMorning.ActionClass");
			
				// Load the generated assembly into the ApplicationDomain 
				
					Object anActionClass;
					Type t = null;
					try
					{
						foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
						{
							t = asm.GetType(strActionClassName);
						
							if (t!=null)
							{
								anActionClass = Activator.CreateInstance(t);
								actionClassObjects.Add(strPage, anActionClass);
								actionClassTypes.Add(strPage, strActionClassName);
							} // if (t!=null)
						}
						return true;
					}
					catch (System.Reflection.TargetInvocationException e)
					{
						sessionObject["ERROR"]="The ActionClass "+strActionClassName+" could not be instantiated.";
						sessionObject["ERROR"]+="The constructor of the object class threw an exception. ";
						return false;
					}
					catch (System.ArgumentNullException)
					{
						sessionObject["ERROR"]="The type of "+strActionClassName+" could not be found in the ";
						sessionObject["ERROR"]+="running assembly. Make sure the type exists.";
						return false;
					}

				return false;
				/*
				// BindingFlags enumeration specifies flags that control binding and 
				// the way in which the search for members and types is conducted by reflection. 
				// The following specifies the Access Control of the bound type	
	
				BindingFlags bflags = BindingFlags.DeclaredOnly | BindingFlags.Public 
					| BindingFlags.NonPublic | BindingFlags.Instance;

				// Construct an instance of the type and invoke the member method	
				Object anActionClass = t.InvokeMember("doBeforeLoad", bflags | 
					BindingFlags.CreateInstance, null, null, null);
				*/
			
			}
			else
			{
				// ActionClass already instantiated.
				return false;
			}
		}

		/// <summary>
		/// Deletes an ActionClass associated to a page.
		/// </summary>
		/// <param name="strPage">The page name.</param>
		/// <returns></returns>
		public bool DisposeActionClass(string strPage)
		{
			bool rtnBool = true;
			rtnBool = actionClassObjects.Contains(strPage);
			actionClassObjects.Remove(strPage);
			return rtnBool;
		}
		
		/// <summary>
		/// Procedure called before the page mentionned in the XML file is loaded and displayed.
		/// </summary>
		public void DoBeforeDisplay(string strPage, string strXmlMCContext)
		{
			object anActionClass = actionClassObjects[strPage];
			string strType = (string)actionClassTypes[strPage];
			
			if (anActionClass!=null)
			{
				// Load the generated assembly into the ApplicationDomain 
				Type t;
				foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
				{
					t = asm.GetType(strType);
						
					if (t!=null)
					{
						// BindingFlags enumeration specifies flags that control binding and 
						// the way in which the search for members and types is conducted by reflection. 
						// The following specifies the Access Control of the bound type

						BindingFlags bflags = BindingFlags.DeclaredOnly | BindingFlags.Public 
							| BindingFlags.NonPublic | BindingFlags.Instance;
						string[] allParams = new string[1];
						allParams[0]=strXmlMCContext;
						// Call the method
						t.InvokeMember("DoBeforeDisplay", bflags | BindingFlags.InvokeMethod,
							null, anActionClass,allParams);
						break;
					} // if (t!=null)
				}
				
			}
		}
		
		
		/// <summary>
		/// doPageValidation validates the page input. 
		/// If the result is false, the page is displayed again with a PopUp message containing
		/// strErrorMessage. If no ActionClass is associated to the page, returns the value true.
		/// </summary>
		public bool ValidatePageBeforeSavePoints(string strPage,Hashtable pageInputs, out string strErrorMessage)
		{
			object anActionClass = actionClassObjects[strPage];
			string strType = (string)actionClassTypes[strPage];
			strErrorMessage = "";

			if (anActionClass!=null)
			{
				// Load the generated assembly into the ApplicationDomain 
				
				Type t;
				foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
				{
					t = asm.GetType(strType);
						
					if (t!=null)
					{

						// BindingFlags enumeration specifies flags that control binding and 
						// the way in which the search for members and types is conducted by reflection. 
						// The following specifies the Access Control of the bound type

						BindingFlags bflags = BindingFlags.DeclaredOnly | BindingFlags.Public 
							| BindingFlags.NonPublic | BindingFlags.Instance;
		
						object[] allParams = new object[2];
						allParams[0]=pageInputs;
						allParams[1]=strErrorMessage;
						// Call the method
						object boolRslt = t.InvokeMember("ValidatePageBeforeSavePoints", bflags | BindingFlags.InvokeMethod,
							null, anActionClass,allParams);
						strErrorMessage = (string)allParams[1];

						return ((bool)boolRslt);
					} // if (t!=null)
				} // foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
				return false;

				
			} // if (anActionClass!=null)
			else
			{
				return true;
			}
		}
		

		/// <summary>
		/// ValidatePageAfterSavePoint validates the page input after a savePoint has been executed.
		/// The savePoint must be contained in the current path between the current page and its successor.
		/// </summary>
		public bool ValidatePageAfterSavePoint(string strPage, string strSavePointName, string strXmlMCContext, out string strErrorMessage)
		{
			strErrorMessage = "";
			object anActionClass = actionClassObjects[strPage];
			string strType = (string)actionClassTypes[strPage];
			
			if (anActionClass!=null)
			{
				
				Type t;
				foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
				{
					t = asm.GetType(strType);
						
					if (t!=null)
					{

						// BindingFlags enumeration specifies flags that control binding and 
						// the way in which the search for members and types is conducted by reflection. 
						// The following specifies the Access Control of the bound type

						BindingFlags bflags = BindingFlags.DeclaredOnly | BindingFlags.Public 
							| BindingFlags.NonPublic | BindingFlags.Instance;

						object[] allParams = new object[3];
						allParams[0]=strSavePointName;
						allParams[1]=strXmlMCContext;
						allParams[2]= strErrorMessage;

						// Call the method
						object boolRslt = t.InvokeMember("ValidatePageAfterSavePoint", bflags | BindingFlags.InvokeMethod,
							null, anActionClass,allParams);
						strErrorMessage = (string)allParams[2];

						return ((bool)boolRslt);
					} // if (t!=null)
				} // foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
				return false;
				
			} // if (anActionClass!=null)
			else
			{
				return true;
			}
		}
		

		/// <summary>
		/// Procedure called after the page has been posted and that all values have been saved
		/// into the context. This procedure is executed after ValidatePageBeforeSavePoints.
		/// </summary>
		public void DoAfterContextSave(string strPage, string strXmlMCContext)
		{
			object anActionClass = actionClassObjects[strPage];
			string strType = (string)actionClassTypes[strPage];
			
			if (anActionClass!=null)
			{
				// Load the generated assembly into the ApplicationDomain 
				
				Type t;
				foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
				{
					t = asm.GetType(strType);
						
					if (t!=null)
					{

						// BindingFlags enumeration specifies flags that control binding and 
						// the way in which the search for members and types is conducted by reflection. 
						// The following specifies the Access Control of the bound type

						BindingFlags bflags = BindingFlags.DeclaredOnly | BindingFlags.Public 
							| BindingFlags.NonPublic | BindingFlags.Instance;

						string[] allParams = new string[1];
						allParams[0]=strXmlMCContext;
						// Call the method
						t.InvokeMember("DoAfterContextSave", bflags | BindingFlags.InvokeMethod,
							null, anActionClass,allParams);
						break;
					} // if (t!=null)
				} // foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
			}
		}
	}
}

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

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