using System; using System.Collections; using System.ComponentModel; using System.Web; using System.Web.SessionState; using System.IO; using System.Xml; namespace Repository { /// ///

Generated.
/// Methods modified or created:

///

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 { /// /// Subscriber list. /// public static RepoSubs subRep; /// /// Archive list. /// public static RepoArchs archRep; /// /// Physical path (where subscribers.xml and archives.xml are stored) /// public static string path; /// /// True if RepoSubs and RepoArchs are initialized. /// public static bool isInitialized = false; protected void Application_Start(Object sender, EventArgs e) { } /// /// Restores RepoSubs and RepoArchs. /// private static void restore() { if (File.Exists(path + "\\subscribers.xml")) { XmlTextReader r = new XmlTextReader(path + "\\subscribers.xml"); r.WhitespaceHandling = WhitespaceHandling.None; r.Read(); if (r.NodeType == XmlNodeType.XmlDeclaration) subRep = new RepoSubs(r); else subRep = new RepoSubs(); r.Close(); } else subRep = new RepoSubs(); if (File.Exists(path + "\\archives.xml")) { XmlTextReader r = new XmlTextReader(path + "\\archives.xml"); r.WhitespaceHandling = WhitespaceHandling.None; r.Read(); if (r.NodeType == XmlNodeType.XmlDeclaration) archRep = new RepoArchs(r); else archRep = new RepoArchs(); r.Close(); } else archRep = new RepoArchs(); } protected void Session_Start(Object sender, EventArgs e) { } /// /// Restores and initializes archRep and subRep. ///

Version 0.0.3: support for first invocation from repository/Webservices.

///
protected void Application_BeginRequest(Object sender, EventArgs e) { lock(typeof(Global)) { if (!Global.isInitialized) { string lpath = Request.ServerVariables["PATH_INFO"]; string host = Request.ServerVariables["HTTP_HOST"]; string port = Request.ServerVariables["SERVER_PORT"]; path = Request.ServerVariables["PATH_TRANSLATED"]; int pos = lpath.LastIndexOf("/"); lpath = lpath.Substring(0, pos); // Repository directory pos = lpath.LastIndexOf("/"); int ppos = path.LastIndexOf("\\"); path = path.Substring(0, ppos); // Repository physical directory string dir = lpath.Substring(pos + 1); if (dir.Equals("WebServices") || dir.Equals("webservices")) { lpath = lpath.Substring(0, pos); pos = lpath.LastIndexOf("/"); ppos = path.LastIndexOf("\\"); path = path.Substring(0, ppos); // Repository physical directory } lpath = lpath.Substring(0, pos + 1) + "download/"; // download directory string url; if (port.Equals("80")) url = host + lpath; else url = host + ":" + port + lpath; pos = path.LastIndexOf("\\"); string dpath = path.Substring(0, pos + 1) + "download\\"; restore(); Global.subRep.init(url, Global.archRep); Global.archRep.init(url, Global.subRep, dpath); Global.isInitialized = true; } } } protected void Application_EndRequest(Object sender, EventArgs e) { } protected void Session_End(Object sender, EventArgs e) { } protected void Application_End(Object sender, EventArgs e) { } /// /// Saves subRep (subscriber list). /// Called by RepoArch and RepoSubs when the subscriber list is updated. /// public static void saveSubRep() { lock(typeof(Global)) { XmlTextWriter w = new XmlTextWriter (path + "\\subscribers.xml", null); w.Formatting = Formatting.Indented; w.WriteStartDocument(); subRep.WriteXml(w); w.WriteEndDocument(); w.Close(); } } /// /// Saves archRep (archive list). /// Called by RepoArch and RepoSubs when the subscriber list is updated. /// public static void saveArchRep() { lock(typeof(Global)) { XmlTextWriter w = new XmlTextWriter (path + "\\archives.xml", null); w.Formatting = Formatting.Indented; w.WriteStartDocument(); archRep.WriteXml(w); w.WriteEndDocument(); w.Close(); } } } }