using System; using System.Collections; using System.ComponentModel; using System.Web; using System.Web.SessionState; using System.IO; using System.Xml; namespace Reservation { /// /// Generated. /// Method modified: Application_BeginRequest. ///

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 { /// /// Database connection string /// public static string connectionString = null; /// /// URL of PageBox Query.asmx /// public static string pageboxUrl = null; /// /// true when initialized /// public static bool isInitialized = false; /// /// Reservation archive name /// public static string archive; /// /// SMTP server used to send confirmation messages (Register.aspx and Retrieve.aspx) /// public static string smtpServer; /// /// Configuration user /// public static string user; /// /// Configuration password /// public static string password; /// /// Country codes per country names /// public static Hashtable countries; /// /// US State codes per state names /// public static Hashtable states; /// /// Canada Province codes per province names /// public static Hashtable provinces; /// /// Country names per country codes /// public static Hashtable countryPerCode = null; /// /// US State names per state codes /// public static Hashtable statePerCode = null; /// /// Canada Province names per province codes /// public static Hashtable provincePerCode = null; /// /// Sorted array of state + province names /// public static ArrayList stateAl = new ArrayList(); /// /// State or province name /// public static string stateName = null; /// /// Index of stateName in stateAl /// public static int stateIndex = 0; /// /// Sorted array of country names /// public static ArrayList countryAl = new ArrayList(); /// /// Country name /// public static string countryName = null; /// /// Index of countryName in countryAl /// public static int countryIndex = 0; /// /// Reservation instance address /// public static string address; public static string city; /// /// State or province code /// public static string state; public static string zipcode; /// /// Country code /// public static string country; public static string region; public static string latitude; public static string longitude; /// /// URL of the directory of this Reservation instance /// public static string url; /// /// Application full physical path /// public static string path; protected void Application_Start(Object sender, EventArgs e) { } protected void Session_Start(Object sender, EventArgs e) { } /// /// Computes the physical path and the URL. /// Restores reservation.xml. /// protected void Application_BeginRequest(Object sender, EventArgs e) { lock(typeof(Global)) { if (!Global.isInitialized) { if (path == null) { // Very first time path = Request.ServerVariables["PATH_TRANSLATED"]; int pos = path.LastIndexOf("\\"); path = path.Substring(0, pos + 1); string lpath = Request.ServerVariables["PATH_INFO"]; string host = Request.ServerVariables["HTTP_HOST"]; string port = Request.ServerVariables["SERVER_PORT"]; pos = lpath.LastIndexOf("/"); lpath = lpath.Substring(0, pos); if (port.Equals("80")) url = host + lpath; else url = host + ":" + port + lpath; } if (File.Exists(path + "reservation.xml")) { XmlTextReader r = new XmlTextReader(path + "reservation.xml"); r.WhitespaceHandling = WhitespaceHandling.None; r.ReadStartElement("reservation"); Global.archive = r.ReadElementString("archive"); Global.connectionString = r.ReadElementString("connection-string"); Global.pageboxUrl = r.ReadElementString("pagebox"); Global.smtpServer = r.ReadElementString("smtp-server"); Global.user = r.ReadElementString("user"); Global.password = r.ReadElementString("password"); Global.address = r.ReadElementString("address"); Global.city = r.ReadElementString("city"); Global.state = r.ReadElementString("state"); Global.zipcode = r.ReadElementString("zip"); Global.country = r.ReadElementString("country"); Global.region = r.ReadElementString("region"); Global.latitude = r.ReadElementString("latitude"); Global.longitude = r.ReadElementString("longitude"); r.Close(); if (File.Exists(path + "countries.csv")) Global.countries = restoreCsv(path + "countries.csv", 2); if (File.Exists(path + "states.csv")) Global.states = restoreCsv(path + "states.csv", 0); if (File.Exists(path + "provinces.csv")) Global.provinces = restoreCsv(path + "provinces.csv", 1); Global.stateAl.Add("N/A"); ArrayList stateAl = new ArrayList(Global.states.Keys); stateAl.Sort(); ArrayList provinceAl = new ArrayList(Global.provinces.Keys); provinceAl.Sort(); if (country.Equals("CA")) { Global.stateAl.AddRange(provinceAl); Global.stateAl.AddRange(stateAl); } else { Global.stateAl.AddRange(stateAl); Global.stateAl.AddRange(provinceAl); } if ((Global.state != null) && (Global.state.Length > 0)) { if (Global.statePerCode.Contains(Global.state)) Global.stateName = (string)Global.statePerCode[Global.state]; else { if (Global.provincePerCode.Contains(Global.state)) Global.stateName = (string)Global.provincePerCode[Global.state]; } } if (Global.stateName != null) { for (int i = 0; i < Global.stateAl.Count; ++ i) { string st = (string)Global.stateAl[i]; if (st.Equals(Global.stateName)) { Global.stateIndex = i; break; } } } Global.countryAl = new ArrayList(Global.countries.Keys); Global.countryAl.Sort(); Global.countryName = (string)Global.countryPerCode[Global.country]; for (int i = 0; i < Global.countryAl.Count; ++ i) { string c = (string)Global.countryAl[i]; if (c.Equals(Global.countryName)) { Global.countryIndex = i; break; } } Global.isInitialized = true; } } } } /// /// Populates a Hashtable from a csv file. /// /// Path of a csv file val, key /// Type of csv /// Populated Hashtable key=name private static Hashtable restoreCsv(string csvp, int type) { Hashtable h = new Hashtable(); Hashtable hpc = new Hashtable(); StreamReader sr = new StreamReader(csvp); string line = null; while((line = sr.ReadLine()) != null) { string[] la = line.Split(new char[] { ',' }); if (la.Length >= 2) { h.Add(la[1], la[0]); hpc.Add(la[0], la[1]); } } sr.Close(); switch(type) { case 0: Global.statePerCode = hpc; break; case 1: Global.provincePerCode = hpc; break; case 2: Global.countryPerCode = hpc; break; } return h; } protected void Application_EndRequest(Object sender, EventArgs e) { } protected void Session_End(Object sender, EventArgs e) { } protected void Application_End(Object sender, EventArgs e) { } } }