internal void UpdateConfiguration(PostgresServiceInfo si, PostgresProviderConnectorOptions configuration) { if (si == null) { return; } if (!string.IsNullOrEmpty(si.Uri)) { if (si.Port > 0) { configuration.Port = si.Port; } if (configuration.UrlEncodedCredentials) { configuration.Username = WebUtility.UrlDecode(si.UserName); configuration.Password = WebUtility.UrlDecode(si.Password); } else { configuration.Username = si.UserName; configuration.Password = si.Password; } configuration.Host = si.Host; configuration.Database = si.Path; if (si.Query != null) { foreach (var kvp in UriExtensions.ParseQuerystring(si.Query)) { if (kvp.Key.Equals("sslmode", StringComparison.InvariantCultureIgnoreCase)) { // Npgsql parses SSL Mode into an enum, the first character must be capitalized configuration.SslMode = FirstCharToUpper(kvp.Value); } else if (kvp.Key.Equals("sslcert")) { // TODO: Map this client cert into the npgsql client cert callback configuration.ClientCertificate = kvp.Value; } else if (kvp.Key.Equals("sslkey")) { // TODO: Map this client cert into the npgsql client cert callback configuration.ClientKey = kvp.Value; } else if (kvp.Key.Equals("sslrootcert")) { // TODO: Map this client cert into the npgsql remote cert validation callback configuration.SslRootCertificate = kvp.Value; } else { configuration.Options.Add(kvp.Key, kvp.Value); } } } } }
public void UpdateConfiguration(SqlServerServiceInfo si, SqlServerProviderConnectorOptions configuration) { if (si == null) { return; } if (!string.IsNullOrEmpty(si.Uri)) { configuration.Port = si.Port; configuration.Server = si.Host; if (!string.IsNullOrEmpty(si.Path)) { configuration.Database = si.Path; } if (si.Query != null) { foreach (var kvp in UriExtensions.ParseQuerystring(si.Query)) { if (kvp.Key.EndsWith("database", StringComparison.InvariantCultureIgnoreCase) || kvp.Key.EndsWith("databaseName", StringComparison.InvariantCultureIgnoreCase)) { configuration.Database = kvp.Value; } else if (kvp.Key.EndsWith("instancename", StringComparison.InvariantCultureIgnoreCase)) { configuration.InstanceName = kvp.Value; } else if (kvp.Key.StartsWith("hostnameincertificate", StringComparison.InvariantCultureIgnoreCase)) { // adding this key could result in "System.ArgumentException : Keyword not supported: 'hostnameincertificate'" later } else { configuration.Options.Add(kvp.Key, kvp.Value); } } } if (configuration.UrlEncodedCredentials) { configuration.Username = WebUtility.UrlDecode(si.UserName); configuration.Password = WebUtility.UrlDecode(si.Password); } else { configuration.Username = si.UserName; configuration.Password = si.Password; } } }