DirectOutputR1
DirectOutput framework R1 for virtual pinball cabinets.
Go to:
Overview 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros Pages
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;
5 using DirectOutput.General.Generic;
6 
7 namespace DirectOutput.Cab.Out
8 {
9 
13  public class OutputControllerList : NamedItemList<IOutputController>, IXmlSerializable
14  {
15 
16  #region IXmlSerializable implementation
17 
18 
19 
20 
21 
22  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  Type T = Types[reader.LocalName];
55  if (T != null)
56  {
57  XmlSerializer serializer = new XmlSerializer(T);
58  IOutputController O = (IOutputController)serializer.Deserialize(reader);
59  if (!Contains(O.Name))
60  {
61  Add(O);
62  }
63  }
64  else
65  {
66  reader.Skip();
67  }
68  }
69 
70  reader.ReadEndElement();
71  }
72 
73 
78  public System.Xml.Schema.XmlSchema GetSchema() { return (null); }
79  #endregion
80 
81 
82 
87  public void Init(Cabinet Cabinet)
88  {
89  Log.Debug("Initializing output controllers");
90  foreach (IOutputController OC in this)
91  {
92  OC.Init(Cabinet);
93  }
94  Log.Debug("Output controllers initialized");
95  }
96 
100  public void Finish()
101  {
102  Log.Debug("Finishing output controllers");
103  foreach (IOutputController OC in this)
104  {
105  OC.Finish();
106  }
107  Log.Debug("Output controllers finished");
108  }
109 
113  public void Update()
114  {
115  foreach (IOutputController OC in this)
116  {
117  OC.Update();
118  }
119  }
120 
121 
122 
123  }
124 }