You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
7.0 KiB

4 years ago
  1. #if MYSQL_6_10
  2. // Copyright ?2013, 2018, Oracle and/or its affiliates. All rights reserved.
  3. //
  4. // MySQL Connector/NET is licensed under the terms of the GPLv2
  5. // <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
  6. // MySQL Connectors. There are special exceptions to the terms and
  7. // conditions of the GPLv2 as it is applied to this software, see the
  8. // FLOSS License Exception
  9. // <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
  10. //
  11. // This program is free software; you can redistribute it and/or modify
  12. // it under the terms of the GNU General Public License as published
  13. // by the Free Software Foundation; version 2 of the License.
  14. //
  15. // This program is distributed in the hope that it will be useful, but
  16. // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  18. // for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License along
  21. // with this program; if not, write to the Free Software Foundation, Inc.,
  22. // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. using System;
  24. using System.Collections.Generic;
  25. using System.Text;
  26. using System.Configuration;
  27. namespace Externals.MySql.Data.MySqlClient
  28. {
  29. /// <summary>
  30. /// Represents a section within a configuration file.
  31. /// </summary>
  32. internal sealed class MySqlConfiguration : ConfigurationSection
  33. {
  34. private static MySqlConfiguration settings
  35. = ConfigurationManager.GetSection("MySQL") as MySqlConfiguration;
  36. /// <summary>
  37. /// Gets the MySQL configuations associated to the current configuration.
  38. /// </summary>
  39. public static MySqlConfiguration Settings
  40. {
  41. get { return settings; }
  42. }
  43. /// <summary>
  44. /// Gets a collection of the exception interceptors available in the current configuration.
  45. /// </summary>
  46. [ConfigurationProperty("ExceptionInterceptors", IsRequired = false)]
  47. [ConfigurationCollection(typeof(InterceptorConfigurationElement), AddItemName = "add", ClearItemsName = "clear", RemoveItemName = "remove")]
  48. public GenericConfigurationElementCollection<InterceptorConfigurationElement> ExceptionInterceptors
  49. {
  50. get { return (GenericConfigurationElementCollection<InterceptorConfigurationElement>)this["ExceptionInterceptors"]; }
  51. }
  52. /// <summary>
  53. /// Gets a collection of the command interceptors available in the current configuration.
  54. /// </summary>
  55. [ConfigurationProperty("CommandInterceptors", IsRequired = false)]
  56. [ConfigurationCollection(typeof(InterceptorConfigurationElement), AddItemName = "add", ClearItemsName = "clear", RemoveItemName = "remove")]
  57. public GenericConfigurationElementCollection<InterceptorConfigurationElement> CommandInterceptors
  58. {
  59. get { return (GenericConfigurationElementCollection<InterceptorConfigurationElement>)this["CommandInterceptors"]; }
  60. }
  61. /// <summary>
  62. /// Gets a collection of the authentication plugins available in the current configuration.
  63. /// </summary>
  64. [ConfigurationProperty("AuthenticationPlugins", IsRequired = false)]
  65. [ConfigurationCollection(typeof(AuthenticationPluginConfigurationElement), AddItemName = "add", ClearItemsName = "clear", RemoveItemName = "remove")]
  66. public GenericConfigurationElementCollection<AuthenticationPluginConfigurationElement> AuthenticationPlugins
  67. {
  68. get { return (GenericConfigurationElementCollection<AuthenticationPluginConfigurationElement>)this["AuthenticationPlugins"]; }
  69. }
  70. /// <summary>
  71. /// Gets or sets the replication configurations.
  72. /// </summary>
  73. [ConfigurationProperty("Replication", IsRequired = true)]
  74. public ReplicationConfigurationElement Replication
  75. {
  76. get
  77. {
  78. return (ReplicationConfigurationElement)this["Replication"];
  79. }
  80. set
  81. {
  82. this["Replication"] = value;
  83. }
  84. }
  85. }
  86. /// <summary>
  87. /// Defines the configurations allowed for an authentication plugin.
  88. /// </summary>
  89. internal sealed class AuthenticationPluginConfigurationElement : ConfigurationElement
  90. {
  91. /// <summary>
  92. /// Gets or sets the name of the authentication plugin.
  93. /// </summary>
  94. [ConfigurationProperty("name", IsRequired = true)]
  95. public string Name
  96. {
  97. get
  98. {
  99. return (string)this["name"];
  100. }
  101. set
  102. {
  103. this["name"] = value;
  104. }
  105. }
  106. /// <summary>
  107. /// Gets or sets the type of the authentication plugin.
  108. /// </summary>
  109. [ConfigurationProperty("type", IsRequired = true)]
  110. public string Type
  111. {
  112. get
  113. {
  114. return (string)this["type"];
  115. }
  116. set
  117. {
  118. this["type"] = value;
  119. }
  120. }
  121. }
  122. /// <summary>
  123. /// Defines the configurations allowed for an interceptor.
  124. /// </summary>
  125. internal sealed class InterceptorConfigurationElement : ConfigurationElement
  126. {
  127. /// <summary>
  128. /// Gets or sets the name of the interceptor.
  129. /// </summary>
  130. [ConfigurationProperty("name", IsRequired = true)]
  131. public string Name
  132. {
  133. get
  134. {
  135. return (string)this["name"];
  136. }
  137. set
  138. {
  139. this["name"] = value;
  140. }
  141. }
  142. /// <summary>
  143. /// Gets or sets the type of the interceptor.
  144. /// </summary>
  145. [ConfigurationProperty("type", IsRequired = true)]
  146. public string Type
  147. {
  148. get
  149. {
  150. return (string)this["type"];
  151. }
  152. set
  153. {
  154. this["type"] = value;
  155. }
  156. }
  157. }
  158. /// <summary>
  159. /// Represents a generic configuration element.
  160. /// </summary>
  161. /// <typeparam name="T"></typeparam>
  162. internal sealed class GenericConfigurationElementCollection<T> : ConfigurationElementCollection, IEnumerable<T> where T : ConfigurationElement, new()
  163. {
  164. List<T> _elements = new List<T>();
  165. protected override ConfigurationElement CreateNewElement()
  166. {
  167. T newElement = new T();
  168. _elements.Add(newElement);
  169. return newElement;
  170. }
  171. protected override object GetElementKey(ConfigurationElement element)
  172. {
  173. return _elements.Find(e => e.Equals(element));
  174. }
  175. /// <summary>
  176. /// Gets an enumerator that iterates through the returned list.
  177. /// </summary>
  178. /// <returns>An enumerator that iterates through the returned list.</returns>
  179. public new IEnumerator<T> GetEnumerator()
  180. {
  181. return _elements.GetEnumerator();
  182. }
  183. }
  184. }
  185. #endif