WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
OutputList.cs
Go to the documentation of this file.
1 using System;
2 using System.Linq;
3 using System.Xml;
4 using System.Xml.Serialization;
6 
7 namespace DirectOutput.Cab.Out
8 {
9 
13  public class OutputList : NamedItemList<IOutput>, IXmlSerializable
14  {
15 
16  #region IXmlSerializable implementation
17  public void WriteXml(XmlWriter writer)
23  {
24 
25  XmlSerializerNamespaces Namespaces = new XmlSerializerNamespaces();
26  Namespaces.Add(string.Empty, string.Empty);
27  foreach (IOutput E in this)
28  {
29  XmlSerializer serializer = new XmlSerializer(E.GetType());
30  serializer.Serialize(writer, E, Namespaces);
31  }
32  }
33 
34 
40  public void ReadXml(XmlReader reader)
41  {
42  if (reader.IsEmptyElement)
43  {
44  reader.ReadStartElement();
45  return;
46  }
47  General.TypeList Types = new General.TypeList(AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(s => s.GetTypes()).Where(p => typeof(IOutput).IsAssignableFrom(p) && !p.IsAbstract));
48 
49  reader.Read();
50 
51  while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
52  {
53  Type T = Types[reader.LocalName];
54  if (T != null)
55  {
56  XmlSerializer serializer = new XmlSerializer(T);
57  IOutput O = (IOutput)serializer.Deserialize(reader);
58  if (!Contains(O.Name))
59  {
60  Add(O);
61  }
62  }
63  else
64  {
65  reader.Skip();
66  }
67  }
68 
69  reader.ReadEndElement();
70  }
71 
72 
79  public System.Xml.Schema.XmlSchema GetSchema() { return (null); }
80  #endregion
81 
82 
83  #region Events
84 
85  #region Event handling
86 
87  void OutputList_BeforeClear(object sender, EventArgs e)
88  {
89  foreach (IOutput O in this)
90  {
91  O.ValueChanged -= new Output.ValueChangedEventHandler(Item_ValueChanged);
92  }
93  }
94 
95  void OutputList_AfterRemove(object sender, RemoveEventArgs<IOutput> e)
96  {
97  e.Item.ValueChanged -= new Output.ValueChangedEventHandler(Item_ValueChanged);
98  }
99 
100  void OutputList_AfterInsert(object sender, InsertEventArgs<IOutput> e)
101  {
102  e.Item.ValueChanged += new Output.ValueChangedEventHandler(Item_ValueChanged);
103  }
104 
105  void OutputList_AfterSet(object sender, SetEventArgs<IOutput> e)
106  {
107  e.OldItem.ValueChanged -= new Output.ValueChangedEventHandler(Item_ValueChanged);
108  e.NewItem.ValueChanged += new Output.ValueChangedEventHandler(Item_ValueChanged);
109  }
110 
111  void Item_ValueChanged(object sender, OutputEventArgs e)
112  {
113  OnOutputValueChanged(e.Output);
114  }
115 
116  #endregion
117 
118  #region ValueChanged Event
119 
120 
126  {
127  if (OutputValueChanged != null)
128  {
129  OutputValueChanged(this, new OutputEventArgs(Output));
130  }
131  }
132 
136  public event OutputValueChangedEventHandler OutputValueChanged;
137 
143  public delegate void OutputValueChangedEventHandler(object sender, OutputEventArgs e);
144 
145 
146 
147  #endregion
148  #endregion
149 
153  public OutputList()
154  {
155  this.AfterInsert += new EventHandler<InsertEventArgs<IOutput>>(OutputList_AfterInsert);
156  this.AfterRemove += new EventHandler<RemoveEventArgs<IOutput>>(OutputList_AfterRemove);
157  this.AfterSet += new EventHandler<SetEventArgs<IOutput>>(OutputList_AfterSet);
158  this.BeforeClear += new EventHandler<EventArgs>(OutputList_BeforeClear);
159  }
160 
161 
162 
166  ~OutputList()
167  {
168  foreach (IOutput O in this)
169  {
170  O.ValueChanged -= new Output.ValueChangedEventHandler(Item_ValueChanged);
171  }
172  }
173 
174 
175 
176 
177 
178  }
179 }
Ty Item
The value of the Item to remove from index.
Event args for Set events.
Definition: SetEventArgs.cs:9
OutputList()
Initializes a new instance of the OutputList class.
Definition: OutputList.cs:153
OutputValueChangedEventHandler OutputValueChanged
Event fires if the value of any IOutput in the list has changed.
Definition: OutputList.cs:136
void ReadXml(XmlReader reader)
Deserializes the IOutput objects in the XmlReader. The IOutput objects are deserialized using the ob...
Definition: OutputList.cs:40
Ty NewItem
New item for the replacement.
Definition: SetEventArgs.cs:25
Output.ValueChangedEventHandler ValueChanged
This event has to fire if the Value of the output is changed
Definition: IOutput.cs:33
Ty Item
The new value of the element at Index.
delegate void ValueChangedEventHandler(object sender, OutputEventArgs e)
Event handler for ValueChanged events.
string Name
Gets or sets the name of the item. Must fire the BeforeNameChange and AfterNameChange events when th...
Definition: INamedItem.cs:17
List of IOutput objects
Definition: OutputList.cs:13
System.Xml.Schema.XmlSchema GetSchema()
Method is required by the IXmlSerializable interface.
Definition: OutputList.cs:79
Common interface for outputs of any output controller. The Output class implements this interface and...
Definition: IOutput.cs:10
void OnOutputValueChanged(IOutput Output)
Triggers the OutputValueChanged event when called.
Definition: OutputList.cs:125
EventArgs for events of IOutput objects.
A list of uniquely named items which can be referenced by their name.
Eventargs of BeforeInsert and AfterInsert events.
The namespace DirectOutput.General contains classes for general use.
Basic IOutput implementation.
Definition: Output.cs:14