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];
143 return _TableElementsDictionary[(
TableElementTypeEnum)TableElementDescriptor[0]][TableElementDescriptor.Substring(1).ToInteger()];
158 #region UpdateState()
170 if (Contains(TableElementType, Number))
172 _TableElementsDictionary[TableElementType][Number].
Value = State;
177 Add(TableElementType, Number, State);
196 if (TableElement==null)
198 throw new Exception(
"Cant add null to the list of table elements.");
200 if (Contains(TableElement))
202 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));
205 base.Add(TableElement);
240 return _TableElementsDictionary[TableElement.
TableElementType].ContainsKey(TableElement.
Number) || base.Contains(TableElement);
251 return _TableElementsDictionary[TableElementType].ContainsKey(Number);
269 return base.Remove(TableElement);
280 if (!Contains(TableElementType, Number))
return false;
281 Remove(_TableElementsDictionary[TableElementType][Number]);
282 _TableElementsDictionary[TableElementType].Remove(Number);
290 #region Events & Event handling
291 void TableElementList_AfterSet(
object sender, SetEventArgs<TableElement> e)
293 _TableElementsDictionary[e.OldItem.TableElementType].Remove(e.OldItem.Number);
294 e.OldItem.ValueChanged -=
new EventHandler<TableElementValueChangedEventArgs>(Item_ValueChanged);
295 _TableElementsDictionary[e.NewItem.TableElementType].Add(e.NewItem.Number, e.NewItem);
296 e.NewItem.ValueChanged +=
new EventHandler<TableElementValueChangedEventArgs>(Item_ValueChanged);
299 void TableElementList_BeforeSet(
object sender, SetEventArgs<TableElement> e)
301 if (!Contains(e.NewItem.TableElementType, e.NewItem.Number) || (e.NewItem.TableElementType == e.OldItem.TableElementType && e.NewItem.Number == e.OldItem.Number))
307 throw new Exception(
"Another TableElement with type {0} and number {1} does already exist in the list.".Build(e.NewItem.TableElementType, e.NewItem.Number));
312 void TableElementList_AfterRemove(
object sender, RemoveEventArgs<TableElement> e)
314 e.Item.ValueChanged -=
new EventHandler<TableElementValueChangedEventArgs>(Item_ValueChanged);
317 void TableElementList_AfterInsert(
object sender, InsertEventArgs<TableElement> e)
319 e.Item.ValueChanged +=
new EventHandler<TableElementValueChangedEventArgs>(Item_ValueChanged);
322 void Item_ValueChanged(
object sender, TableElementValueChangedEventArgs e)
324 OnTableElementValueChanged(e);
327 #region "ableElement Value Changed Event
330 private void OnTableElementValueChanged(TableElementValueChangedEventArgs e)
332 if (TableElementValueChanged != null)
334 TableElementValueChanged(
this, e);
365 _TableElementsDictionary =
new Dictionary<TableElementTypeEnum, Dictionary<int, TableElement>>();
368 _TableElementsDictionary.
Add(T,
new Dictionary<int, TableElement>());
370 this.AfterInsert +=
new EventHandler<InsertEventArgs<TableElement>>(TableElementList_AfterInsert);
371 this.AfterRemove +=
new EventHandler<RemoveEventArgs<TableElement>>(TableElementList_AfterRemove);
372 this.BeforeSet +=
new EventHandler<SetEventArgs<TableElement>>(TableElementList_BeforeSet);
373 this.AfterSet +=
new EventHandler<SetEventArgs<TableElement>>(TableElementList_AfterSet);
389 TE.
ValueChanged -=
new EventHandler<TableElementValueChangedEventArgs>(Item_ValueChanged);