using System; using System.Collections; using System.Data.OleDb; namespace Reservation { /// /// Responsible to maintain the Application table.
/// Calls Query (towards PageBox constellation) and /// Location Web service (towards peer Reservation instances).
/// Populates the applications table. ///

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 Application { /// /// Local PageBox URL /// string PageBoxUrl; /// /// Constructor. /// /// Local PageBox URL public Application(string url) { this.PageBoxUrl = url; } /// /// Synchronizes the Application table. /// /// boolean, false if unable to contact the local PageBox public bool Refresh() { Query query = new Query(PageBoxUrl); string[] archBase = Global.archive.Split(new Char[] { '.' }); string[] subUrls = null; try { query.Discover(); subUrls = query.GetSubscribers(Global.archive); if (subUrls == null) return false; } catch(Exception e) { return false; } Hashtable urlTable = new Hashtable(); for (int i = 0; i < subUrls.Length; ++i) { string url = computeUrl(subUrls[i], archBase[0]); LocationProxy loc = new LocationProxy(url); Entry en = null; try { loc.Discover(); en = loc.Notify(Global.url, Global.address, Global.city, Global.state, Global.zipcode, Global.country, Global.region, Global.latitude, Global.longitude); } catch(Exception e) { continue; } urlTable.Add(url, true); Location.populate(url, en.address, en.city, en.state, en.zip, en.country, en.region, en.latitude, en.longitude); } OleDbConnection odc = new OleDbConnection(Global.connectionString); odc.Open(); OleDbConnection odc2 = new OleDbConnection(Global.connectionString); odc2.Open(); OleDbCommand odcmd = new OleDbCommand("select url from applications", odc); OleDbDataReader odr = odcmd.ExecuteReader(); while(odr.Read()) { string url = (string)odr["url"]; if (!urlTable.Contains(url)) { OleDbCommand odcd = new OleDbCommand("delete from applications where url='" + url + "'", odc2); odcd.ExecuteNonQuery(); } } odr.Close(); odc.Close(); odc2.Close(); return true; } /// /// Customizable method. /// Compute the peer Location.asmx URL from the remote PageBox and from the Reservation archive name. /// /// Remote PageBox URL /// Archive name without extension /// URL of the peer Location.asmx Web service private string computeUrl(string subUrl, string archBase) { int pos = subUrl.LastIndexOf('/'); string url = subUrl.Substring(0, pos + 1) + archBase + "/Location.asmx"; if (!url.StartsWith("http://")) return "http://" + url; else return url; } } }