4
4
5
5
namespace Nest
6
6
{
7
- public class ConnectionSettings : IConnectionSettings
8
- {
9
- private string _defaultIndex ;
10
- public string DefaultIndex
11
- {
12
- get
13
- {
14
- if ( this . _defaultIndex . IsNullOrEmpty ( ) )
15
- throw new NullReferenceException ( "No default index set on connection!" ) ;
16
- return this . _defaultIndex ;
17
- }
18
- private set { this . _defaultIndex = value ; }
19
- }
20
- public Uri Uri { get ; private set ; }
21
- public string Host { get ; private set ; }
22
- public int Port { get ; private set ; }
23
- public int Timeout { get ; private set ; }
24
- public string ProxyUsername { get ; private set ; }
25
- public string ProxyPassword { get ; private set ; }
26
- public string ProxyAddress { get ; private set ; }
27
-
28
- public int MaximumAsyncConnections { get ; private set ; }
29
- public bool UsesPrettyResponses { get ; private set ; }
7
+ public class ConnectionSettings : IConnectionSettings
8
+ {
9
+ private string _defaultIndex ;
10
+ public string DefaultIndex
11
+ {
12
+ get
13
+ {
14
+ if ( this . _defaultIndex . IsNullOrEmpty ( ) )
15
+ throw new NullReferenceException ( "No default index set on connection!" ) ;
16
+ return this . _defaultIndex ;
17
+ }
18
+ private set { this . _defaultIndex = value ; }
19
+ }
20
+ public Uri Uri { get ; private set ; }
21
+ public string Host { get ; private set ; }
22
+ public int Port { get ; private set ; }
23
+ public int Timeout { get ; private set ; }
24
+ public string ProxyUsername { get ; private set ; }
25
+ public string ProxyPassword { get ; private set ; }
26
+ public string ProxyAddress { get ; private set ; }
27
+
28
+ public int MaximumAsyncConnections { get ; private set ; }
29
+ public bool UsesPrettyResponses { get ; private set ; }
30
30
public bool TraceEnabled { get ; private set ; }
31
31
public bool DontDoubleEscapePathDotsAndSlashes { get ; private set ; }
32
32
33
- public Func < Type , string > DefaultTypeNameInferrer { get ; private set ; }
34
- public Action < ConnectionStatus > ConnectionStatusHandler { get ; private set ; }
35
- public FluentDictionary < Type , string > DefaultIndices { get ; private set ; }
36
- public FluentDictionary < Type , string > DefaultTypeNames { get ; private set ; }
37
- public NameValueCollection QueryStringParameters { get ; private set ; }
33
+ public Func < Type , string > DefaultTypeNameInferrer { get ; private set ; }
34
+ public Action < ConnectionStatus > ConnectionStatusHandler { get ; private set ; }
35
+ public FluentDictionary < Type , string > DefaultIndices { get ; private set ; }
36
+ public FluentDictionary < Type , string > DefaultTypeNames { get ; private set ; }
37
+ public NameValueCollection QueryStringParameters { get ; private set ; }
38
38
39
- public ConnectionSettings ( Uri uri )
40
- {
41
- uri . ThrowIfNull ( "uri" ) ;
39
+ public ConnectionSettings ( Uri uri )
40
+ {
41
+ uri . ThrowIfNull ( "uri" ) ;
42
42
43
- this . Timeout = 60 * 1000 ;
43
+ this . Timeout = 60 * 1000 ;
44
44
45
- this . Uri = uri ;
46
- if ( ! uri . ToString ( ) . EndsWith ( "/" ) )
47
- this . Uri = new Uri ( uri . ToString ( ) + "/" ) ;
48
- this . Host = uri . Host ;
49
- this . Port = uri . Port ;
45
+ this . Uri = uri ;
46
+ if ( ! uri . ToString ( ) . EndsWith ( "/" ) )
47
+ this . Uri = new Uri ( uri . ToString ( ) + "/" ) ;
48
+ this . Host = uri . Host ;
49
+ this . Port = uri . Port ;
50
50
51
- this . MaximumAsyncConnections = 20 ;
52
- this . DefaultTypeNameInferrer = this . LowerCaseAndPluralizeTypeNameInferrer ;
53
- this . DefaultIndices = new FluentDictionary < Type , string > ( ) ;
54
- this . DefaultTypeNames = new FluentDictionary < Type , string > ( ) ;
55
- this . ConnectionStatusHandler = this . ConnectionStatusDefaultHandler ;
56
- }
51
+ this . MaximumAsyncConnections = 20 ;
52
+ this . DefaultTypeNameInferrer = this . LowerCaseAndPluralizeTypeNameInferrer ;
53
+ this . DefaultIndices = new FluentDictionary < Type , string > ( ) ;
54
+ this . DefaultTypeNames = new FluentDictionary < Type , string > ( ) ;
55
+ this . ConnectionStatusHandler = this . ConnectionStatusDefaultHandler ;
56
+ }
57
57
58
58
/// <summary>
59
59
/// Enable Trace signals to the IConnection that it should put debug information on the Trace.
@@ -72,6 +72,10 @@ public ConnectionSettings EnableTrace(bool enabled = true)
72
72
/// <returns></returns>
73
73
public ConnectionSettings SetGlobalQueryStringParameters ( NameValueCollection queryStringParameters )
74
74
{
75
+ if ( this . QueryStringParameters != null )
76
+ {
77
+ this . QueryStringParameters . Add ( queryStringParameters ) ;
78
+ }
75
79
this . QueryStringParameters = queryStringParameters ;
76
80
return this ;
77
81
}
@@ -86,53 +90,54 @@ public ConnectionSettings SetTimeout(int timeout)
86
90
this . Timeout = timeout ;
87
91
return this ;
88
92
}
89
- /// <summary>
90
- /// Index to default to when no index is specified.
91
- /// </summary>
92
- /// <param name="defaultIndex">When null/empty/not set might throw NRE later on
93
- /// when not specifying index explicitly while indexing.
94
- /// </param>
95
- /// <returns></returns>
96
- public ConnectionSettings SetDefaultIndex ( string defaultIndex )
97
- {
98
- this . DefaultIndex = defaultIndex ;
99
- return this ;
100
- }
101
- /// <summary>
102
- /// Semaphore asynchronous connections automatically by giving
103
- /// it a maximum concurrent connections. Great to prevent
104
- /// out of memory exceptions
105
- /// </summary>
106
- /// <param name="maximum">defaults to 20</param>
107
- /// <returns></returns>
108
- public ConnectionSettings SetMaximumAsyncConnections ( int maximum )
109
- {
110
- this . MaximumAsyncConnections = maximum ;
111
- return this ;
112
- }
113
-
114
- /// <summary>
115
- /// If your connection has to go through proxy use this method to specify the proxy url
116
- /// </summary>
117
- /// <returns></returns>
118
- public ConnectionSettings SetProxy ( Uri proxyAdress , string username , string password )
119
- {
120
- proxyAdress . ThrowIfNull ( "proxyAdress" ) ;
121
- this . ProxyAddress = proxyAdress . ToString ( ) ;
122
- this . ProxyUsername = username ;
123
- this . ProxyPassword = password ;
124
- return this ;
125
- }
126
-
127
- /// <summary>
128
- /// Append ?pretty=true to requests, this helps to debug send and received json.
129
- /// </summary>
130
- /// <returns></returns>
131
- public ConnectionSettings UsePrettyResponses ( bool b = true )
132
- {
133
- this . UsesPrettyResponses = b ;
134
- return this ;
135
- }
93
+ /// <summary>
94
+ /// Index to default to when no index is specified.
95
+ /// </summary>
96
+ /// <param name="defaultIndex">When null/empty/not set might throw NRE later on
97
+ /// when not specifying index explicitly while indexing.
98
+ /// </param>
99
+ /// <returns></returns>
100
+ public ConnectionSettings SetDefaultIndex ( string defaultIndex )
101
+ {
102
+ this . DefaultIndex = defaultIndex ;
103
+ return this ;
104
+ }
105
+ /// <summary>
106
+ /// Semaphore asynchronous connections automatically by giving
107
+ /// it a maximum concurrent connections. Great to prevent
108
+ /// out of memory exceptions
109
+ /// </summary>
110
+ /// <param name="maximum">defaults to 20</param>
111
+ /// <returns></returns>
112
+ public ConnectionSettings SetMaximumAsyncConnections ( int maximum )
113
+ {
114
+ this . MaximumAsyncConnections = maximum ;
115
+ return this ;
116
+ }
117
+
118
+ /// <summary>
119
+ /// If your connection has to go through proxy use this method to specify the proxy url
120
+ /// </summary>
121
+ /// <returns></returns>
122
+ public ConnectionSettings SetProxy ( Uri proxyAdress , string username , string password )
123
+ {
124
+ proxyAdress . ThrowIfNull ( "proxyAdress" ) ;
125
+ this . ProxyAddress = proxyAdress . ToString ( ) ;
126
+ this . ProxyUsername = username ;
127
+ this . ProxyPassword = password ;
128
+ return this ;
129
+ }
130
+
131
+ /// <summary>
132
+ /// Append ?pretty=true to requests, this helps to debug send and received json.
133
+ /// </summary>
134
+ /// <returns></returns>
135
+ public ConnectionSettings UsePrettyResponses ( bool b = true )
136
+ {
137
+ this . UsesPrettyResponses = b ;
138
+ this . SetGlobalQueryStringParameters ( new NameValueCollection { { "pretty" , b . ToString ( ) . ToLowerInvariant ( ) } } ) ;
139
+ return this ;
140
+ }
136
141
137
142
/// <summary>
138
143
/// Append ?pretty=true to requests, this helps to debug send and received json.
@@ -144,43 +149,43 @@ public ConnectionSettings SetDontDoubleEscapePathDotsAndSlashes(bool b = true)
144
149
return this ;
145
150
}
146
151
147
- private string LowerCaseAndPluralizeTypeNameInferrer ( Type type )
148
- {
149
- type . ThrowIfNull ( "type" ) ;
150
- return Inflector . MakePlural ( type . Name ) . ToLower ( ) ;
151
- }
152
-
153
- private void ConnectionStatusDefaultHandler ( ConnectionStatus status )
154
- {
155
- return ;
156
- }
157
-
158
- public ConnectionSettings SetDefaultTypeNameInferrer ( Func < Type , string > defaultTypeNameInferrer )
159
- {
160
- defaultTypeNameInferrer . ThrowIfNull ( "defaultTypeNameInferrer" ) ;
161
- this . DefaultTypeNameInferrer = defaultTypeNameInferrer ;
162
- return this ;
163
- }
164
-
165
- public ConnectionSettings SetConnectionStatusHandler ( Action < ConnectionStatus > handler )
166
- {
167
- handler . ThrowIfNull ( "handler" ) ;
168
- this . ConnectionStatusHandler = handler ;
169
- return this ;
170
- }
171
-
172
- public ConnectionSettings MapDefaultTypeIndices ( Action < FluentDictionary < Type , string > > mappingSelector )
173
- {
174
- mappingSelector . ThrowIfNull ( "mappingSelector" ) ;
175
- mappingSelector ( this . DefaultIndices ) ;
176
- return this ;
177
- }
178
- public ConnectionSettings MapDefaultTypeNames ( Action < FluentDictionary < Type , string > > mappingSelector )
179
- {
180
- mappingSelector . ThrowIfNull ( "mappingSelector" ) ;
181
- mappingSelector ( this . DefaultTypeNames ) ;
182
- return this ;
183
- }
184
-
185
- }
152
+ private string LowerCaseAndPluralizeTypeNameInferrer ( Type type )
153
+ {
154
+ type . ThrowIfNull ( "type" ) ;
155
+ return Inflector . MakePlural ( type . Name ) . ToLower ( ) ;
156
+ }
157
+
158
+ private void ConnectionStatusDefaultHandler ( ConnectionStatus status )
159
+ {
160
+ return ;
161
+ }
162
+
163
+ public ConnectionSettings SetDefaultTypeNameInferrer ( Func < Type , string > defaultTypeNameInferrer )
164
+ {
165
+ defaultTypeNameInferrer . ThrowIfNull ( "defaultTypeNameInferrer" ) ;
166
+ this . DefaultTypeNameInferrer = defaultTypeNameInferrer ;
167
+ return this ;
168
+ }
169
+
170
+ public ConnectionSettings SetConnectionStatusHandler ( Action < ConnectionStatus > handler )
171
+ {
172
+ handler . ThrowIfNull ( "handler" ) ;
173
+ this . ConnectionStatusHandler = handler ;
174
+ return this ;
175
+ }
176
+
177
+ public ConnectionSettings MapDefaultTypeIndices ( Action < FluentDictionary < Type , string > > mappingSelector )
178
+ {
179
+ mappingSelector . ThrowIfNull ( "mappingSelector" ) ;
180
+ mappingSelector ( this . DefaultIndices ) ;
181
+ return this ;
182
+ }
183
+ public ConnectionSettings MapDefaultTypeNames ( Action < FluentDictionary < Type , string > > mappingSelector )
184
+ {
185
+ mappingSelector . ThrowIfNull ( "mappingSelector" ) ;
186
+ mappingSelector ( this . DefaultTypeNames ) ;
187
+ return this ;
188
+ }
189
+
190
+ }
186
191
}
0 commit comments