Click here to Skip to main content
15,894,646 members
Articles / Programming Languages / C#

The Application Automation Layer - Using XML to generate Menus

Rate me:
Please Sign up or sign in to vote.
4.81/5 (56 votes)
5 May 200313 min read 238.8K   2.6K   194  
Exploring the issues of menu management as specified externally via an XML file, in the context of status bars, toolbars, and events.
using System;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using AAL;

namespace AAL
{
	public class BootstrapLoader
	{
		static ICore.IComponentManager icm;

		static void Main(string[] args) 
		{
			Dbg.Initialize();

			Dbg.Problems.Add(
				new DbgKey("NullValueError"),
				"",
				new String[] {"A null value was encountered."});


			MethodInfo mi=Lib.Methods.GetMethodInfo("ComponentManager.dll/AAL.ComponentManager/Init1");
			icm=mi.Invoke(null, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.InvokeMethod | BindingFlags.Static, null, null, null) as ICore.IComponentManager;
			icm.InitializeComponents();

			// typical application functions
			icm.RegisterInterfacePoint("App", "Exit", new InterfacePoint(AppExit));

			// test workflow domain and data set creation

//***
			icm.Invoke("TestComponent.Test", null);
			
			ICore.IWorkflowManager iwm=icm.GetInterface("WorkflowManager") as ICore.IWorkflowManager;
			ICore.IDataHub idh=icm.GetInterface("DataHub") as ICore.IDataHub;

			idh.LoadDomainSpecifications("dataDomain.xml");
			idh.CreateWorkflowDomain("SingleItemSaleOrder");
			idh.LoadInitialLoadSet("SingleItemSaleOrder", "RetailPrice");
//***
		
			// Application Initialization

			DataTable dt=Lib.Xml.GetTable("appInfo.xsd", args[0], "//AppInfo");
			string formListFile=dt.Rows[0]["FormFile"] as string;
			string mainFormName=dt.Rows[0]["MainFormName"] as string;
			string menuFile=dt.Rows[0]["MenuFile"] as string;
			string appType=dt.Rows[0]["AppType"] as string;
			string appIcon=dt.Rows[0]["AppIcon"] as string;

			EventData ev=EventData.Marshal(new MED[] {new MED("FormList", formListFile)});
			icm.Invoke("WindowFormManager.LoadForms", ev);

			ev=EventData.Marshal(new MED[] {new MED("MenuDefFile", menuFile)});
			icm.Invoke("MenuMgr.LoadMenus", ev);

			ev=EventData.Marshal(new MED[] {new MED("FormName", mainFormName), new MED("AppIcon", appIcon)});
			switch(appType)
			{
				case "Dialog":
					icm.Invoke("FormMgr.CreateDlgApp", ev);
					break;

				case "Single Document":
					icm.Invoke("FormMgr.CreateSDIApp", ev);
					break;

				case "Multi Document":
					icm.Invoke("FormMgr.CreateMDIApp", ev);
					break;
			}
			icm.Invoke("FormMgr.ShowForm", ev);

			ev=EventData.Marshal(new MED[] {new MED("FormName", mainFormName), new MED("MenuName", "MainMenu")});
			icm.Invoke("MenuMgr.AssignMenu", ev);

			// create child forms
			// ******************* Window selection of child forms is broken **********************

			ev=EventData.Marshal(new MED[] {new MED("ParentFormName", "MDI1"), new MED("FormName", "MDIChild1")});
			icm.Invoke("FormMgr.AddMDIChild", ev);
			icm.Invoke("FormMgr.ShowForm", ev);

			ev=EventData.Marshal(new MED[] {new MED("ParentFormName", "MDI1"), new MED("FormName", "MDIChild2")});
			icm.Invoke("FormMgr.AddMDIChild", ev);
			icm.Invoke("FormMgr.ShowForm", ev);

			// ******************** Menu State Test ******************

			ev=EventData.Marshal(new MED[] {new MED("MenuItemName", "TileH"), new MED("State", false)});
			icm.Invoke("MenuMgr.SetState", ev);


			// Testing
//			ev=EventData.Marshal(new MED[] {new MED("FormName", "MainPanelForm"), new MED("ControlSetName", "CheckInCS")});
//			icm.Invoke("FormMgr.LoadControlSet", ev);
/*
			// simple MDI test

			EventData ev=EventData.Marshal(new MED[] {new MED("FormList", "TestFormList.xml")});
			icm.Invoke("WindowFormManager.LoadForms", ev);

			ev=EventData.Marshal(new MED[] {new MED("MenuDefFile", "menus.xml")});
			icm.Invoke("MenuMgr.LoadMenus", ev);

			ev=EventData.Marshal(new MED[] {new MED("FormName", "MDI1"), new MED("AppIcon", "ka.ico")});
			icm.Invoke("FormMgr.CreateMDIApp", ev);
			icm.Invoke("FormMgr.ShowForm", ev);

			ev=EventData.Marshal(new MED[] {new MED("ParentFormName", "MDI1"), new MED("FormName", "MDIChild1")});
			icm.Invoke("FormMgr.AddMDIChild", ev);
			icm.Invoke("FormMgr.ShowForm", ev);

			ev=EventData.Marshal(new MED[] {new MED("ParentFormName", "MDI1"), new MED("FormName", "MDIChild2")});
			icm.Invoke("FormMgr.AddMDIChild", ev);
			icm.Invoke("FormMgr.ShowForm", ev);
			
			ev=EventData.Marshal(new MED[] {new MED("FormName", "MDI1"), new MED("MenuName", "MainMenu")});
			icm.Invoke("MenuMgr.AssignMenu", ev);
*/
			// DBY example
/*
			EventData ev=EventData.Marshal(new MED[] {new MED("FormList", "BoatYardFormList.xml")});
			icm.Invoke("WindowFormManager.LoadForms", ev);
			
			ev=EventData.Marshal(new MED[] {new MED("MenuDefFile", "menus.xml")});
			icm.Invoke("MenuMgr.LoadMenus", ev);

			ev=EventData.Marshal(new MED[] {new MED("FormName", "MainForm")});
			icm.Invoke("FormMgr.CreateSDIApp", ev);
			icm.Invoke("FormMgr.ShowForm", ev);

			ev=EventData.Marshal(new MED[] {new MED("FormName", "MainForm"), new MED("MenuName", "MainMenu")});
			icm.Invoke("MenuMgr.AssignMenu", ev);
*/
			Application.Run();
		}

		static object AppExit(EventData ev)
		{
			icm.Invoke("FormMgr.CloseAll", null);
			Application.Exit();
			return null;
		}
	}
}

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


Written By
Architect Interacx
United States United States
Blog: https://marcclifton.wordpress.com/
Home Page: http://www.marcclifton.com
Research: http://www.higherorderprogramming.com/
GitHub: https://github.com/cliftonm

All my life I have been passionate about architecture / software design, as this is the cornerstone to a maintainable and extensible application. As such, I have enjoyed exploring some crazy ideas and discovering that they are not so crazy after all. I also love writing about my ideas and seeing the community response. As a consultant, I've enjoyed working in a wide range of industries such as aerospace, boatyard management, remote sensing, emergency services / data management, and casino operations. I've done a variety of pro-bono work non-profit organizations related to nature conservancy, drug recovery and women's health.

Comments and Discussions