@@ -132,6 +132,7 @@ internal class StringValue : Attribute
132132 #region Properties and Fields
133133 private ApiAuthManager authManger ;
134134 private HttpService httpService ;
135+ private int maxRetries ;
135136 private readonly DynamicJsonSerializer serializer = new DynamicJsonSerializer ( ) ;
136137 /// <summary>
137138 /// The HTTP headers to be included on all REST requests
@@ -176,6 +177,7 @@ public string WebServiceUrl
176177 /// <param name="authManger">The authorization manager to use when authentication requires it. If no driver is
177178 /// provided a console authentication manager will be used which does not allow SSO authentication.</param>
178179 /// <param name="webServiceVersion">The WSAPI version to use (defaults to DEFAULT_WSAPI_VERSION)</param>
180+ /// <param name="maxRetries">Requests will be attempted a number of times (defaults to 3)</param>
179181 /// <example>
180182 /// For a console application, no authentication manager is needed as shown in this example.
181183 /// <code language="C#">
@@ -196,7 +198,7 @@ public string WebServiceUrl
196198 /// wpfAuthMgr = new RestApiAuthMgrWpf(applicationToken, encryptionKey, encryptionUtilities);
197199 /// </code>
198200 /// </example>
199- public RallyRestApi ( ApiAuthManager authManger = null , string webServiceVersion = DEFAULT_WSAPI_VERSION )
201+ public RallyRestApi ( ApiAuthManager authManger = null , string webServiceVersion = DEFAULT_WSAPI_VERSION , int maxRetries = 3 )
200202 {
201203 // NOTE: The example for using the RestApiAuthMgrWpf is also shown there. Make sure you
202204 // update both if you change it.
@@ -211,6 +213,8 @@ public RallyRestApi(ApiAuthManager authManger = null, string webServiceVersion =
211213 WsapiVersion = DEFAULT_WSAPI_VERSION ;
212214
213215 AuthenticationState = AuthenticationResult . NotAuthorized ;
216+
217+ this . maxRetries = maxRetries ;
214218 }
215219 #endregion
216220
@@ -1339,7 +1343,7 @@ private DynamicJsonObject DoGetAsPost(Request request, bool retry = true, int re
13391343 Dictionary < string , string > processedHeaders = GetProcessedHeaders ( ) ;
13401344 DynamicJsonObject response = serializer . Deserialize ( httpService . GetAsPost ( GetSecuredUri ( uri ) , data , processedHeaders ) ) ;
13411345
1342- if ( retry && response [ response . Fields . First ( ) ] . Errors . Count > 0 && retryCounter < 3 )
1346+ if ( retry && response [ response . Fields . First ( ) ] . Errors . Count > 0 && retryCounter < this . maxRetries )
13431347 {
13441348 ConnectionInfo . SecurityToken = GetSecurityToken ( ) ;
13451349 httpService = new HttpService ( authManger , ConnectionInfo ) ;
@@ -1351,7 +1355,7 @@ private DynamicJsonObject DoGetAsPost(Request request, bool retry = true, int re
13511355 }
13521356 catch ( Exception )
13531357 {
1354- if ( retryCounter < 3 )
1358+ if ( retryCounter < this . maxRetries )
13551359 {
13561360 Thread . Sleep ( retrySleepTime * retryCounter ) ;
13571361 return DoGetAsPost ( request , true , ++ retryCounter ) ;
@@ -1378,7 +1382,7 @@ private DynamicJsonObject DoGet(Uri uri, bool retry = true, int retryCounter = 1
13781382 Dictionary < string , string > processedHeaders = GetProcessedHeaders ( ) ;
13791383 DynamicJsonObject response = serializer . Deserialize ( httpService . Get ( uri , processedHeaders ) ) ;
13801384
1381- if ( retry && response [ response . Fields . First ( ) ] . Errors . Count > 0 && retryCounter < 3 )
1385+ if ( retry && response [ response . Fields . First ( ) ] . Errors . Count > 0 && retryCounter < this . maxRetries )
13821386 {
13831387 ConnectionInfo . SecurityToken = GetSecurityToken ( ) ;
13841388 httpService = new HttpService ( authManger , ConnectionInfo ) ;
@@ -1390,7 +1394,7 @@ private DynamicJsonObject DoGet(Uri uri, bool retry = true, int retryCounter = 1
13901394 }
13911395 catch ( Exception )
13921396 {
1393- if ( retryCounter < 3 )
1397+ if ( retryCounter < this . maxRetries )
13941398 {
13951399 Thread . Sleep ( retrySleepTime * retryCounter ) ;
13961400 return DoGet ( uri , true , ++ retryCounter ) ;
@@ -1417,7 +1421,7 @@ private DynamicJsonObject DoPost(Uri uri, DynamicJsonObject data, bool retry = t
14171421 Dictionary < string , string > processedHeaders = GetProcessedHeaders ( ) ;
14181422 var response = serializer . Deserialize ( httpService . Post ( GetSecuredUri ( uri ) , serializer . Serialize ( data ) , processedHeaders ) ) ;
14191423
1420- if ( retry && response [ response . Fields . First ( ) ] . Errors . Count > 0 && retryCounter < 3 )
1424+ if ( retry && response [ response . Fields . First ( ) ] . Errors . Count > 0 && retryCounter < this . maxRetries )
14211425 {
14221426 ConnectionInfo . SecurityToken = GetSecurityToken ( ) ;
14231427 httpService = new HttpService ( authManger , ConnectionInfo ) ;
@@ -1429,7 +1433,7 @@ private DynamicJsonObject DoPost(Uri uri, DynamicJsonObject data, bool retry = t
14291433 }
14301434 catch ( Exception )
14311435 {
1432- if ( retryCounter < 3 )
1436+ if ( retryCounter < this . maxRetries )
14331437 {
14341438 Thread . Sleep ( retrySleepTime * retryCounter ) ;
14351439 return DoPost ( uri , data , true , ++ retryCounter ) ;
@@ -1479,7 +1483,7 @@ private string GetSecurityToken()
14791483 {
14801484 try
14811485 {
1482- DynamicJsonObject securityTokenResponse = DoGet ( new Uri ( GetFullyQualifiedRef ( SECURITY_ENDPOINT ) ) ) ;
1486+ DynamicJsonObject securityTokenResponse = DoGet ( new Uri ( GetFullyQualifiedRef ( SECURITY_ENDPOINT ) ) , this . maxRetries > 1 ) ;
14831487 return securityTokenResponse [ "OperationResult" ] [ "SecurityToken" ] ;
14841488 }
14851489 catch
0 commit comments