5 using System.Xml.Serialization;
6 using DirectOutput.Cab.Out;
7 using DirectOutput.General;
8 using DirectOutput.General.Color;
11 namespace DirectOutput.Cab
21 public void AutoConfig()
23 Log.
Write(
"Cabinet auto configuration started");
25 General.TypeList Types =
new General.TypeList(AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(s => s.GetTypes()).Where(p => typeof(
IAutoConfigOutputController).IsAssignableFrom(p) && !p.IsAbstract));
26 foreach (Type T
in Types)
37 Log.
Exception(
"A exception occured during auto configuration for output controller(s) of type {0}.".Build(T.Name), E);
43 Log.
Write(
"Cabinet auto configuration finished");
62 public string Name {
get;
set; }
71 public string CabinetConfigurationFilename {
get;
set; }
73 private Toys.ToyList _Toys;
79 public DirectOutput.Cab.Toys.ToyList Toys
82 set { _Toys = value; }
99 get {
return _Colors; }
100 set { _Colors = value; }
111 get {
return _Curves; }
112 set { _Curves = value; }
115 private bool _AutoConfigEnabled=
true;
124 public bool AutoConfigEnabled
126 get {
return _AutoConfigEnabled; }
127 set { _AutoConfigEnabled = value; }
145 private Out.OutputControllerList _OutputControllers;
151 public Out.OutputControllerList OutputControllers
153 get {
return _OutputControllers; }
154 set { _OutputControllers = value; }
158 #region Serialization
164 public string GetConfigXml()
167 using (MemoryStream ms =
new MemoryStream())
169 new XmlSerializer(typeof(
Cabinet)).Serialize(ms,
this);
171 using (StreamReader sr =
new StreamReader(ms, Encoding.Default))
173 Xml = sr.ReadToEnd();
186 public void SaveConfigXmlFile(
string FileName)
188 GetConfigXml().WriteToFile(FileName);
197 public static Cabinet GetCabinetFromConfigXmlFile(
string FileName)
202 Xml = General.FileReader.ReadFileToString(FileName);
206 Log.
Exception(
"Could not load cabinet config from {0}.".Build(FileName), E);
207 throw new Exception(
"Could not read cabinet config file {0}.".Build(FileName), E);
210 return GetCabinetFromConfigXml(Xml);
219 public static bool TestCabinetConfigXmlFile(
string FileName)
224 C = GetCabinetFromConfigXmlFile(FileName);
239 public static Cabinet GetCabinetFromConfigXmlFile(FileInfo CabinetConfigFile)
241 return GetCabinetFromConfigXmlFile(CabinetConfigFile.FullName);
249 public static Cabinet GetCabinetFromConfigXml(
string ConfigXml)
251 byte[] xmlBytes = Encoding.Default.GetBytes(ConfigXml);
252 using (MemoryStream ms =
new MemoryStream(xmlBytes))
256 return (
Cabinet)
new XmlSerializer(typeof(
Cabinet)).Deserialize(ms);
261 Exception Ex =
new Exception(
"Could not deserialize the cabinet config from XML data.", E);
262 Ex.Data.Add(
"XML Data", ConfigXml);
263 Log.
Exception(
"Could not load cabinet config from XML data.", Ex);
278 this.Pinball = Pinball;
279 OutputControllers.
Init(
this);
291 Toys.UpdateOutputs();
292 OutputControllers.Update();
305 OutputControllers.Finish();
317 _OutputControllers =
new Out.OutputControllerList();
319 _Toys =
new Toys.ToyList();