home *** CD-ROM | disk | FTP | other *** search
Wrap
<% /*===================================================================== File: TOC.aspx Summary: Brief summary of the file contents and purpose. --------------------------------------------------------------------- This file is part of the Microsoft NGWS SDK Code Samples. Copyright (C) 2000 Microsoft Corporation. All rights reserved. This source code is intended only as a supplement to Microsoft Development Tools and/or on-line documentation. See these other materials for detailed information regarding Microsoft code samples. THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. =====================================================================*/ %> <%@ Page Language="C#" %> <%@ Import Namespace="System" %> <%@ Import Namespace="System.Reflection"%> <%@ Import Namespace="System.Collections"%> <%@ Import Namespace="System.IO"%> <%@ Import Namespace="System.Data"%> <%@ Import Namespace="System.Data.XML"%> <%@ Import Namespace="System.Data.XML.DOM"%> <HTML> <HEAD> <TITLE>Contents</TITLE> <STYLE TYPE="text/css"> UL.toc {cursor:hand} /* Set image for the bulleted list. */ UL.toc UL {list-style:none} /* Hide the child elements by default. */ UL.toc UL {display:none} /* Display the child elements. */ UL.toc UL.expanded {display:block} </STYLE> <style type="text/css"> @import url(backTOC1.css); </style> <BASE TARGET="DEMO"> <SCRIPT LANGUAGE="JavaScript"> var curSelection = null; function setStyle(src, toClass) { // Format the element to the specified class. if (null != src) src.className = toClass; } function mouseEnters() { // Be sure the element is not the current selection and // that it is an anchor. if ((curSelection != event.toElement) && ("A" == event.toElement.tagName)) setStyle(event.toElement,"over"); } function mouseLeaves() { // Again, be sure the element is not the current selection // and that it is an anchor. if ((curSelection != event.fromElement) && ("A" == event.fromElement.tagName)) setStyle(event.fromElement, ""); } function outliner() { var child = null, el = null; /* Assumes that the DIV containing the child elements immediately follows the heading anchor. */ switch (event.srcElement.tagName) { case "H6": el = event.srcElement.parentElement; child = document.all[event.srcElement.sourceIndex + 1]; break; case "LI": el = event.srcElement; child = document.all[event.srcElement.sourceIndex + 2]; break; } /* Be sure the child element exists and that it is the child LI. */ if ((null != child) && ("UL" == child.tagName) && ("LI" == child.parentElement.tagName)) { if ("" == child.className) { // Collapse the item. child.className = "expanded"; el.className = "open"; } else { // Expand the item. child.className = ""; el.className = "closed"; } } if ("A" == event.srcElement.tagName) { if (null != curSelection) setStyle(curSelection, ""); // Save and highlight new selection. curSelection = event.srcElement; setStyle(curSelection, "select"); } } </SCRIPT> <script runat=server> private Hashtable Hash; private String[] Namespaces; private int Pivot; private ArrayList Assemblies = null; void Page_Load(Object sender, EventArgs e){ if (Request.Form.Count > 0){ if (Request.Form["Remove"] != null){ Assemblies = ((ArrayList)Session["Assems"]); // if Remove, then parse the line to break it up into a string[]. string unparsedassems = Request.Form["Remove"]; Char[] separators = {','}; string[] ParsedAssems = unparsedassems.Split(separators); for (int index = 0; index < ParsedAssems.Length; ++index){ if (Assemblies.IndexOf(ParsedAssems[index]) != -1) Assemblies.Remove(ParsedAssems[index]); } Session["Assems"] = Assemblies; } else if (Request.Form["Add"] != null){ LoadModule(Request.Form["Add"]); } } else if (Request.QueryString.Count > 0 && Request.QueryString["Add"] != null){ string File = Request.QueryString["Add"]; LoadModule(Directory.Combine(Request.QueryString["CurrentDir"], Request.QueryString["Add"])); Response.Write("Command is to Add: <BR/> \"" + Directory.Combine(Request.QueryString["CurrentDir"], Request.QueryString["Add"]) + "\"<BR>"); } else{ // Write the function that loads the assemblies into Session State. // Then modify below to load assemblies from state, rather than from strings. // Then when you modify state, the toc will always reload the newly modified // state. LoadInitialState(Session); } System.Collections.Hashtable hash = PopulateHash(); hash = Alphabetize(hash); string[] tempkeys = new string[hash.Keys.Count]; hash.Keys.CopyTo(tempkeys, 0); Namespaces = (string[])tempkeys; Array.Sort(Namespaces); Hash = hash; } /* LoadModule attempts to load an assembly and if it can, adds the load string to the session TOC state. If it's unsuccessful, it writes an error and returns. First it attempts to load using the ModulePath as a known assembly name. If that fails, it attempts to load using the ModulePath as a fully qualified path name. */ private void LoadModule(string ModulePath){ Assembly NewAssembly = null; try{ // if you just happen to know the Assembly name and it's discoverable. if ((NewAssembly = Assembly.Load(ModulePath)) == null){ NewAssembly = Assembly.LoadFrom(ModulePath); if (NewAssembly == null){ Page.Response.Write(ModulePath + " does not resolve to a NGWS SDK assembly.<BR>"); // so it does nothing if it couldn't find your thingie. It should write an error. return; } } // if you got here, NewAssembly did resolve to a NGWS SDK assembly. Assemblies = ((ArrayList)Session["Assems"]); Assemblies.Add(ModulePath); Session["Assems"] = Assemblies; } catch(Exception Ex){ ; } } private void LoadInitialState(HttpSessionState AssemblyState){ // Load the session state with all the assemblies. Assemblies = new System.Collections.ArrayList(); // Create your XmlReader for the file string StaticAssembliesPath = Request.PhysicalApplicationPath + "Assemblies.xml"; XmlReader XReader = new XmlReader(StaticAssembliesPath); XmlDocument XMLDoc = new XmlDocument(); // XmlDocuments require an XmlReader to load if you don't have a DataSet. // load the XmlReader for this file XMLDoc.Load(XReader); // Get an XML DOM-based document -- party from here in the standard way. // if you're not going to use XmlReader and XmlWriter and DataNavigator. IDocument IDoc = XMLDoc.DomDocument; IElement docElement = IDoc.documentElement; INodeList Nodes = docElement.getElementsByTagName("Assembly"); INode ThisNode = null; while((ThisNode = Nodes.nextNode) != null){ Assemblies.Add(ThisNode.text); //this.Response.Write("Added: " + ThisNode.text + "<BR>"); } AssemblyState["Assems"] = Assemblies; } private System.Collections.Hashtable PopulateHash(){ System.Collections.Hashtable hash = new System.Collections.Hashtable((int)Math.Pow((double)2,(double)5)); Assemblies = (ArrayList)(Session["Assems"]); if (Assemblies == null){ throw new NullReferenceException("Unable to retrieve the AssemState[\"Assems\"] state variable."); } Assembly ThisAssembly = null; for (int i = 0; i < Assemblies.Count; ++i) { try{ ThisAssembly = Assembly.Load((string)Assemblies[i]); } catch(Exception Ex){ throw new Exception("Error trying to load assembly \"" + (string)Assemblies[i], Ex); continue; } Module[] ModuleArray; if (ThisAssembly == null){ Response.Write(((string)Assemblies[i]) + " was null.<BR>"); continue; } ModuleArray = ThisAssembly.GetModules(); for (int k = 0; k < ModuleArray.Length; ++k){ try { if (ModuleArray == null || ModuleArray[k] == null) { continue; } else { Type[] types = ModuleArray[k].GetTypes(); for(int j = 0; j < types.Length; j++) { try{ if (types[j] == null || !types[j].IsPublic) continue; String key = types[j].Namespace; if (key == null) key = String.Empty; if (hash.ContainsKey(key)) { hash[key] = String.Format("{0}{1};", (string)hash[key], types[j].Name); } else { hash.Add(key, String.Format("{0};", types[j].Name)); } } catch(ReflectionTypeLoadException TypeEx){ Response.Write("Problem with : " + types[j].Name); continue; } } } } catch(Exception Ex) { Response.Write("<p>Unable to load a module from " + ((string)Assemblies[i]) + ". The exception was " + Ex.GetType().Name + " at " + Ex.TargetSite.Name + ".</p>"); Exception Inner = Ex.InnerException; while(Inner != null){ Response.Write("Inner: " + Inner.GetType().Name); Inner = Inner.InnerException; } continue; } } } return hash; } //end PopulateHash private System.Collections.Hashtable Alphabetize(System.Collections.Hashtable hash) { string[] tempkeys = new string[hash.Keys.Count]; hash.Keys.CopyTo(tempkeys, 0); string[] keys = (string[])tempkeys; char[] separator = new char[1]; separator[0] = ';'; for (int c = 0; c < keys.Length; c++) { String key = keys[c]; String value = (String)hash[key]; String[] temp = value.Split(separator); Array.Sort(temp); value = String.Join(";", temp, 1, temp.Length - 1); value = String.Format("{0};", value); hash[key] = value; } return hash; } //end Alphabetize(System.Collections.Hashtable hash) private int[] GetOrder() { int index1 = 0; for (int i = 0; i < Namespaces.Length; i++) { if (Namespaces[i].Equals("System")) { index1 = i; break; } } int index2 = Namespaces.Length - 1; for(int i = Namespaces.Length - 1; i > -1; i--) { if (Namespaces[i].IndexOf("S") == 0) { index2 = i; break; } } int[] result = new int[Namespaces.Length]; for(int i = 0; i < index1; i++) { result[index2 - index1 + 1 + i] = i; } for(int i = index1; i < index2 + 1; i++) { result[i - index1] = i; } for(int i = index2 + 1; i < result.Length; i++) { result[i] = i; } Pivot = index2 - index1 + 1; return result; } </script> </HEAD> <!-- *********************************************************************** --> <!-- *********************************************************************** --> <!-- *********************************************************************** --> <!-- *********************************************************************** --> <!-- *********************************************************************** --> <BODY> <!--<SPAN Title="Click to reload all the original assemblies at once." id=Reset onclick="javascript:window.navigate(toc.aspx);" onmouseout="Reset.style.color='blue'" onmouseover="Reset.style.color='red'" style="CURSOR: hand; color:blue"> [Reset all assemblies] ain't working. </SPAN> --> <BR> <% int[] order = GetOrder(); for (int k = 0; k < order.Length; k++) { if (k == 0 || k == Pivot) { Response.Write("<UL CLASS=\"toc\" ONCLICK=\"outliner();\"\r\n"); Response.Write("ONSELECTSTART=\"return false;\"\r\n"); Response.Write("ONMOUSEOVER=\"mouseEnters();\"\r\n"); Response.Write("ONMOUSEOUT=\"mouseLeaves();\">\r\n"); if(k == Pivot) { Response.Write("<p> </p>"); } } Response.Write("<LI><H6>"); if (order[k] == 0 && Namespaces[order[k]].Length == 0) Response.Write("Empty Namespace"); else Response.Write(Namespaces[order[k]]); Response.Write("</H6>\r\n<UL>\r\n"); char[] separator = new char[1]; separator[0] = ';'; String [] classes = ((String)Hash[Namespaces[order[k]]]).Split(separator); // Last element in classes is String.Empty, so we loop until Length - 1. for(int j = 0; j < classes.Length - 1; j++) { Response.Write("<LI>"); String link = String.Format("<A HREF=\"browser.aspx?class={0}.{1}\"" + " Title={0}.{1}" + " target=\"main\">{1}</A></LI>\r\n", Namespaces[order[k]], classes[j]); Response.Write(link); } Response.Write("</UL>\r\n"); if (k == Pivot - 1 || k == order.Length - 1) { Response.Write("</UL>\r\n"); } } %> </BODY> </HTML>