WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
ShapeList.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
6 using System.Xml.Serialization;
7 using System.Xml;
8 
9 namespace DirectOutput.FX.MatrixFX.BitmapShapes
10 {
11  public class ShapeList : NamedItemList<Shape>, IXmlSerializable
12  {
13 
14 
15  #region IXmlSerializable implementation
16  public void WriteXml(XmlWriter writer)
22  {
23 
24  XmlSerializerNamespaces Namespaces = new XmlSerializerNamespaces();
25  Namespaces.Add(string.Empty, string.Empty);
26  foreach (Shape T in this)
27  {
28  XmlSerializer serializer = new XmlSerializer(T.GetType());
29  serializer.Serialize(writer, T, Namespaces);
30  }
31  }
32 
33 
39  public void ReadXml(XmlReader reader)
40  {
41  if (reader.IsEmptyElement)
42  {
43  reader.ReadStartElement();
44  return;
45  }
46  General.TypeList Types = new General.TypeList(AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(s => s.GetTypes()).Where(p => typeof(Shape).IsAssignableFrom(p) && !p.IsAbstract));
47 
48  reader.Read();
49 
50  while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
51  {
52  Type T = Types[reader.LocalName];
53 
54  if (T != null)
55  {
56  XmlSerializer serializer = new XmlSerializer(T);
57  Shape Shape = (Shape)serializer.Deserialize(reader);
58  if (!Contains(Shape.Name))
59  {
60  Add(Shape);
61  }
62  }
63  else
64  {
65  Log.Warning("ShapeDefinition type {0} not found during deserialization of cabinet data.".Build(reader.LocalName));
66  reader.Skip();
67  }
68 
69 
70  }
71  reader.ReadEndElement();
72  }
73 
74 
79  public System.Xml.Schema.XmlSchema GetSchema() { return (null); }
80  #endregion
81 
82 
83 
84  }
85 }
void ReadXml(XmlReader reader)
Deserializes the ShapeDefinition objects in the XmlReader The ShapeDefinition objects are deserialize...
Definition: ShapeList.cs:39
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
System.Xml.Schema.XmlSchema GetSchema()
Method is required by the IXmlSerializable interface
Definition: ShapeList.cs:79
A list of uniquely named items which can be referenced by their name.
The namespace DirectOutput.General contains classes for general use.
string Name
Name of the named item. Triggers BeforeNameChange before a new Name is set. Triggers AfterNameChang...