|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Data.Common;
|
4 | 4 | using System.Globalization;
|
| 5 | +using System.Reflection; |
5 | 6 |
|
6 | 7 | namespace MySql.Data.MySqlClient
|
7 | 8 | {
|
| 9 | + public enum SslMode |
| 10 | + { |
| 11 | + None, |
| 12 | + Required, |
| 13 | + VerifyCa, |
| 14 | + VerifyFull, |
| 15 | + } |
| 16 | + |
8 | 17 | public sealed class MySqlConnectionStringBuilder : DbConnectionStringBuilder
|
9 | 18 | {
|
10 | 19 | public MySqlConnectionStringBuilder()
|
@@ -82,6 +91,24 @@ public bool UseCompression
|
82 | 91 | set { MySqlConnectionStringOption.UseCompression.SetValue(this, value); }
|
83 | 92 | }
|
84 | 93 |
|
| 94 | + public SslMode SslMode |
| 95 | + { |
| 96 | + get { return MySqlConnectionStringOption.SslMode.GetValue(this); } |
| 97 | + set { MySqlConnectionStringOption.SslMode.SetValue(this, value); } |
| 98 | + } |
| 99 | + |
| 100 | + public string CertificateFile |
| 101 | + { |
| 102 | + get { return MySqlConnectionStringOption.CertificateFile.GetValue(this); } |
| 103 | + set { MySqlConnectionStringOption.CertificateFile.SetValue(this, value); } |
| 104 | + } |
| 105 | + |
| 106 | + public string CertificatePassword |
| 107 | + { |
| 108 | + get { return MySqlConnectionStringOption.CertificatePassword.GetValue(this); } |
| 109 | + set { MySqlConnectionStringOption.CertificatePassword.SetValue(this, value); } |
| 110 | + } |
| 111 | + |
85 | 112 | public bool Pooling
|
86 | 113 | {
|
87 | 114 | get { return MySqlConnectionStringOption.Pooling.GetValue(this); }
|
@@ -179,6 +206,9 @@ internal abstract class MySqlConnectionStringOption
|
179 | 206 | public static readonly MySqlConnectionStringOption<bool> OldGuids;
|
180 | 207 | public static readonly MySqlConnectionStringOption<bool> PersistSecurityInfo;
|
181 | 208 | public static readonly MySqlConnectionStringOption<bool> UseCompression;
|
| 209 | + public static readonly MySqlConnectionStringOption<SslMode> SslMode; |
| 210 | + public static readonly MySqlConnectionStringOption<string> CertificateFile; |
| 211 | + public static readonly MySqlConnectionStringOption<string> CertificatePassword; |
182 | 212 | public static readonly MySqlConnectionStringOption<bool> Pooling;
|
183 | 213 | public static readonly MySqlConnectionStringOption<bool> ConnectionReset;
|
184 | 214 | public static readonly MySqlConnectionStringOption<uint> ConnectionTimeout;
|
@@ -265,6 +295,18 @@ static MySqlConnectionStringOption()
|
265 | 295 | keys: new[] { "Compress", "Use Compression", "UseCompression" },
|
266 | 296 | defaultValue: false));
|
267 | 297 |
|
| 298 | + AddOption(CertificateFile = new MySqlConnectionStringOption<string>( |
| 299 | + keys: new[] { "CertificateFile", "Certificate File" }, |
| 300 | + defaultValue: "")); |
| 301 | + |
| 302 | + AddOption(CertificatePassword = new MySqlConnectionStringOption<string>( |
| 303 | + keys: new[] { "CertificatePassword", "Certificate Password" }, |
| 304 | + defaultValue: "")); |
| 305 | + |
| 306 | + AddOption(SslMode = new MySqlConnectionStringOption<SslMode>( |
| 307 | + keys: new[] { "SSL Mode", "SslMode" }, |
| 308 | + defaultValue: MySqlClient.SslMode.None)); |
| 309 | + |
268 | 310 | AddOption(Pooling = new MySqlConnectionStringOption<bool>(
|
269 | 311 | keys: new[] { "Pooling" },
|
270 | 312 | defaultValue: true));
|
@@ -334,6 +376,16 @@ private static T ChangeType(object objectValue)
|
334 | 376 | return (T) (object) false;
|
335 | 377 | }
|
336 | 378 |
|
| 379 | + if (typeof(T).GetTypeInfo().IsSubclassOf(typeof(Enum)) && objectValue is string) |
| 380 | + { |
| 381 | + foreach (var val in Enum.GetValues(typeof(T))) |
| 382 | + { |
| 383 | + if (string.Equals((string) objectValue, val.ToString(), StringComparison.OrdinalIgnoreCase)) |
| 384 | + return (T) val; |
| 385 | + } |
| 386 | + throw new InvalidOperationException("Value '{0}' not supported for option '{1}'.".FormatInvariant(objectValue, typeof(T).GetTypeInfo().Name)); |
| 387 | + } |
| 388 | + |
337 | 389 | return (T) Convert.ChangeType(objectValue, typeof(T), CultureInfo.InvariantCulture);
|
338 | 390 | }
|
339 | 391 |
|
|
0 commit comments