@@ -155,19 +155,17 @@ private static EventStoreClientSettings CreateSettings(
155
155
if ( typedOptions . TryGetValue ( ConnectionName , out object ? connectionName ) )
156
156
settings . ConnectionName = ( string ) connectionName ;
157
157
158
- var connSettings = settings . ConnectivitySettings ;
159
-
160
158
if ( typedOptions . TryGetValue ( MaxDiscoverAttempts , out object ? maxDiscoverAttempts ) )
161
- connSettings . MaxDiscoverAttempts = ( int ) maxDiscoverAttempts ;
159
+ settings . ConnectivitySettings . MaxDiscoverAttempts = ( int ) maxDiscoverAttempts ;
162
160
163
161
if ( typedOptions . TryGetValue ( DiscoveryInterval , out object ? discoveryInterval ) )
164
- connSettings . DiscoveryInterval = TimeSpan . FromMilliseconds ( ( int ) discoveryInterval ) ;
162
+ settings . ConnectivitySettings . DiscoveryInterval = TimeSpan . FromMilliseconds ( ( int ) discoveryInterval ) ;
165
163
166
164
if ( typedOptions . TryGetValue ( GossipTimeout , out object ? gossipTimeout ) )
167
- connSettings . GossipTimeout = TimeSpan . FromMilliseconds ( ( int ) gossipTimeout ) ;
165
+ settings . ConnectivitySettings . GossipTimeout = TimeSpan . FromMilliseconds ( ( int ) gossipTimeout ) ;
168
166
169
167
if ( typedOptions . TryGetValue ( NodePreference , out object ? nodePreference ) ) {
170
- connSettings . NodePreference = ( ( string ) nodePreference ) . ToLowerInvariant ( ) switch {
168
+ settings . ConnectivitySettings . NodePreference = ( ( string ) nodePreference ) . ToLowerInvariant ( ) switch {
171
169
"leader" => EventStore . Client . NodePreference . Leader ,
172
170
"follower" => EventStore . Client . NodePreference . Follower ,
173
171
"random" => EventStore . Client . NodePreference . Random ,
@@ -203,17 +201,17 @@ private static EventStoreClientSettings CreateSettings(
203
201
} ;
204
202
}
205
203
206
- connSettings . Insecure = ! useTls ;
204
+ settings . ConnectivitySettings . Insecure = ! useTls ;
207
205
208
206
if ( hosts . Length == 1 && scheme != UriSchemeDiscover ) {
209
- connSettings . Address = hosts [ 0 ] . ToUri ( useTls ) ;
207
+ settings . ConnectivitySettings . Address = hosts [ 0 ] . ToUri ( useTls ) ;
210
208
}
211
209
else {
212
210
if ( hosts . Any ( x => x is DnsEndPoint ) )
213
- connSettings . DnsGossipSeeds =
211
+ settings . ConnectivitySettings . DnsGossipSeeds =
214
212
Array . ConvertAll ( hosts , x => new DnsEndPoint ( x . GetHost ( ) , x . GetPort ( ) ) ) ;
215
213
else
216
- connSettings . IpGossipSeeds = Array . ConvertAll ( hosts , x => ( IPEndPoint ) x ) ;
214
+ settings . ConnectivitySettings . IpGossipSeeds = Array . ConvertAll ( hosts , x => ( IPEndPoint ) x ) ;
217
215
}
218
216
219
217
if ( typedOptions . TryGetValue ( TlsVerifyCert , out var tlsVerifyCert ) ) {
@@ -223,14 +221,13 @@ private static EventStoreClientSettings CreateSettings(
223
221
if ( typedOptions . TryGetValue ( TlsCaFile , out var tlsCaFile ) ) {
224
222
var tlsCaFilePath = Path . GetFullPath ( ( string ) tlsCaFile ) ;
225
223
if ( ! string . IsNullOrEmpty ( tlsCaFilePath ) && ! File . Exists ( tlsCaFilePath ) ) {
226
- throw new FileNotFoundException ( $ "Failed to load certificate. File was not found.") ;
224
+ throw new InvalidClientCertificateException ( $ "Failed to load certificate. File was not found.") ;
227
225
}
228
226
229
227
try {
230
- using var x509Certificate2 = new X509Certificate2 ( tlsCaFilePath ) ;
231
- settings . ConnectivitySettings . TlsCaFile = tlsCaFilePath ;
228
+ settings . ConnectivitySettings . TlsCaFile = new X509Certificate2 ( tlsCaFilePath ) ;
232
229
} catch ( CryptographicException ) {
233
- throw new Exception ( "Failed to load certificate. Invalid file format." ) ;
230
+ throw new InvalidClientCertificateException ( "Failed to load certificate. Invalid file format." ) ;
234
231
}
235
232
}
236
233
@@ -249,9 +246,7 @@ HttpMessageHandler CreateDefaultHandler() {
249
246
var sslOptions = new SslClientAuthenticationOptions ( ) ;
250
247
251
248
if ( settings . ConnectivitySettings is { TlsCaFile : not null , Insecure : false } ) {
252
- sslOptions . ClientCertificates = new X509Certificate2Collection {
253
- new X509Certificate2 ( settings . ConnectivitySettings . TlsCaFile )
254
- } ;
249
+ sslOptions . ClientCertificates ? . Add ( settings . ConnectivitySettings . TlsCaFile ) ;
255
250
}
256
251
257
252
if ( ! settings . ConnectivitySettings . TlsVerifyCert ) {
@@ -267,10 +262,8 @@ HttpMessageHandler CreateDefaultHandler() {
267
262
EnableMultipleHttp2Connections = true
268
263
} ;
269
264
270
-
271
265
if ( settings . ConnectivitySettings is { TlsCaFile : not null , Insecure : false } ) {
272
- var clientCertificate = new X509Certificate2 ( settings . ConnectivitySettings . TlsCaFile ) ;
273
- handler . ClientCertificates . Add ( clientCertificate ) ;
266
+ handler . ClientCertificates . Add ( settings . ConnectivitySettings . TlsCaFile ) ;
274
267
}
275
268
276
269
if ( ! settings . ConnectivitySettings . TlsVerifyCert ) {
0 commit comments