3
3
using System . ComponentModel ;
4
4
5
5
namespace Elasticsearch . Net
6
- {
6
+ {
7
7
/// <summary>
8
8
/// ConnectionConfiguration allows you to control how ElasticsearchClient behaves and where/how it connects
9
9
/// to elasticsearch
@@ -12,40 +12,40 @@ public class ConnectionConfiguration : ConnectionConfiguration<ConnectionConfigu
12
12
{
13
13
public static TimeSpan DefaultTimeout = TimeSpan . FromMinutes ( 1 ) ;
14
14
public static TimeSpan DefaultPingTimeout = TimeSpan . FromSeconds ( 2 ) ;
15
- public static TimeSpan DefaultPingTimeoutOnSSL = TimeSpan . FromSeconds ( 5 ) ;
16
-
15
+ public static TimeSpan DefaultPingTimeoutOnSSL = TimeSpan . FromSeconds ( 5 ) ;
16
+
17
17
/// <summary>
18
18
/// ConnectionConfiguration allows you to control how ElasticsearchClient behaves and where/how it connects
19
19
/// to elasticsearch
20
20
/// </summary>
21
21
/// <param name="uri">The root of the elasticsearch node we want to connect to. Defaults to http://localhost:9200</param>
22
22
public ConnectionConfiguration ( Uri uri = null )
23
- : this ( new SingleNodeConnectionPool ( uri ?? new Uri ( "http://localhost:9200" ) ) )
24
- { }
25
-
23
+ : this ( new SingleNodeConnectionPool ( uri ?? new Uri ( "http://localhost:9200" ) ) )
24
+ { }
25
+
26
26
/// <summary>
27
27
/// ConnectionConfiguration allows you to control how ElasticsearchClient behaves and where/how it connects
28
28
/// to elasticsearch
29
29
/// </summary>
30
30
/// <param name="connectionPool">A connection pool implementation that'll tell the client what nodes are available</param>
31
- public ConnectionConfiguration ( IConnectionPool connectionPool )
32
- // ReSharper disable once IntroduceOptionalParameters.Global
33
- : this ( connectionPool , null , null )
31
+ public ConnectionConfiguration ( IConnectionPool connectionPool )
32
+ // ReSharper disable once IntroduceOptionalParameters.Global
33
+ : this ( connectionPool , null , null )
34
34
{ }
35
35
36
- public ConnectionConfiguration ( IConnectionPool connectionPool , IConnection connection )
37
- // ReSharper disable once IntroduceOptionalParameters.Global
38
- : this ( connectionPool , connection , null )
36
+ public ConnectionConfiguration ( IConnectionPool connectionPool , IConnection connection )
37
+ // ReSharper disable once IntroduceOptionalParameters.Global
38
+ : this ( connectionPool , connection , null )
39
39
{ }
40
40
41
41
public ConnectionConfiguration ( IConnectionPool connectionPool , IElasticsearchSerializer serializer )
42
- : this ( connectionPool , null , serializer )
43
- { }
44
-
45
- // ReSharper disable once MemberCanBePrivate.Global
46
- // eventhough we use don't use this we very much would like to expose this constructor
42
+ : this ( connectionPool , null , serializer )
43
+ { }
44
+
45
+ // ReSharper disable once MemberCanBePrivate.Global
46
+ // eventhough we use don't use this we very much would like to expose this constructor
47
47
public ConnectionConfiguration ( IConnectionPool connectionPool , IConnection connection , IElasticsearchSerializer serializer )
48
- : base ( connectionPool , connection , serializer )
48
+ : base ( connectionPool , connection , serializer )
49
49
{ }
50
50
}
51
51
@@ -111,8 +111,8 @@ public abstract class ConnectionConfiguration<T> : IConnectionConfigurationValue
111
111
private bool _enableHttpCompression ;
112
112
bool IConnectionConfigurationValues . EnableHttpCompression => _enableHttpCompression ;
113
113
114
- private bool _httpPipeliningEnabled = true ;
115
- bool IConnectionConfigurationValues . HttpPipeliningEnabled => _httpPipeliningEnabled ;
114
+ private bool _enableHttpPipelining = true ;
115
+ bool IConnectionConfigurationValues . HttpPipeliningEnabled => _enableHttpPipelining ;
116
116
117
117
private bool _throwExceptions ;
118
118
bool IConnectionConfigurationValues . ThrowExceptions => _throwExceptions ;
@@ -140,13 +140,13 @@ private static void DefaultApiCallHandler(IApiCallDetails status) { }
140
140
IConnection IConnectionConfigurationValues . Connection => _connection ;
141
141
142
142
[ System . Diagnostics . CodeAnalysis . SuppressMessage (
143
- "Potential Code Quality Issues" , "RECS0021:Warns about calls to virtual member functions occuring in the constructor" ,
143
+ "Potential Code Quality Issues" , "RECS0021:Warns about calls to virtual member functions occuring in the constructor" ,
144
144
Justification = "We want the virtual method to run on most derived" ) ]
145
145
protected ConnectionConfiguration ( IConnectionPool connectionPool , IConnection connection , IElasticsearchSerializer serializer )
146
146
{
147
147
this . _connectionPool = connectionPool ;
148
- this . _connection = connection ?? new HttpConnection ( ) ;
149
- // ReSharper disable once VirtualMemberCallInContructor
148
+ this . _connection = connection ?? new HttpConnection ( ) ;
149
+ // ReSharper disable once VirtualMemberCallInContructor
150
150
this . _serializer = serializer ?? this . DefaultSerializer ( ) ;
151
151
152
152
this . _requestTimeout = ConnectionConfiguration . DefaultTimeout ;
@@ -162,95 +162,95 @@ protected ConnectionConfiguration(IConnectionPool connectionPool, IConnection co
162
162
public T EnableTcpKeepAlive ( TimeSpan keepAliveTime , TimeSpan keepAliveInterval ) =>
163
163
Assign ( a => { this . _keepAliveTime = keepAliveTime ; this . _keepAliveInterval = keepAliveInterval ; } ) ;
164
164
165
- public T MaximumRetries ( int maxRetries ) => Assign ( a => a . _maxRetries = maxRetries ) ;
166
-
165
+ public T MaximumRetries ( int maxRetries ) => Assign ( a => a . _maxRetries = maxRetries ) ;
166
+
167
167
/// <summary>
168
168
/// On connection pools that support reseeding setting this to true (default) will resniff the cluster when a call fails
169
169
/// </summary>
170
- public T SniffOnConnectionFault ( bool sniffsOnConnectionFault = true ) => Assign ( a => a . _sniffOnConnectionFault = sniffsOnConnectionFault ) ;
171
-
170
+ public T SniffOnConnectionFault ( bool sniffsOnConnectionFault = true ) => Assign ( a => a . _sniffOnConnectionFault = sniffsOnConnectionFault ) ;
171
+
172
172
/// <summary>
173
173
/// Enables sniffing on first usage of a connection pool if that pool supports reseeding, defaults to true
174
174
/// </summary>
175
- public T SniffOnStartup ( bool sniffsOnStartup = true ) => Assign ( a => a . _sniffOnStartup = sniffsOnStartup ) ;
176
-
175
+ public T SniffOnStartup ( bool sniffsOnStartup = true ) => Assign ( a => a . _sniffOnStartup = sniffsOnStartup ) ;
176
+
177
177
/// <summary>
178
178
/// Set the duration after which a cluster state is considered stale and a sniff should be performed again.
179
179
/// An IConnectionPool has to signal it supports reseeding otherwise sniffing will never happen.
180
180
/// Defaults to 1 hour.
181
181
/// Set to null to disable completely. Sniffing will only ever happen on ConnectionPools that return true for SupportsReseeding
182
182
/// </summary>
183
183
/// <param name="sniffLifeSpan">The duration a clusterstate is considered fresh, set to null to disable periodic sniffing</param>
184
- public T SniffLifeSpan ( TimeSpan ? sniffLifeSpan ) => Assign ( a => a . _sniffLifeSpan = sniffLifeSpan ) ;
185
-
184
+ public T SniffLifeSpan ( TimeSpan ? sniffLifeSpan ) => Assign ( a => a . _sniffLifeSpan = sniffLifeSpan ) ;
185
+
186
186
/// <summary>
187
187
/// Enable gzip compressed requests and responses, do note that you need to configure elasticsearch to set this
188
188
/// <para>http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-http.html"</para>
189
189
/// </summary>
190
190
public T EnableHttpCompression ( bool enabled = true ) => Assign ( a => a . _enableHttpCompression = enabled ) ;
191
191
192
- public T DisableAutomaticProxyDetection ( bool disable = true ) => Assign ( a => a . _disableAutomaticProxyDetection = disable ) ;
193
-
192
+ public T DisableAutomaticProxyDetection ( bool disable = true ) => Assign ( a => a . _disableAutomaticProxyDetection = disable ) ;
193
+
194
194
/// <summary>
195
195
/// Instead of following a c/go like error checking on response.IsValid always throw an exception
196
196
/// on the client when a call resulted in an exception on either the client or the Elasticsearch server.
197
197
/// <para>Reasons for such exceptions could be search parser errors, index missing exceptions, etc...</para>
198
198
/// </summary>
199
- public T ThrowExceptions ( bool alwaysThrow = true ) => Assign ( a => a . _throwExceptions = alwaysThrow ) ;
200
-
199
+ public T ThrowExceptions ( bool alwaysThrow = true ) => Assign ( a => a . _throwExceptions = alwaysThrow ) ;
200
+
201
201
/// <summary>
202
202
/// When a node is used for the very first time or when it's used for the first time after it has been marked dead
203
203
/// a ping with a very low timeout is send to the node to make sure that when it's still dead it reports it as fast as possible.
204
204
/// You can disable these pings globally here if you rather have it fail on the possible slower original request
205
205
/// </summary>
206
- public T DisablePing ( bool disable = true ) => Assign ( a => a . _disablePings = disable ) ;
207
-
206
+ public T DisablePing ( bool disable = true ) => Assign ( a => a . _disablePings = disable ) ;
207
+
208
208
/// <summary>
209
209
/// This NameValueCollection will be appended to every url NEST calls, great if you need to pass i.e an API key.
210
210
/// </summary>
211
- public T GlobalQueryStringParameters ( NameValueCollection queryStringParameters ) => Assign ( a => a . _queryString . Add ( queryStringParameters ) ) ;
212
-
211
+ public T GlobalQueryStringParameters ( NameValueCollection queryStringParameters ) => Assign ( a => a . _queryString . Add ( queryStringParameters ) ) ;
212
+
213
213
/// <summary>
214
214
/// a NameValueCollection that will be send as headers for each request
215
215
/// </summary>
216
- public T GlobalHeaders ( NameValueCollection headers ) => Assign ( a => a . _headers . Add ( headers ) ) ;
217
-
216
+ public T GlobalHeaders ( NameValueCollection headers ) => Assign ( a => a . _headers . Add ( headers ) ) ;
217
+
218
218
/// <summary>
219
219
/// Sets the default timeout in milliseconds for each request to Elasticsearch.
220
220
/// NOTE: You can set this to a high value here, and specify the timeout on Elasticsearch's side.
221
221
/// </summary>
222
222
/// <param name="timeout">time out in milliseconds</param>
223
- public T RequestTimeout ( TimeSpan timeout ) => Assign ( a => a . _requestTimeout = timeout ) ;
224
-
223
+ public T RequestTimeout ( TimeSpan timeout ) => Assign ( a => a . _requestTimeout = timeout ) ;
224
+
225
225
/// <summary>
226
226
/// Sets the default ping timeout in milliseconds for ping requests, which are used
227
227
/// to determine whether a node is alive. Pings should fail as fast as possible.
228
228
/// </summary>
229
229
/// <param name="timeout">The ping timeout in milliseconds defaults to 1000, or 2000 is using SSL.</param>
230
- public T PingTimeout ( TimeSpan timeout ) => Assign ( a => a . _pingTimeout = timeout ) ;
231
-
230
+ public T PingTimeout ( TimeSpan timeout ) => Assign ( a => a . _pingTimeout = timeout ) ;
231
+
232
232
/// <summary>
233
233
/// Sets the default dead timeout factor when a node has been marked dead.
234
234
/// </summary>
235
235
/// <remarks>Some connection pools may use a flat timeout whilst others take this factor and increase it exponentially</remarks>
236
236
/// <param name="timeout"></param>
237
- public T DeadTimeout ( TimeSpan timeout ) => Assign ( a => a . _deadTimeout = timeout ) ;
238
-
237
+ public T DeadTimeout ( TimeSpan timeout ) => Assign ( a => a . _deadTimeout = timeout ) ;
238
+
239
239
/// <summary>
240
240
/// Sets the maximum time a node can be marked dead.
241
241
/// Different implementations of IConnectionPool may choose a different default.
242
242
/// </summary>
243
243
/// <param name="timeout">The timeout in milliseconds</param>
244
- public T MaxDeadTimeout ( TimeSpan timeout ) => Assign ( a => a . _maxDeadTimeout = timeout ) ;
245
-
244
+ public T MaxDeadTimeout ( TimeSpan timeout ) => Assign ( a => a . _maxDeadTimeout = timeout ) ;
245
+
246
246
/// <summary>
247
247
/// Limits the total runtime including retries separately from <see cref="RequestTimeout"/>
248
248
/// <pre>
249
249
/// When not specified defaults to <see cref="RequestTimeout"/> which itself defaults to 60seconds
250
250
/// </pre>
251
251
/// </summary>
252
- public T MaxRetryTimeout ( TimeSpan maxRetryTimeout ) => Assign ( a => a . _maxRetryTimeout = maxRetryTimeout ) ;
253
-
252
+ public T MaxRetryTimeout ( TimeSpan maxRetryTimeout ) => Assign ( a => a . _maxRetryTimeout = maxRetryTimeout ) ;
253
+
254
254
/// <summary>
255
255
/// If your connection has to go through proxy use this method to specify the proxy url
256
256
/// </summary>
@@ -261,33 +261,33 @@ public T Proxy(Uri proxyAdress, string username, string password)
261
261
this . _proxyUsername = username ;
262
262
this . _proxyPassword = password ;
263
263
return ( T ) this ;
264
- }
265
-
264
+ }
265
+
266
266
/// <summary>
267
267
/// Forces all requests to have ?pretty=true, causing elasticsearch to return formatted json.
268
268
/// Also forces the client to send out formatted json. Defaults to false
269
269
/// </summary>
270
- public T PrettyJson ( bool b = true ) => Assign ( a =>
270
+ public T PrettyJson ( bool b = true ) => Assign ( a =>
271
271
{
272
272
this . _prettyJson = b ;
273
273
if ( ! b && this . _queryString [ "pretty" ] != null ) this . _queryString . Remove ( "pretty" ) ;
274
274
else if ( b && this . _queryString [ "pretty" ] == null )
275
- this . GlobalQueryStringParameters ( new NameValueCollection { { "pretty" , b . ToString ( ) . ToLowerInvariant ( ) } } ) ;
276
- } ) ;
277
-
275
+ this . GlobalQueryStringParameters ( new NameValueCollection { { "pretty" , b . ToString ( ) . ToLowerInvariant ( ) } } ) ;
276
+ } ) ;
277
+
278
278
/// <summary>
279
279
/// Make sure the reponse bytes are always available on the ElasticsearchResponse object
280
280
/// <para>Note: that depending on the registered serializer this may cause the respond to be read in memory first</para>
281
281
/// </summary>
282
- public T DisableDirectStreaming ( bool b = true ) => Assign ( a => a . _disableDirectStreaming = b ) ;
283
-
282
+ public T DisableDirectStreaming ( bool b = true ) => Assign ( a => a . _disableDirectStreaming = b ) ;
283
+
284
284
/// <summary>
285
285
/// Global callback for every response that NEST receives, useful for custom logging.
286
286
/// Calling this multiple times will register multiple listeners
287
287
/// </summary>
288
288
public T ConnectionStatusHandler ( Action < IApiCallDetails > handler ) =>
289
- Assign ( a => a . _apiCallHandler += handler ?? DefaultApiCallHandler ) ;
290
-
289
+ Assign ( a => a . _apiCallHandler += handler ?? DefaultApiCallHandler ) ;
290
+
291
291
/// <summary>
292
292
/// Basic access authentication credentials to specify with all requests.
293
293
/// </summary>
@@ -299,13 +299,13 @@ public T BasicAuthentication(string userName, string password)
299
299
Password = password
300
300
} ;
301
301
return ( T ) this ;
302
- }
303
-
302
+ }
303
+
304
304
/// <summary>
305
305
/// Allows for requests to be pipelined. http://en.wikipedia.org/wiki/HTTP_pipelining
306
306
/// <para>Note: HTTP pipelining must also be enabled in Elasticsearch for this to work properly.</para>
307
307
/// </summary>
308
- public T HttpPipeliningEnabled ( bool enabled = true ) => Assign ( a => a . _httpPipeliningEnabled = enabled ) ;
308
+ public T EnableHttpPipelining ( bool enabled = true ) => Assign ( a => a . _enableHttpPipelining = enabled ) ;
309
309
}
310
310
}
311
311
0 commit comments