static MySqlBaseConnectionStringBuilder() { // Server options. Options.Add(new MySqlConnectionStringOption("server", "host,data source,datasource,address,addr,network address", typeof(string), "" /*"localhost"*/, false)); Options.Add(new MySqlConnectionStringOption("database", "initial catalog", typeof(string), string.Empty, false)); Options.Add(new MySqlConnectionStringOption("protocol", "connection protocol, connectionprotocol", typeof(MySqlConnectionProtocol), MySqlConnectionProtocol.Sockets, false, (BaseSetterDelegate)((msb, sender, value) => { #if NETSTANDARD1_6 || NETSTANDARD2_0 MySqlConnectionProtocol enumValue; if (Enum.TryParse <MySqlConnectionProtocol>(value.ToString(), true, out enumValue)) { if (enumValue == MySqlConnectionProtocol.Memory || enumValue == MySqlConnectionProtocol.Pipe) { throw new PlatformNotSupportedException(string.Format(Resources.OptionNotCurrentlySupported, $"Protocol={value}")); } } #endif msb.SetValue("protocol", value); }), (msb, sender) => msb.ConnectionProtocol)); Options.Add(new MySqlConnectionStringOption("port", null, typeof(uint), (uint)3306, false)); // Authentication options. Options.Add(new MySqlConnectionStringOption("user id", "uid,username,user name,user,userid", typeof(string), "", false)); Options.Add(new MySqlConnectionStringOption("password", "pwd", typeof(string), "", false)); Options.Add(new MySqlConnectionStringOption("certificatefile", "certificate file", typeof(string), null, false)); Options.Add(new MySqlConnectionStringOption("certificatepassword", "certificate password,ssl-ca-pwd", typeof(string), null, false)); Options.Add(new MySqlConnectionStringOption("certificatestorelocation", "certificate store location", typeof(MySqlCertificateStoreLocation), MySqlCertificateStoreLocation.None, false)); Options.Add(new MySqlConnectionStringOption("certificatethumbprint", "certificate thumb print", typeof(string), null, false)); Options.Add(new MySqlConnectionStringOption("sslmode", "ssl mode,ssl-mode", typeof(MySqlSslMode), MySqlSslMode.Preferred, false)); Options.Add(new MySqlConnectionStringOption("sslca", "ssl-ca", typeof(string), null, false, (BaseSetterDelegate)((msb, sender, value) => { msb.SslCa = value as string; }), (BaseGetterDelegate)((msb, sender) => { return(msb.SslCa); }))); Options.Add(new MySqlConnectionStringOption("sslkey", "ssl-key", typeof(string), null, false)); Options.Add(new MySqlConnectionStringOption("sslcert", "ssl-cert", typeof(string), null, false)); // SSH tunneling options. Options.Add(new MySqlConnectionStringOption("sshhostname", "ssh host name,ssh-host-name", typeof(string), "", false)); Options.Add(new MySqlConnectionStringOption("sshport", "ssh port,ssh-port", typeof(uint), (uint)22, false)); Options.Add(new MySqlConnectionStringOption("sshusername", "ssh user name,ssh-user-name", typeof(string), "", false)); Options.Add(new MySqlConnectionStringOption("sshpassword", "ssh password,ssh-password", typeof(string), "", false)); Options.Add(new MySqlConnectionStringOption("sshkeyfile", "ssh key file,ssh-key-file", typeof(string), "", false)); Options.Add(new MySqlConnectionStringOption("sshpassphrase", "ssh pass phrase,ssh-pass-phrase", typeof(string), "", false)); // Other properties. Options.Add(new MySqlConnectionStringOption("keepalive", "keep alive", typeof(uint), (uint)0, false)); // Language and charset options. Options.Add(new MySqlConnectionStringOption("characterset", "character set,charset", typeof(string), "", false)); }
static MySqlBaseConnectionStringBuilder() { // Server options. Options.Add(new MySqlConnectionStringOption("server", "host,data source,datasource", typeof(string), "" /*"localhost"*/, false)); Options.Add(new MySqlConnectionStringOption("database", "initial catalog", typeof(string), string.Empty, false)); Options.Add(new MySqlConnectionStringOption("protocol", "connection protocol,connectionprotocol", typeof(MySqlConnectionProtocol), MySqlConnectionProtocol.Sockets, false, (SetterDelegate)((msb, sender, value) => { #if !NET452 MySqlConnectionProtocol enumValue; if (Enum.TryParse <MySqlConnectionProtocol>(value.ToString(), true, out enumValue)) { if (enumValue == MySqlConnectionProtocol.Memory || enumValue == MySqlConnectionProtocol.Pipe) { throw new PlatformNotSupportedException(string.Format(Resources.OptionNotCurrentlySupported, $"Protocol={value}")); } } #endif msb.SetValue("protocol", value); }), (GetterDelegate)((msb, sender) => msb.ConnectionProtocol))); Options.Add(new MySqlConnectionStringOption("port", null, typeof(uint), (uint)3306, false)); Options.Add(new MySqlConnectionStringOption("dns-srv", "dnssrv", typeof(bool), false, false)); // Authentication options. Options.Add(new MySqlConnectionStringOption("user id", "uid,username,user name,user,userid", typeof(string), "", false)); Options.Add(new MySqlConnectionStringOption("password", "pwd", typeof(string), "", false)); Options.Add(new MySqlConnectionStringOption("certificatefile", "certificate file", typeof(string), null, false)); Options.Add(new MySqlConnectionStringOption("certificatepassword", "certificate password,ssl-ca-pwd", typeof(string), null, false)); Options.Add(new MySqlConnectionStringOption("certificatestorelocation", "certificate store location", typeof(MySqlCertificateStoreLocation), MySqlCertificateStoreLocation.None, false)); Options.Add(new MySqlConnectionStringOption("certificatethumbprint", "certificate thumb print", typeof(string), null, false)); Options.Add(new MySqlConnectionStringOption("sslmode", "ssl mode,ssl-mode", typeof(MySqlSslMode), MySqlSslMode.Preferred, false, (SetterDelegate)((msb, sender, value) => { MySqlSslMode newValue = (MySqlSslMode)Enum.Parse(typeof(MySqlSslMode), value.ToString(), true); if (newValue == MySqlSslMode.None && msb.TlsVersion != null) { throw new ArgumentException(Resources.InvalidTlsVersionAndSslModeOption, nameof(TlsVersion)); } msb.SetValue("sslmode", newValue); }), (GetterDelegate)((msb, sender) => { return(msb.SslMode); }))); Options.Add(new MySqlConnectionStringOption("sslca", "ssl-ca", typeof(string), null, false, (SetterDelegate)((msb, sender, value) => { msb.SslCa = value as string; }), (GetterDelegate)((msb, sender) => { return(msb.SslCa); }))); Options.Add(new MySqlConnectionStringOption("sslkey", "ssl-key", typeof(string), null, false)); Options.Add(new MySqlConnectionStringOption("sslcert", "ssl-cert", typeof(string), null, false)); Options.Add(new MySqlConnectionStringOption("tlsversion", "tls-version,tls version", typeof(string), null, false, (SetterDelegate)((msb, sender, value) => { if (value == null || string.IsNullOrWhiteSpace((string)value)) { msb.SetValue("tlsversion", null); return; } if (msb.SslMode == MySqlSslMode.None) { throw new ArgumentException(Resources.InvalidTlsVersionAndSslModeOption, nameof(TlsVersion)); } string strValue = ((string)value).TrimStart('[', '(').TrimEnd(']', ')').Replace(" ", string.Empty); if (string.IsNullOrWhiteSpace(strValue) || strValue == ",") { throw new ArgumentException(Resources.TlsVersionNotSupported); } SslProtocols protocols = SslProtocols.None; foreach (string opt in strValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { string tls = opt.ToLowerInvariant().Replace("v", "").Replace(".", ""); if (tls.Equals("tls1") || tls.Equals("tls10")) { tls = "tls"; } SslProtocols protocol; if (!tls.StartsWith("tls", StringComparison.OrdinalIgnoreCase) || (!Enum.TryParse <SslProtocols>(tls, true, out protocol) && !tls.Equals("tls13", StringComparison.OrdinalIgnoreCase))) { string info = string.Empty; #if NET48 || NETSTANDARD2_1 info = ", TLSv1.3"; #endif throw new ArgumentException(string.Format(Resources.InvalidTlsVersionOption, opt, info), nameof(TlsVersion)); } protocols |= protocol; } string strProtocols = protocols == SslProtocols.None ? string.Empty : Enum.Format(typeof(SslProtocols), protocols, "G"); strProtocols = (value.ToString().Equals("Tls13", StringComparison.OrdinalIgnoreCase) || value.ToString().Equals("Tlsv1.3", StringComparison.OrdinalIgnoreCase)) ? "Tls13" : strProtocols; msb.SetValue("tlsversion", strProtocols); }), (GetterDelegate)((msb, sender) => { return(msb.TlsVersion); }))); // SSH tunneling options. Options.Add(new MySqlConnectionStringOption("sshhostname", "ssh host name,ssh-host-name", typeof(string), "", false)); Options.Add(new MySqlConnectionStringOption("sshport", "ssh port,ssh-port", typeof(uint), (uint)22, false)); Options.Add(new MySqlConnectionStringOption("sshusername", "ssh user name,ssh-user-name", typeof(string), "", false)); Options.Add(new MySqlConnectionStringOption("sshpassword", "ssh password,ssh-password", typeof(string), "", false)); Options.Add(new MySqlConnectionStringOption("sshkeyfile", "ssh key file,ssh-key-file", typeof(string), "", false)); Options.Add(new MySqlConnectionStringOption("sshpassphrase", "ssh pass phrase,ssh-pass-phrase", typeof(string), "", false)); // Other properties. Options.Add(new MySqlConnectionStringOption("keepalive", "keep alive", typeof(uint), (uint)0, false)); // Language and charset options. Options.Add(new MySqlConnectionStringOption("characterset", "character set,charset", typeof(string), "", false)); }