using System; using System.Collections; using System.Xml; namespace Repository { /// ///

Describes a Subscriber.

///

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 Subscriber { /// /// Subscriber state. pbState in PHP version. /// public string state; /// /// Subscriber array of archives. /// Key: archive name. /// Value: archive status (string). /// public Hashtable archs; public Hashtable internalArchs; /// /// Constructor used when a new Subscriber is subscribed. /// /// Subscriber state /// archive/state associative table public Subscriber(string st, Hashtable a) { state = st; internalArchs = a; archs = Hashtable.Synchronized(internalArchs); } /// /// Constructor and unserializer. /// /// XML stream to unserialize public Subscriber(XmlReader r) { internalArchs = new Hashtable(); r.ReadStartElement("Subscriber"); while (true) { if (r.NodeType == XmlNodeType.Element) { if (r.LocalName.Equals("state")) { r.Read(); state = r.ReadString(); r.ReadEndElement(); } if (r.LocalName.Equals("arch")) { r.Read(); string name = r.ReadElementString("name"); string status = r.ReadElementString("status"); internalArchs.Add(name, status); r.ReadEndElement(); // arch } } if ((r.NodeType == XmlNodeType.EndElement) && r.LocalName.Equals("Subscriber")) break; } r.ReadEndElement(); // Subscriber archs = Hashtable.Synchronized(internalArchs); } /// Serializer. /// stream where the Subscriber must be serialized public void WriteXml(XmlWriter w) { w.WriteStartElement("Subscriber"); IDictionaryEnumerator ide = internalArchs.GetEnumerator(); while(ide.MoveNext()) { w.WriteStartElement("arch"); w.WriteElementString("name", (string)ide.Key); w.WriteElementString("status", (string)ide.Value); w.WriteEndElement(); } w.WriteElementString("state", state); w.WriteEndElement(); } } }