2 // EngineConfig.cs - Holds information on the capabilities and behavior of an
6 // Gert Driesen (drieseng@users.sourceforge.net
8 // Copyright (c) 2008 Gert Driesen
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Globalization;
34 namespace MonoTests.System.Data.Connected
36 public sealed class EngineConfig
39 private string quoteCharacter;
40 private bool removesTrailingSpaces;
41 private bool emptyBinaryAsNull;
42 private bool supportsMicroseconds;
43 private bool supportsUniqueIdentifier;
44 private bool supportsDate;
45 private bool supportsTime;
46 private bool supportsTimestamp;
47 private EngineType type;
48 private int clientVersion;
50 public EngineConfig ()
59 /// Returns the character(s) for quoting identifiers.
61 public string QuoteCharacter {
62 get { return quoteCharacter; }
63 set { quoteCharacter = value; }
66 public EngineType Type {
71 public bool RemovesTrailingSpaces {
72 get { return removesTrailingSpaces; }
73 set { removesTrailingSpaces = value; }
76 public bool EmptyBinaryAsNull {
77 get { return emptyBinaryAsNull; }
78 set { emptyBinaryAsNull = value; }
81 public bool SupportsMicroseconds {
82 get { return supportsMicroseconds; }
83 set { supportsMicroseconds = value; }
86 public bool SupportsUniqueIdentifier {
87 get { return supportsUniqueIdentifier; }
88 set { supportsUniqueIdentifier = value; }
91 public bool SupportsDate {
92 get { return supportsDate; }
93 set { supportsDate = value; }
96 public bool SupportsTime {
97 get { return supportsTime; }
98 set { supportsTime = value; }
101 public bool SupportsTimestamp {
102 get { return supportsTimestamp; }
103 set { supportsTimestamp = value; }
106 public int ClientVersion {
107 get { return clientVersion; }
108 set { clientVersion = value; }
111 public static EngineConfig FromXml (XmlNode config)
113 EngineConfig engine = new EngineConfig ();
114 engine.name = GetAttribValue (config, "name", true);
115 engine.quoteCharacter = GetAttribValue (config, "quoteCharacter", true);
116 engine.removesTrailingSpaces = ParseBoolean (config, "removesTrailingSpaces", false, true);
117 engine.emptyBinaryAsNull = ParseBoolean (config, "emptyBinaryAsNull", false, true);
118 engine.supportsMicroseconds = ParseBoolean (config, "supportsMicroseconds", false, true);
119 engine.supportsUniqueIdentifier = ParseBoolean (config, "supportsUniqueIdentifier", false, true);
120 engine.supportsDate = ParseBoolean (config, "supportsDate", false, true);
121 engine.supportsTime = ParseBoolean (config, "supportsTime", false, true);
122 engine.supportsTimestamp = ParseBoolean (config, "supportsTimestamp", false, true);
123 engine.type = ParseEngineType (config, "type");
124 engine.clientVersion = ParseClientVersion (config, "clientversion");
128 static string GetAttribValue (XmlNode node, string name, bool required)
130 XmlAttribute attr = node.Attributes [name];
133 throw CreateAttributeMissingException (name, node);
139 static bool ParseBoolean (XmlNode config, string attrName, bool required, bool defaultValue)
141 XmlAttribute attr = config.Attributes [attrName];
144 throw CreateAttributeMissingException (attrName, config);
148 string value = attr.Value;
151 return bool.Parse (value);
152 } catch (Exception ex) {
153 throw CreateInvalidValueException (attrName,
158 static EngineType ParseEngineType (XmlNode config, string attrName)
160 XmlAttribute attr = config.Attributes [attrName];
162 throw CreateAttributeMissingException (attrName, config);
164 string value = attr.Value;
167 return (EngineType) Enum.Parse (typeof (EngineType), value);
168 } catch (Exception ex) {
169 throw CreateInvalidValueException (attrName,
174 static int ParseClientVersion (XmlNode config, string attrName)
176 XmlAttribute attr = config.Attributes [attrName];
180 string value = attr.Value;
183 return Int32.Parse (value);
184 } catch (Exception ex) {
185 throw CreateInvalidValueException (attrName,
190 static Exception CreateInvalidValueException (string name, string value, XmlNode node, Exception cause)
192 string msg = string.Format (CultureInfo.InvariantCulture,
193 "Invalid value '{0}' for attribute {1}.",
195 throw new ArgumentOutOfRangeException (msg, cause);
198 static Exception CreateAttributeMissingException (string name, XmlNode node)
200 string msg = string.Format (CultureInfo.InvariantCulture,
201 "Missing '{0}' attribute.", name);
202 throw new ArgumentException (msg);