2 using System.Collections.Generic;
5 using System.Xml.Serialization;
6 using System.Reflection;
9 using DirectOutput.Cab.Out.LW;
10 using DirectOutput.Cab.Toys;
11 using DirectOutput.Cab.Out;
12 using DirectOutput.Cab.Toys.LWEquivalent;
13 using DirectOutput.Cab.Color;
16 namespace DirectOutput.Cab
26 public void AutoConfig()
28 Log.
Write(
"Cabinet auto configuration started");
30 General.TypeList Types =
new General.TypeList(AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(s => s.GetTypes()).Where(p => typeof(
IAutoConfigOutputController).IsAssignableFrom(p) && !p.IsAbstract));
31 foreach (Type T
in Types)
39 Log.
Write(
"Cabinet auto configuration finished");
57 [XmlElementAttribute(Order = 1)]
58 public string Name {
get;
set; }
67 public string CabinetConfigurationFilename {
get;
set; }
69 private Toys.ToyList _Toys;
74 [XmlElementAttribute(Order = 3)]
75 public DirectOutput.Cab.Toys.ToyList Toys
78 set { _Toys = value; }
87 private DirectOutput.Cab.Color.ColorList _Colors;
92 [XmlElementAttribute(Order = 4)]
93 public DirectOutput.Cab.Color.ColorList Colors
95 get {
return _Colors; }
96 set { _Colors = value; }
100 private bool _AutoConfigEnabled=
true;
108 [XmlElementAttribute(Order = 5)]
109 public bool AutoConfigEnabled
111 get {
return _AutoConfigEnabled; }
112 set { _AutoConfigEnabled = value; }
130 private Out.OutputControllerList _OutputControllers;
135 [XmlElementAttribute(Order = 2)]
136 public Out.OutputControllerList OutputControllers
138 get {
return _OutputControllers; }
139 set { _OutputControllers = value; }
143 #region Serialization
149 public string GetConfigXml()
152 using (MemoryStream ms =
new MemoryStream())
154 new XmlSerializer(typeof(
Cabinet)).Serialize(ms,
this);
156 using (StreamReader sr =
new StreamReader(ms, Encoding.Default))
158 Xml = sr.ReadToEnd();
171 public void SaveConfigXmlFile(
string FileName)
173 GetConfigXml().WriteToFile(FileName);
182 public static Cabinet GetCabinetFromConfigXmlFile(
string FileName)
187 Xml = General.FileReader.ReadFileToString(FileName);
191 Log.
Exception(
"Could not load cabinet config from {0}.".Build(FileName), E);
192 throw new Exception(
"Could not read cabinet config file {0}.".Build(FileName), E);
195 return GetCabinetFromConfigXml(Xml);
204 public static bool TestCabinetConfigXmlFile(
string FileName)
209 C = GetCabinetFromConfigXmlFile(FileName);
224 public static Cabinet GetCabinetFromConfigXmlFile(FileInfo CabinetConfigFile)
226 return GetCabinetFromConfigXmlFile(CabinetConfigFile.FullName);
234 public static Cabinet GetCabinetFromConfigXml(
string ConfigXml)
236 byte[] xmlBytes = Encoding.Default.GetBytes(ConfigXml);
237 using (MemoryStream ms =
new MemoryStream(xmlBytes))
241 return (
Cabinet)
new XmlSerializer(typeof(
Cabinet)).Deserialize(ms);
246 Exception Ex =
new Exception(
"Could not deserialize the cabinet config from XML data.", E);
247 Ex.Data.Add(
"XML Data", ConfigXml);
248 Log.
Exception(
"Could not load cabinet config from XML data.", Ex);
263 this.Pinball = Pinball;
264 OutputControllers.
Init(
this);
276 Toys.UpdateOutputs();
277 OutputControllers.Update();
290 OutputControllers.Finish();
302 _OutputControllers =
new Out.OutputControllerList();
304 _Toys =
new Toys.ToyList();