WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
ShapeDefinitions.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.IO;
7 using System.Xml.Serialization;
8 
9 namespace DirectOutput.FX.MatrixFX.BitmapShapes
10 {
11  public class ShapeDefinitions
12  {
13  private FilePattern _BitmapFilePattern;
14 
21  [XmlIgnore]
22  public FilePattern BitmapFilePattern
23  {
24  get { return _BitmapFilePattern; }
25  set { _BitmapFilePattern = value; }
26  }
27 
28  private ShapeList _Shapes=new ShapeList();
29 
30  public ShapeList Shapes
31  {
32  get { return _Shapes; }
33  set { _Shapes = value; }
34  }
35 
36 
37  #region Serialization
38 
43  public string GetShapeDefinitionsXml()
44  {
45  string Xml = "";
46  using (MemoryStream ms = new MemoryStream())
47  {
48  new XmlSerializer(typeof(ShapeDefinitions)).Serialize(ms, this);
49  ms.Position = 0;
50  using (StreamReader sr = new StreamReader(ms, Encoding.Default))
51  {
52  Xml = sr.ReadToEnd();
53  sr.Dispose();
54  }
55  }
56 
57  return Xml;
58  }
59 
60 
65  public void SaveShapeDefinitionsXmlFile(string FileName)
66  {
67  GetShapeDefinitionsXml().WriteToFile(FileName);
68  }
69 
70 
77  {
78  string Xml;
79  try
80  {
81  Xml = General.FileReader.ReadFileToString(FileName);
82  }
83  catch (Exception E)
84  {
85  Log.Exception("Could not load ShapeDefinitions from {0}.".Build(FileName), E);
86  throw new Exception("Could not read ShapeDefinitions file {0}.".Build(FileName), E);
87  }
88 
89  return GetShapeDefinitionsFromShapeDefinitionsXml(Xml);
90  }
91 
92 
98  public static bool TestShapeDefinitionsShapeDefinitionsXmlFile(string FileName)
99  {
100  ShapeDefinitions C = null;
101  try
102  {
103  C = GetShapeDefinitionsFromShapeDefinitionsXmlFile(FileName);
104  }
105  catch
106  {
107  return false;
108  }
109  return C != null;
110 
111  }
112 
118  public static ShapeDefinitions GetShapeDefinitionsFromShapeDefinitionsXmlFile(FileInfo ShapeDefinitionsShapeDefinitionsFile)
119  {
120  return GetShapeDefinitionsFromShapeDefinitionsXmlFile(ShapeDefinitionsShapeDefinitionsFile.FullName);
121  }
122 
128  public static ShapeDefinitions GetShapeDefinitionsFromShapeDefinitionsXml(string ShapeDefinitionsXml)
129  {
130  byte[] xmlBytes = Encoding.Default.GetBytes(ShapeDefinitionsXml);
131  using (MemoryStream ms = new MemoryStream(xmlBytes))
132  {
133  try
134  {
135  return (ShapeDefinitions)new XmlSerializer(typeof(ShapeDefinitions)).Deserialize(ms);
136  }
137  catch (Exception E)
138  {
139 
140  Exception Ex = new Exception("Could not deserialize the ShapeDefinitions from XML data.", E);
141  Ex.Data.Add("XML Data", ShapeDefinitionsXml);
142  Log.Exception("Could not load ShapeDefinitions from XML data.", Ex);
143  throw Ex;
144  }
145  }
146  }
147  #endregion
148 
149 
150 
151 
152  }
153 }
static ShapeDefinitions GetShapeDefinitionsFromShapeDefinitionsXmlFile(FileInfo ShapeDefinitionsShapeDefinitionsFile)
Instanciates a ShapeDefinitions object from a ShapeDefinitions ShapeDefinitionsuration in a XML file...
A simple logger used to record important events and exceptions.
Definition: Log.cs:14
static ShapeDefinitions GetShapeDefinitionsFromShapeDefinitionsXmlFile(string FileName)
Instanciates a ShapeDefinitions object from a ShapeDefinitions ShapeDefinitionsuration in a XML file...
void SaveShapeDefinitionsXmlFile(string FileName)
Serializes the ShapeDefinitions ShapeDefinitionsuration to a XML file.
static bool TestShapeDefinitionsShapeDefinitionsXmlFile(string FileName)
Tests a ShapeDefinitions ShapeDefinitions in a XML file.
string GetShapeDefinitionsXml()
Returns a serialized XML representation of the ShapeDefinitions ShapeDefinitionsuration.
The namespace DirectOutput.General contains classes for general use.
A file pattern class used to lookup files matching a specified pattern.
Definition: FilePattern.cs:12
static void Exception(string Message, Exception E=null)
Writes a exception message to the log.
Definition: Log.cs:144
static ShapeDefinitions GetShapeDefinitionsFromShapeDefinitionsXml(string ShapeDefinitionsXml)
Instanciates a ShapeDefinitions object from a ShapeDefinitions ShapeDefinitionsuration in a XML strin...