using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.IO; using System.Globalization; using RepositoryMG; namespace Repository { /// ///

Displays archive list and allows selecting subscribed archives.
/// Calls RepoSubs.

/// Methods created or modified: ///

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 aselect : System.Web.UI.Page { protected System.Web.UI.WebControls.HyperLink logo; protected System.Web.UI.WebControls.Label SubscriberLab; protected System.Web.UI.WebControls.Button BtnRefresh; protected System.Web.UI.WebControls.Label Subscriber; protected System.Web.UI.WebControls.Label LabStatus; protected System.Web.UI.WebControls.Label Snapshot; protected System.Web.UI.WebControls.HyperLink Support; protected MultiGrid archiveDB; public aselect() { Page.Init += new System.EventHandler(Page_Init); } /// /// Called on Page load event. /// Builds a list of archives and binds it to archiveDB (DataGrid). /// private void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { Subscriber.Text = Request.QueryString["subscriber"]; if (Subscriber.Text.Length == 0) { LabStatus.Text = "Subscriber not set"; return; } if (!Global.subRep.asubscribers.Contains(Subscriber.Text)) { LabStatus.Text = Subscriber.Text + " is not an archive subscriber"; return; } bind(Subscriber.Text); } } /// /// Enumerates archives and identify archives already subscribed /// /// Archive subscriber private void bind(string s) { Subscriber su = (Subscriber)Global.subRep.asubscribers[s]; ArrayList al = new ArrayList(); IDictionaryEnumerator ide = Global.archRep.archives.GetEnumerator(); string sn = null; while(ide.MoveNext()) { string owner = (string)ide.Value; string arch = (string)ide.Key; if (sn != null) sn += ("|" + arch); else sn = arch; string doc = (string)Global.archRep.docs[arch]; string size = "-1"; bool selected = su.archs.Contains(arch); DateTime dt = new DateTime(0L); if (File.Exists(Global.archRep.downloadPath + arch)) { dt = File.GetLastWriteTime(Global.archRep.downloadPath + arch); FileStream fs = File.Open(Global.archRep.downloadPath + arch, FileMode.Open, FileAccess.Read); size = "" + fs.Length; fs.Close(); } al.Add(new SelectorEntry(selected, arch, dt.ToString("u", DateTimeFormatInfo.InvariantInfo), owner, doc, size)); } Snapshot.Text = sn; archiveDB.DataSource = al; archiveDB.DataBind(); } /// /// Called on refresh event. Refresh subscriber display. /// public void Form1_refresh(object sender, EventArgs e) { Subscriber su = (Subscriber)Global.subRep.asubscribers[Subscriber.Text]; ArrayList al = archiveDB.SelectedItems; string[] archs = Snapshot.Text.Split(new char[1] { '|' }); IEnumerator ie = al.GetEnumerator(); string host = Request.ServerVariables["REMOTE_HOST"]; while(ie.MoveNext()) { SelectedEntry se = (SelectedEntry)ie.Current; string archive = archs[se.archNum]; if (!Global.archRep.archives.Contains(archive)) continue; if (se.selected) { if (!su.archs.Contains(archive)) { Global.subRep.add(User.Identity.Name, host, Subscriber.Text, archive); Log.write(User.Identity.Name, host, "add archive(" + Subscriber.Text + ", " + archive + ")"); } } else { if (su.archs.Contains(archive)) { Global.subRep.delete(User.Identity.Name, host, Subscriber.Text, archive); Log.write(User.Identity.Name, host, "delete archive(" + Subscriber.Text + ", " + archive + ")"); } } } bind(Subscriber.Text); } private void Page_Init(object sender, EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); } #region Web Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } /// /// Describes an archive. Element of the archive list. /// public sealed class SelectorEntry { /// /// If true the archive is subscribed /// public bool selected; /// /// Archive name. /// public string archive; /// /// Archive last modified time. /// private string date; /// /// User who published the archive. /// private string owner; /// /// URL of the archive documentation. /// private string doc; /// /// Size of the archive. /// private string size; /// /// Constructor. /// /// True: subscribed /// Archive name /// Archive last modified time /// User who published the archive /// URL of the archive documentation /// Size of the archive public SelectorEntry(bool b, string a, string t, string o, string d, string s) { selected = b; archive = a; date = t; owner = o; doc = d; size = s; } /// Archive name public bool Selected { get { return selected; } } /// Archive name public string Archive { get { return archive; } } /// Archive last modified time public string Date { get { return date; } } /// User who published the archive public string Owner { get { return owner; } } /// URL of the archive documentation public string Documentation { get { return doc; } } /// Size of the archive public string Size { get { return size; } } } }