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.

169 lines
4.9 KiB

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