| 1 |
// License: BSD/LGPL |
| 2 |
// Copyright (C) 2011-2018 Thomas d'Otreppe |
| 3 |
using System; |
| 4 |
using System.Collections; |
| 5 |
|
| 6 |
namespace WirelessPanda |
| 7 |
{ |
| 8 |
public abstract class WirelessDevice |
| 9 |
{ |
| 10 |
#region Dictionary stuff |
| 11 |
/// <summary> |
| 12 |
/// Keep track of the last position for the column |
| 13 |
/// </summary> |
| 14 |
private int _lastPosition = 0; |
| 15 |
|
| 16 |
/// <summary> |
| 17 |
/// Dictionary containing all values |
| 18 |
/// </summary> |
| 19 |
protected Hashtable _fieldsDictionary = new Hashtable(); |
| 20 |
|
| 21 |
/// <summary> |
| 22 |
/// Order of the columns |
| 23 |
/// </summary> |
| 24 |
protected Hashtable _fieldsOrder = new Hashtable(); |
| 25 |
|
| 26 |
/// <summary> |
| 27 |
/// Sets a value in the dictionary |
| 28 |
/// </summary> |
| 29 |
/// <param name="key">Key</param> |
| 30 |
/// <param name="value">Value</param> |
| 31 |
protected void setDictValue(string key, object value) |
| 32 |
{ |
| 33 |
if (this._fieldsDictionary.ContainsKey(key)) |
| 34 |
{ |
| 35 |
this._fieldsDictionary.Remove(key); |
| 36 |
} |
| 37 |
else |
| 38 |
{ |
| 39 |
// Save the position for the column (useful when creating the dataset) |
| 40 |
this._fieldsOrder.Add(this._lastPosition++, key); |
| 41 |
} |
| 42 |
|
| 43 |
this._fieldsDictionary.Add(key, value); |
| 44 |
} |
| 45 |
|
| 46 |
/// <summary> |
| 47 |
/// Return a value in the dictionary |
| 48 |
/// </summary> |
| 49 |
/// <param name="key">Key</param> |
| 50 |
/// <returns>Object value</returns> |
| 51 |
/// <exception cref="MissingFieldException"></exception> |
| 52 |
protected object getDictValue(string key) |
| 53 |
{ |
| 54 |
if (this._fieldsDictionary.ContainsKey(key)) |
| 55 |
{ |
| 56 |
return this._fieldsDictionary[key]; |
| 57 |
} |
| 58 |
|
| 59 |
throw new MissingFieldException("Value for <" + key + "> is not set or does not exist"); |
| 60 |
} |
| 61 |
|
| 62 |
/// <summary> |
| 63 |
/// Returns a copy of the dictionary |
| 64 |
/// </summary> |
| 65 |
internal Hashtable FieldsDictionary |
| 66 |
{ |
| 67 |
get |
| 68 |
{ |
| 69 |
return this._fieldsDictionary as Hashtable; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
/// <summary> |
| 74 |
/// Returns a copy of the column order |
| 75 |
/// </summary> |
| 76 |
internal Hashtable FieldsOrder |
| 77 |
{ |
| 78 |
get |
| 79 |
{ |
| 80 |
return this._fieldsOrder as Hashtable; |
| 81 |
} |
| 82 |
} |
| 83 |
#endregion |
| 84 |
|
| 85 |
#region Properties |
| 86 |
public string BSSID |
| 87 |
{ |
| 88 |
get |
| 89 |
{ |
| 90 |
return (string)this.getDictValue("BSSID"); |
| 91 |
} |
| 92 |
set |
| 93 |
{ |
| 94 |
this.setDictValue("BSSID", value); |
| 95 |
|
| 96 |
if (value != null) |
| 97 |
{ |
| 98 |
// Special case, not associated |
| 99 |
if (value.Trim() == "(not associated)") |
| 100 |
{ |
| 101 |
this.setDictValue("BSSID", string.Empty); |
| 102 |
} |
| 103 |
else |
| 104 |
{ |
| 105 |
this.setDictValue("BSSID", value.Trim()); |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
public DateTime FirstTimeSeen |
| 112 |
{ |
| 113 |
get |
| 114 |
{ |
| 115 |
return (DateTime)this.getDictValue("First Time Seen"); |
| 116 |
} |
| 117 |
set |
| 118 |
{ |
| 119 |
this.setDictValue("First Time Seen", value); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
public DateTime LastTimeSeen |
| 124 |
{ |
| 125 |
get |
| 126 |
{ |
| 127 |
return (DateTime)this.getDictValue("Last Time Seen"); |
| 128 |
} |
| 129 |
set |
| 130 |
{ |
| 131 |
this.setDictValue("Last Time Seen", value); |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
public int Channel |
| 136 |
{ |
| 137 |
get |
| 138 |
{ |
| 139 |
return (int)this.getDictValue("Channel"); |
| 140 |
} |
| 141 |
set |
| 142 |
{ |
| 143 |
this.setDictValue("Channel", value); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
public ulong TotalFrames |
| 148 |
{ |
| 149 |
get |
| 150 |
{ |
| 151 |
return (ulong)this.getDictValue("Total Frames"); |
| 152 |
} |
| 153 |
set |
| 154 |
{ |
| 155 |
this.setDictValue("Total Frames", value); |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
public Coordinates Location |
| 160 |
{ |
| 161 |
get |
| 162 |
{ |
| 163 |
return (Coordinates)this.getDictValue("Location"); |
| 164 |
} |
| 165 |
set |
| 166 |
{ |
| 167 |
this.setDictValue("Location", value); |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
public int Power |
| 172 |
{ |
| 173 |
get |
| 174 |
{ |
| 175 |
return (int)this.getDictValue("Power"); |
| 176 |
} |
| 177 |
set |
| 178 |
{ |
| 179 |
this.setDictValue("Power", value); |
| 180 |
} |
| 181 |
} |
| 182 |
#endregion |
| 183 |
} |
| 184 |
} |