// License: BSD/LGPL // Copyright (C) 2011 Thomas d'Otreppe using System; using System.Collections; namespace WirelessPanda { public abstract class WirelessDevice { #region Dictionary stuff /// /// Keep track of the last position for the column /// private int _lastPosition = 0; /// /// Dictionary containing all values /// protected Hashtable _fieldsDictionary = new Hashtable(); /// /// Order of the columns /// protected Hashtable _fieldsOrder = new Hashtable(); /// /// Sets a value in the dictionary /// /// Key /// Value protected void setDictValue(string key, object value) { if (this._fieldsDictionary.ContainsKey(key)) { this._fieldsDictionary.Remove(key); } else { // Save the position for the column (useful when creating the dataset) this._fieldsOrder.Add(this._lastPosition++, key); } this._fieldsDictionary.Add(key, value); } /// /// Return a value in the dictionary /// /// Key /// Object value /// protected object getDictValue(string key) { if (this._fieldsDictionary.ContainsKey(key)) { return this._fieldsDictionary[key]; } throw new MissingFieldException("Value for <" + key + "> is not set or does not exist"); } /// /// Returns a copy of the dictionary /// internal Hashtable FieldsDictionary { get { return this._fieldsDictionary as Hashtable; } } /// /// Returns a copy of the column order /// internal Hashtable FieldsOrder { get { return this._fieldsOrder as Hashtable; } } #endregion #region Properties public string BSSID { get { return (string)this.getDictValue("BSSID"); } set { this.setDictValue("BSSID", value); if (value != null) { // Special case, not associated if (value.Trim() == "(not associated)") { this.setDictValue("BSSID", string.Empty); } else { this.setDictValue("BSSID", value.Trim()); } } } } public DateTime FirstTimeSeen { get { return (DateTime)this.getDictValue("First Time Seen"); } set { this.setDictValue("First Time Seen", value); } } public DateTime LastTimeSeen { get { return (DateTime)this.getDictValue("Last Time Seen"); } set { this.setDictValue("Last Time Seen", value); } } public int Channel { get { return (int)this.getDictValue("Channel"); } set { this.setDictValue("Channel", value); } } public ulong TotalFrames { get { return (ulong)this.getDictValue("Total Frames"); } set { this.setDictValue("Total Frames", value); } } public Coordinates Location { get { return (Coordinates)this.getDictValue("Location"); } set { this.setDictValue("Location", value); } } public int Power { get { return (int)this.getDictValue("Power"); } set { this.setDictValue("Power", value); } } #endregion } }