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 private EngineConfig ()
59 /// Returns the character(s) for quoting identifiers.
61 public string QuoteCharacter {
62 get { return quoteCharacter; }
65 public EngineType Type {
69 public bool RemovesTrailingSpaces {
70 get { return removesTrailingSpaces; }
73 public bool EmptyBinaryAsNull {
74 get { return emptyBinaryAsNull; }
77 public bool SupportsMicroseconds {
78 get { return supportsMicroseconds; }
81 public bool SupportsUniqueIdentifier {
82 get { return supportsUniqueIdentifier; }
85 public bool SupportsDate {
86 get { return supportsDate; }
89 public bool SupportsTime {
90 get { return supportsTime; }
93 public bool SupportsTimestamp {
94 get { return supportsTimestamp; }
97 public int ClientVersion {
98 get { return clientVersion; }
101 public static EngineConfig FromXml (XmlNode config)
103 EngineConfig engine = new EngineConfig ();
104 engine.name = GetAttribValue (config, "name", true);
105 engine.quoteCharacter = GetAttribValue (config, "quoteCharacter", true);
106 engine.removesTrailingSpaces = ParseBoolean (config, "removesTrailingSpaces", false, true);
107 engine.emptyBinaryAsNull = ParseBoolean (config, "emptyBinaryAsNull", false, true);
108 engine.supportsMicroseconds = ParseBoolean (config, "supportsMicroseconds", false, true);
109 engine.supportsUniqueIdentifier = ParseBoolean (config, "supportsUniqueIdentifier", false, true);
110 engine.supportsDate = ParseBoolean (config, "supportsDate", false, true);
111 engine.supportsTime = ParseBoolean (config, "supportsTime", false, true);
112 engine.supportsTimestamp = ParseBoolean (config, "supportsTimestamp", false, true);
113 engine.type = ParseEngineType (config, "type");
114 engine.clientVersion = ParseClientVersion (config, "clientversion");
118 static string GetAttribValue (XmlNode node, string name, bool required)
120 XmlAttribute attr = node.Attributes [name];
123 throw CreateAttributeMissingException (name, node);
129 static bool ParseBoolean (XmlNode config, string attrName, bool required, bool defaultValue)
131 XmlAttribute attr = config.Attributes [attrName];
134 throw CreateAttributeMissingException (attrName, config);
138 string value = attr.Value;
141 return bool.Parse (value);
142 } catch (Exception ex) {
143 throw CreateInvalidValueException (attrName,
148 static EngineType ParseEngineType (XmlNode config, string attrName)
150 XmlAttribute attr = config.Attributes [attrName];
152 throw CreateAttributeMissingException (attrName, config);
154 string value = attr.Value;
157 return (EngineType) Enum.Parse (typeof (EngineType), value);
158 } catch (Exception ex) {
159 throw CreateInvalidValueException (attrName,
164 static int ParseClientVersion (XmlNode config, string attrName)
166 XmlAttribute attr = config.Attributes [attrName];
170 string value = attr.Value;
173 return Int32.Parse (value);
174 } catch (Exception ex) {
175 throw CreateInvalidValueException (attrName,
180 static Exception CreateInvalidValueException (string name, string value, XmlNode node, Exception cause)
182 string msg = string.Format (CultureInfo.InvariantCulture,
183 "Invalid value '{0}' for attribute {1}.",
185 throw new ArgumentOutOfRangeException (msg, cause);
188 static Exception CreateAttributeMissingException (string name, XmlNode node)
190 string msg = string.Format (CultureInfo.InvariantCulture,
191 "Missing '{0}' attribute.", name);
192 throw new ArgumentException (msg);