WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
OutputControllerList.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 OutputControllerList : NamedItemList<IOutputController>, 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 (IOutputController OC in this)
28  {
29  XmlSerializer serializer = new XmlSerializer(OC.GetType());
30  serializer.Serialize(writer, OC, Namespaces);
31  }
32  }
33 
34 
40  public void ReadXml(XmlReader reader)
41  {
42  if (reader.IsEmptyElement)
43  {
44  reader.ReadStartElement();
45  return;
46  }
47 
48  General.TypeList Types = new General.TypeList(AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(s => s.GetTypes()).Where(p => typeof(IOutputController).IsAssignableFrom(p) && !p.IsAbstract));
49 
50  reader.Read();
51 
52  while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
53  {
54  if (reader.NodeType == XmlNodeType.Element)
55  {
56  Type T = Types[reader.LocalName];
57  if (T != null)
58  {
59  XmlSerializer serializer = new XmlSerializer(T);
60  IOutputController O = (IOutputController)serializer.Deserialize(reader);
61  if (!Contains(O.Name))
62  {
63  Add(O);
64  }
65  }
66  else
67  {
68  Log.Warning("Output controller type {0} not found during deserialization of data.".Build(reader.LocalName));
69  reader.Skip();
70  }
71  }
72  else
73  {
74  //Not a xml element. Probably a comment. Skip.
75  reader.Skip();
76  }
77  }
78 
79  reader.ReadEndElement();
80  }
81 
82 
87  public System.Xml.Schema.XmlSchema GetSchema() { return (null); }
88  #endregion
89 
90 
91 
96  public void Init(Cabinet Cabinet)
97  {
98  Log.Debug("Initializing output controllers");
99  foreach (IOutputController OC in this)
100  {
101  OC.Init(Cabinet);
102  }
103  Log.Debug("Output controllers initialized");
104  }
105 
109  public void Finish()
110  {
111  Log.Debug("Finishing output controllers");
112  foreach (IOutputController OC in this)
113  {
114  OC.Finish();
115  }
116  Log.Debug("Output controllers finished");
117  }
118 
122  public void Update()
123  {
124  foreach (IOutputController OC in this)
125  {
126  OC.Update();
127  }
128  }
129 
130 
131 
132  }
133 }
The Cabinet object describes the parts of a pinball cabinet (toys, outputcontrollers, outputs and more).
Definition: Cabinet.cs:17
new string Name
Name of the IOutputController. This property is fully implemented in the abstract OutputControllerBas...
void Init(Cabinet Cabinet)
Initializes all IOutputController objects in the list.
void Init(Cabinet Cabinet)
Must initialize the IOutputController. Is called after the objects have been instanciated.
static void Warning(string Message)
Writes a warning message to the log.
Definition: Log.cs:134
A simple logger used to record important events and exceptions.
Definition: Log.cs:14
void Finish()
Finishes all IOutputController objects in the list.
static void Debug(string Message="")
Writes the specified debug message to the log file.
Definition: Log.cs:216
List of IOutputController objects
System.Xml.Schema.XmlSchema GetSchema()
Method is required by the IXmlSerializable interface.
void Finish()
Must finish the IOutputController and do all necessary cleanup task. Must turn off the physical outpu...
Common interface for all outputcontrollers. Only classes implementing this interface can be used as o...
void Update()
Updates all IOutputController objects in the list.
A list of uniquely named items which can be referenced by their name.
The namespace DirectOutput.General contains classes for general use.
void Update()
Must update resp. thrigger the update of the physical outputs of the IOutputController.
void ReadXml(XmlReader reader)
Deserializes the IOutputController objects in the XmlReader. The IOutputController objects are deser...