From e0df170a198f6b875fbbe37a7fa8a3c5fdf3aa5c Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 29 Apr 2012 23:05:51 +0000 Subject: Adding driver and test project. --- .../KeyboardKey.cs | 61 +++++++++------------- 1 file changed, 25 insertions(+), 36 deletions(-) (limited to 'src/Noddybox.Emulation.Keyboard.Schema/KeyboardKey.cs') diff --git a/src/Noddybox.Emulation.Keyboard.Schema/KeyboardKey.cs b/src/Noddybox.Emulation.Keyboard.Schema/KeyboardKey.cs index 6dac9b1..501fd2f 100644 --- a/src/Noddybox.Emulation.Keyboard.Schema/KeyboardKey.cs +++ b/src/Noddybox.Emulation.Keyboard.Schema/KeyboardKey.cs @@ -16,7 +16,7 @@ // Copyright (c) 2012 Ian Cowburn // using System; -using System.Xml; +using System.IO; namespace Noddybox.Emulation.Keyboard.Schema { @@ -61,50 +61,39 @@ namespace Noddybox.Emulation.Keyboard.Schema #endregion - #region Xml members + #region Load/Save /// - /// Set up an XmlElement with the contents of this object. + /// Save this object to a stream. /// - /// The document the element is to be attached to. - public void SetElement(XmlElement element) + /// The stream to write to. + public void Save(BinaryWriter stream) { - element.SetAttribute("KeySymbol", KeySymbol); - element.SetAttribute("X", X.ToString()); - element.SetAttribute("Y", Y.ToString()); - element.SetAttribute("Width", Width.ToString()); - element.SetAttribute("Height", Height.ToString()); - element.SetAttribute("Sticky", Sticky.ToString()); + stream.Write(KeySymbol); + stream.Write(X); + stream.Write(Y); + stream.Write(Width); + stream.Write(Height); + stream.Write(Sticky); } /// - /// Create an instance of this object from an XmlElement. + /// Create an instance of this object from a stream. /// - /// The document the element is to be attached to. - /// The XML element. - public static KeyboardKey CreateFromElement(XmlElement element) + /// The stream to read from. + /// The KeyboardKey object. + public static KeyboardKey Load(BinaryReader stream) { - XmlAttribute symbol = element.Attributes["KeySymbol"]; - XmlAttribute x = element.Attributes["X"]; - XmlAttribute y = element.Attributes["Y"]; - XmlAttribute width = element.Attributes["Width"]; - XmlAttribute height = element.Attributes["Height"]; - XmlAttribute sticky = element.Attributes["Sticky"]; - - if (symbol == null || x == null || y == null || width == null || height == null || sticky == null) - { - throw new ArgumentException("Element does not contain expected attributes"); - } - - return new KeyboardKey() - { - KeySymbol = symbol.Value, - X = Convert.ToInt32(x.Value), - Y = Convert.ToInt32(y.Value), - Width = Convert.ToInt32(width.Value), - Height = Convert.ToInt32(height.Value), - Sticky = Convert.ToBoolean(sticky.Value) - }; + KeyboardKey key = new KeyboardKey(); + + key.KeySymbol = stream.ReadString(); + key.X = stream.ReadInt32(); + key.Y = stream.ReadInt32(); + key.Width = stream.ReadInt32(); + key.Height = stream.ReadInt32(); + key.Sticky = stream.ReadBoolean(); + + return key; } #endregion -- cgit v1.2.3