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
ToyList.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.Toys
8 {
9 
13  public class ToyList : NamedItemList<IToy>, 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 (IToy T in this)
28  {
29  XmlSerializer serializer = new XmlSerializer(T.GetType());
30  serializer.Serialize(writer, T, 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(IToy).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 
55  if (T != null)
56  {
57  XmlSerializer serializer = new XmlSerializer(T);
58  IToy Toy = (IToy)serializer.Deserialize(reader);
59  if (!Contains(Toy.Name))
60  {
61  Add(Toy);
62  }
63  }
64  else
65  {
66  Log.Warning("Toy type {0} not found during deserialization of cabinet data.".Build(reader.LocalName));
67  reader.Skip();
68  }
69 
70 
71  }
72  reader.ReadEndElement();
73  }
74 
75 
80  public System.Xml.Schema.XmlSchema GetSchema() { return (null); }
81  #endregion
82 
87  public void Init(Cabinet Cabinet)
88  {
89  foreach (IToy T in this)
90  {
91  T.Init(Cabinet);
92  }
93 
94  }
95 
99  public void Reset()
100  {
101  foreach (IToy T in this)
102  {
103  T.Reset();
104  }
105  }
106 
107 
108 
112  public void Finish()
113  {
114  foreach (IToy T in this)
115  {
116  T.Finish();
117  }
118  }
119 
120 
124  public void UpdateOutputs()
125  {
126  foreach (IToy T in this)
127  {
128  if (T is IToyUpdatable)
129  {
130  ((IToyUpdatable)T).UpdateOutputs();
131  }
132  }
133  }
134  }
135 }