WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
EffectList.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.FX
8 {
9 
14  public class EffectList : NamedItemList<IEffect>, IXmlSerializable
15  {
16 
17  #region IXmlSerializable implementation
18  public void WriteXml(XmlWriter writer)
24  {
25 
26  XmlSerializerNamespaces Namespaces = new XmlSerializerNamespaces();
27  Namespaces.Add(string.Empty, string.Empty);
28  foreach (IEffect E in this)
29  {
30  XmlSerializer serializer = new XmlSerializer(E.GetType());
31  serializer.Serialize(writer, E, Namespaces);
32  }
33  }
34 
35 
41  public void ReadXml(XmlReader reader)
42  {
43  if (reader.IsEmptyElement)
44  {
45  reader.ReadStartElement();
46  return;
47  }
48 
49  General.TypeList Types = new General.TypeList(AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(s => s.GetTypes()).Where(p => typeof(IEffect).IsAssignableFrom(p) && !p.IsAbstract));
50 
51  reader.Read();
52 
53  while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
54  {
55  Type T = Types[reader.LocalName];
56  if (T != null)
57  {
58  XmlSerializer serializer = new XmlSerializer(T);
59  IEffect E = (IEffect)serializer.Deserialize(reader);
60  if (!Contains(E.Name))
61  {
62  Add(E);
63  }
64  }
65  else
66  {
67  reader.Skip();
68  }
69  }
70 
71  reader.ReadEndElement();
72  }
73 
74 
78  public System.Xml.Schema.XmlSchema GetSchema() { return (null); }
79  #endregion
80 
84  public void Finish()
85  {
86  foreach (IEffect Effect in this)
87  {
88  Effect.Finish();
89  }
90  }
91 
92 
96  public void Init(Table.Table Table)
97  {
98  foreach (IEffect Effect in this)
99  {
100  Effect.Init(Table);
101  }
102  }
103 
104 
108  public EffectList()
109  {
110 
111  }
112 
113 
114 
115  }
116 }
void Finish()
Calls Finish on all IEffect objects in the list.
Definition: EffectList.cs:84
void Init(Table.Table Table)
Calls Init on all IEffect objects in the list.
Definition: EffectList.cs:96
new string Name
Name of the effect.
Definition: IEffect.cs:53
void Init(Table.Table Table)
Init must do all necessary initialization work after the IEffect object has been instanciated.
void ReadXml(XmlReader reader)
Deserializes the IEffect objects in the XmlReader The IEffect objects are deserialized using the obje...
Definition: EffectList.cs:41
Common interface for all effects. If a new effect is implemented it is best to inherit from the abst...
Definition: IEffect.cs:13
void Finish()
Finish must do all necessary cleanupwork before a IEffect object is discarded.
A list of uniquely named items which can be referenced by their name.
The namespace DirectOutput.General contains classes for general use.
System.Xml.Schema.XmlSchema GetSchema()
Method is required by the IXmlSerializable interface
Definition: EffectList.cs:78
EffectList()
Initializes a new instance of the EffectList class.
Definition: EffectList.cs:108
Collection of IEffect objects. Every object can only exist once in the list and every objects needs t...
Definition: EffectList.cs:14