DirectOuput Framework R2
DirectOutput framework R2 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  Log.Warning("Output controller type {0} not found during deserialization of data.".Build(reader.LocalName));
67  reader.Skip();
68  }
69  }
70 
71  reader.ReadEndElement();
72  }
73 
74 
79  public System.Xml.Schema.XmlSchema GetSchema() { return (null); }
80  #endregion
81 
82 
83 
88  public void Init(Cabinet Cabinet)
89  {
90  Log.Debug("Initializing output controllers");
91  foreach (IOutputController OC in this)
92  {
93  OC.Init(Cabinet);
94  }
95  Log.Debug("Output controllers initialized");
96  }
97 
101  public void Finish()
102  {
103  Log.Debug("Finishing output controllers");
104  foreach (IOutputController OC in this)
105  {
106  OC.Finish();
107  }
108  Log.Debug("Output controllers finished");
109  }
110 
114  public void Update()
115  {
116  foreach (IOutputController OC in this)
117  {
118  OC.Update();
119  }
120  }
121 
122 
123 
124  }
125 }