using System; using System.Collections; using System.ComponentModel; using System.Web; using System.Web.SessionState; using System.Xml; using System.IO; namespace GoogleControl { /// /// The GoogleControl's Global is a neutral location for the static initialize method /// and for the static pages Hashtable. You can move them in another class if needed. /// The pages Hashtable contains RefererItem objects. /// The RefererItem class is also defined here. ///

Copyright (c) 2002 Alexis Grandemange
/// Mail: alexis.grandemange@pagebox.net

///
This program is free software; you can redistribute it and/or
	/// modify it under the terms of the GNU Lesser General Public
	/// License as published by the Free Software Foundation; version
	/// 2.1 of the License.
	/// This library is distributed in the hope that it will be useful,
	/// but WITHOUT ANY WARRANTY; without even the implied warranty of
	/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	/// GNU Lesser General Public License for more details.
	/// A copy of the GNU Lesser General Public License lesser.txt should be
	/// included in the distribution.
///
public class Global : System.Web.HttpApplication { /// /// Key: referer URL /// Value: RefererItem object /// public static Hashtable pages = new Hashtable(); protected void Application_Start(Object sender, EventArgs e) { } protected void Session_Start(Object sender, EventArgs e) { } protected void Application_BeginRequest(Object sender, EventArgs e) { } /// /// initialize adds a RefererItem entry to pages. /// /// The URL of the directory that uses GoogleControl /// The path of Global.asax /// if true tries to find GoogleControl remotely public static void initialize(string referer, string path, bool checkRemote) { lock(typeof(Global)) { if (pages.Contains(referer)) return; XmlTextReader r = null; RefererItem ri = new RefererItem(); if (checkRemote) { string propUrl = "http://" + referer + "GoogleControl.xml"; r = new XmlTextReader(propUrl); r.WhitespaceHandling = WhitespaceHandling.None; // The cheapest way to check if the URL is valid is to try reading it. // If we get an exception the page has no CSS try { r.ReadStartElement("google-control"); } catch(Exception e) { r = null; } } if (r == null) { int pos = path.LastIndexOf("\\"); path = path.Substring(0, pos + 1); string xmlPath = path + "GoogleControl.xml"; if (!File.Exists(xmlPath)) { // Add a fake RefererItem ri.license = "offline"; pages.Add(referer, ri); return; } r = new XmlTextReader(xmlPath); r.WhitespaceHandling = WhitespaceHandling.None; r.ReadStartElement("google-control"); } ri.license = r.ReadElementString("license"); ri.css = r.ReadElementString("css"); ri.titleCss = r.ReadElementString("title-css"); ri.tableMinWidth = r.ReadElementString("table-min-width"); ri.tableMaxWidth = r.ReadElementString("table-max-width"); ri.tableCss = r.ReadElementString("table-css"); ri.dgHeaderCss = r.ReadElementString("datagrid-header-css"); ri.dgCss = r.ReadElementString("datagrid-css"); ri.dgAltCss = r.ReadElementString("datagrid-alt-css"); ri.statusCss = r.ReadElementString("status-css"); ri.copyrightCss = r.ReadElementString("copyright-css"); r.ReadEndElement(); r.Close(); pages.Add(referer, ri); } } protected void Application_EndRequest(Object sender, EventArgs e) { } protected void Session_End(Object sender, EventArgs e) { } protected void Application_End(Object sender, EventArgs e) { } } /// /// Value in the pages Hashtable. /// Same information as GoogleControl.xml. /// public sealed class RefererItem { /// /// CSS URL /// public string css = null; /// /// CSS class to use for the title /// public string titleCss = null; /// /// CSS class to use for the status /// public string statusCss = null; /// /// CSS class to use for the copyright /// public string copyrightCss = null; /// /// Table min width (when the Datagrids are not displayed) /// public string tableMinWidth = null; /// /// Table max width (when the Datagrids are displayed) /// public string tableMaxWidth = null; /// /// CSS class to use for the Datagrid header /// public string dgHeaderCss = null; /// /// CSS class to use for the Datagrid items /// public string dgCss = null; /// /// CSS class to use for the Datagrid alternate items /// public string dgAltCss = null; /// /// CSS class to use for the embedding table /// public string tableCss = null; public string license = null; } }