5 // Copyright (c) 2007-2008 Jiri Moudry, Pascal Craponne
\r
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
\r
8 // of this software and associated documentation files (the "Software"), to deal
\r
9 // in the Software without restriction, including without limitation the rights
\r
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
11 // copies of the Software, and to permit persons to whom the Software is
\r
12 // furnished to do so, subject to the following conditions:
\r
14 // The above copyright notice and this permission notice shall be included in
\r
15 // all copies or substantial portions of the Software.
\r
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
28 using System.Collections.Generic;
\r
29 using System.Configuration;
\r
31 namespace DbMetal.Configuration
\r
34 /// Handles the providers section.
\r
35 /// Each provider is defined as follows:
\r
36 /// <provider name="MySQL" dbLinqSchemaLoader="DbLinq.MySql.MySqlSchemaLoader, DbLinq.MySql"
\r
37 /// databaseConnection="MySql.Data.MySqlClient.MySqlConnection, MySql.Data" />
\r
39 public class ProvidersSection : ConfigurationSection
\r
41 public class ProviderElement : ConfigurationElement
\r
43 [ConfigurationProperty("name", IsRequired = true)]
\r
46 get { return (string)this["name"]; }
\r
49 [ConfigurationProperty("dbLinqSchemaLoader", IsRequired = true)]
\r
50 public string DbLinqSchemaLoader
\r
52 get { return (string)this["dbLinqSchemaLoader"]; }
\r
55 [ConfigurationProperty("databaseConnection", IsRequired = true)]
\r
56 public string DatabaseConnection
\r
58 get { return (string)this["databaseConnection"]; }
\r
61 [ConfigurationProperty("sqlDialectType", IsRequired = false)]
\r
62 public string SqlDialectType
\r
64 get { return (string)this["sqlDialectType"]; }
\r
68 public class ProvidersCollection : ConfigurationElementCollection
\r
70 protected override ConfigurationElement CreateNewElement()
\r
72 return new ProviderElement();
\r
75 protected override object GetElementKey(ConfigurationElement element)
\r
77 var provider = (ProviderElement)element;
\r
78 return provider.Name.ToLower();
\r
81 public ProviderElement GetProvider(string name)
\r
83 return (ProviderElement)BaseGet(name.ToLower());
\r
85 public bool TryGetProvider(string name, out ProviderElement element, out string error)
\r
87 //use Configuration namespace to get our config
\r
88 object[] allKeys = base.BaseGetAllKeys();
\r
89 if (Array.IndexOf(allKeys, name.ToLower())<0)
\r
91 string[] allKeyStrings = allKeys.OfType<string>().ToArray();
\r
94 error = allKeys.Length == 0
\r
95 ? "There are no <provider> entries in your app.config"
\r
96 : "Key " + name + " not found among " + allKeys.Length + " config entries {" + string.Join(",",allKeyStrings) + "}";
\r
99 element = (ProviderElement)BaseGet(name.ToLower());
\r
105 [ConfigurationProperty("providers", IsDefaultCollection = true)]
\r
106 [ConfigurationCollection(typeof(ProviderElement), AddItemName = "provider")]
\r
107 public ProvidersCollection Providers
\r
109 get { return (ProvidersCollection)this["providers"]; }
\r