@@ -174,55 +174,14 @@ public AmqpTcpEndpoint Endpoint
174
174
}
175
175
}
176
176
177
+ public Uri uri
178
+ {
179
+ set { SetUri ( value ) ; }
180
+ }
181
+
177
182
public String Uri
178
183
{
179
- set
180
- {
181
- Endpoint = new AmqpTcpEndpoint ( ) ;
182
-
183
- Uri uri = new Uri ( value , UriKind . Absolute ) ;
184
-
185
- if ( "amqp" . CompareTo ( uri . Scheme . ToLower ( ) ) == 0 ) {
186
- // nothing special to do
187
- } else if ( "amqps" . CompareTo ( uri . Scheme . ToLower ( ) ) == 0 ) {
188
- Ssl . Enabled = true ;
189
- Ssl . AcceptablePolicyErrors = SslPolicyErrors . RemoteCertificateNameMismatch ;
190
- Port = AmqpTcpEndpoint . DefaultAmqpSslPort ;
191
- } else {
192
- throw new ArgumentException ( "Wrong scheme in AMQP URI: " +
193
- value ) ;
194
- }
195
- string host = uri . Host ;
196
- if ( ! String . IsNullOrEmpty ( host ) ) {
197
- HostName = host ;
198
- }
199
- Ssl . ServerName = HostName ;
200
-
201
- int port = uri . Port ;
202
- if ( port != - 1 ) {
203
- Port = port ;
204
- }
205
-
206
- string userInfo = uri . UserInfo ;
207
- if ( ! String . IsNullOrEmpty ( userInfo ) ) {
208
- string [ ] userPass = userInfo . Split ( ':' ) ;
209
- if ( userPass . Length > 2 ) {
210
- throw new ArgumentException ( "Bad user info in AMQP URI: " + value ) ;
211
- }
212
- UserName = UriDecode ( userPass [ 0 ] ) ;
213
- if ( userPass . Length == 2 ) {
214
- Password = UriDecode ( userPass [ 1 ] ) ;
215
- }
216
- }
217
-
218
- /* C# automatically changes URIs into a canonical form
219
- that has at least the path segment "/". */
220
- if ( uri . Segments . Length > 2 ) {
221
- throw new ArgumentException ( "Multiple segments in path of AMQP URI: " + String . Join ( ", " , uri . Segments ) ) ;
222
- } else if ( uri . Segments . Length == 2 ) {
223
- VirtualHost = UriDecode ( uri . Segments [ 1 ] ) ;
224
- }
225
- }
184
+ set { SetUri ( new Uri ( value , UriKind . Absolute ) ) ; }
226
185
}
227
186
228
187
///<summary>Construct a fresh instance, with all fields set to
@@ -374,6 +333,57 @@ public AuthMechanismFactory AuthMechanismFactory(string[] mechs) {
374
333
return null ;
375
334
}
376
335
336
+
337
+ private void SetUri ( Uri uri )
338
+ {
339
+ Endpoint = new AmqpTcpEndpoint ( ) ;
340
+
341
+ if ( "amqp" . CompareTo ( uri . Scheme . ToLower ( ) ) == 0 ) {
342
+ // nothing special to do
343
+ } else if ( "amqps" . CompareTo ( uri . Scheme . ToLower ( ) ) == 0 ) {
344
+ Ssl . Enabled = true ;
345
+ Ssl . AcceptablePolicyErrors =
346
+ SslPolicyErrors . RemoteCertificateNameMismatch ;
347
+ Port = AmqpTcpEndpoint . DefaultAmqpSslPort ;
348
+ } else {
349
+ throw new ArgumentException ( "Wrong scheme in AMQP URI: " +
350
+ uri . Scheme ) ;
351
+ }
352
+ string host = uri . Host ;
353
+ if ( ! String . IsNullOrEmpty ( host ) ) {
354
+ HostName = host ;
355
+ }
356
+ Ssl . ServerName = HostName ;
357
+
358
+ int port = uri . Port ;
359
+ if ( port != - 1 ) {
360
+ Port = port ;
361
+ }
362
+
363
+ string userInfo = uri . UserInfo ;
364
+ if ( ! String . IsNullOrEmpty ( userInfo ) ) {
365
+ string [ ] userPass = userInfo . Split ( ':' ) ;
366
+ if ( userPass . Length > 2 ) {
367
+ throw new ArgumentException ( "Bad user info in AMQP " +
368
+ "URI: " + userInfo ) ;
369
+ }
370
+ UserName = UriDecode ( userPass [ 0 ] ) ;
371
+ if ( userPass . Length == 2 ) {
372
+ Password = UriDecode ( userPass [ 1 ] ) ;
373
+ }
374
+ }
375
+
376
+ /* C# automatically changes URIs into a canonical form
377
+ that has at least the path segment "/". */
378
+ if ( uri . Segments . Length > 2 ) {
379
+ throw new ArgumentException ( "Multiple segments in " +
380
+ "path of AMQP URI: " +
381
+ String . Join ( ", " , uri . Segments ) ) ;
382
+ } else if ( uri . Segments . Length == 2 ) {
383
+ VirtualHost = UriDecode ( uri . Segments [ 1 ] ) ;
384
+ }
385
+ }
386
+
377
387
//<summary>Unescape a string, protecting '+'.</summary>
378
388
private string UriDecode ( string uri ) {
379
389
return Uri . UnescapeDataString ( uri . Replace ( "+" , "%2B" ) ) ;
0 commit comments