2 using System.Collections.Generic;
3 using DirectOutput.General.Generic;
6 namespace DirectOutput.Table
14 private Dictionary<TableElementTypeEnum, Dictionary<int, TableElement>> _TableElementsDictionary;
31 public void FinishAssignedEffects()
39 #region Direct access to TableElementType Dictionaries
46 return _TableElementsDictionary[Type];
56 return new List<TableElement> (_TableElementsDictionary[Type].Values);
62 public Dictionary<int, TableElement>
Switch
72 public Dictionary<int, TableElement>
Solenoid
82 public Dictionary<int, TableElement>
Lamp
92 public Dictionary<int, TableElement>
GIString
103 public Dictionary<int, TableElement>
Mech
123 return _TableElementsDictionary[TableElementType][Number];
130 #region UpdateState()
141 if (Contains(TableElementType, Number))
143 _TableElementsDictionary[TableElementType][Number].
Value = State;
148 Add(TableElementType, Number, State);
167 if (TableElement==null)
169 throw new Exception(
"Cant add null to the list of table elements.");
171 if (Contains(TableElement))
173 throw new Exception(
"The TableElement {0} {1} cant be added to the list. Another entry with the same type and number does already exist.".Build(TableElement.
TableElementType, TableElement.
Number));
176 base.Add(TableElement);
211 return _TableElementsDictionary[TableElement.
TableElementType].ContainsKey(TableElement.
Number) || base.Contains(TableElement);
222 return _TableElementsDictionary[TableElementType].ContainsKey(Number);
240 return base.Remove(TableElement);
251 if (!Contains(TableElementType, Number))
return false;
252 Remove(_TableElementsDictionary[TableElementType][Number]);
253 _TableElementsDictionary[TableElementType].Remove(Number);
261 #region Events & Event handling
262 void TableElementList_AfterSet(
object sender, SetEventArgs<TableElement> e)
264 _TableElementsDictionary[e.OldItem.TableElementType].Remove(e.OldItem.Number);
265 e.OldItem.ValueChanged -=
new EventHandler<TableElementValueChangedEventArgs>(Item_ValueChanged);
266 _TableElementsDictionary[e.NewItem.TableElementType].Add(e.NewItem.Number, e.NewItem);
267 e.NewItem.ValueChanged +=
new EventHandler<TableElementValueChangedEventArgs>(Item_ValueChanged);
270 void TableElementList_BeforeSet(
object sender, SetEventArgs<TableElement> e)
272 if (!Contains(e.NewItem.TableElementType, e.NewItem.Number) || (e.NewItem.TableElementType == e.OldItem.TableElementType && e.NewItem.Number == e.OldItem.Number))
278 throw new Exception(
"Another TableElement with type {0} and number {1} does already exist in the list.".Build(e.NewItem.TableElementType, e.NewItem.Number));
283 void TableElementList_AfterRemove(
object sender, RemoveEventArgs<TableElement> e)
285 e.Item.ValueChanged -=
new EventHandler<TableElementValueChangedEventArgs>(Item_ValueChanged);
288 void TableElementList_AfterInsert(
object sender, InsertEventArgs<TableElement> e)
290 e.Item.ValueChanged +=
new EventHandler<TableElementValueChangedEventArgs>(Item_ValueChanged);
293 void Item_ValueChanged(
object sender, TableElementValueChangedEventArgs e)
295 OnTableElementValueChanged(e);
298 #region "ableElement Value Changed Event
301 private void OnTableElementValueChanged(TableElementValueChangedEventArgs e)
303 if (TableElementValueChanged != null)
305 TableElementValueChanged(
this, e);
336 _TableElementsDictionary =
new Dictionary<TableElementTypeEnum, Dictionary<int, TableElement>>();
339 _TableElementsDictionary.
Add(T,
new Dictionary<int, TableElement>());
341 this.AfterInsert +=
new EventHandler<InsertEventArgs<TableElement>>(TableElementList_AfterInsert);
342 this.AfterRemove +=
new EventHandler<RemoveEventArgs<TableElement>>(TableElementList_AfterRemove);
343 this.BeforeSet +=
new EventHandler<SetEventArgs<TableElement>>(TableElementList_BeforeSet);
344 this.AfterSet +=
new EventHandler<SetEventArgs<TableElement>>(TableElementList_AfterSet);
360 TE.
ValueChanged -=
new EventHandler<TableElementValueChangedEventArgs>(Item_ValueChanged);