@@ -120,6 +120,10 @@ internal class StringValue : Attribute
120120 /// </summary>
121121 public const string DEFAULT_WSAPI_VERSION = "v2.0" ;
122122 /// <summary>
123+ /// The default Trace fields
124+ /// </summary>
125+ public const TraceFieldEnum DEFAULT_TRACE_FIELDS = TraceFieldEnum . Data | TraceFieldEnum . Headers | TraceFieldEnum . Cookies ;
126+ /// <summary>
123127 /// The default server to use: (https://rally1.rallydev.com)
124128 /// </summary>
125129 public const string DEFAULT_SERVER = "https://rally1.rallydev.com" ;
@@ -132,6 +136,7 @@ internal class StringValue : Attribute
132136 #region Properties and Fields
133137 private ApiAuthManager authManger ;
134138 private HttpService httpService ;
139+ private int maxRetries ;
135140 private readonly DynamicJsonSerializer serializer = new DynamicJsonSerializer ( ) ;
136141 /// <summary>
137142 /// The HTTP headers to be included on all REST requests
@@ -176,6 +181,8 @@ public string WebServiceUrl
176181 /// <param name="authManger">The authorization manager to use when authentication requires it. If no driver is
177182 /// provided a console authentication manager will be used which does not allow SSO authentication.</param>
178183 /// <param name="webServiceVersion">The WSAPI version to use (defaults to DEFAULT_WSAPI_VERSION)</param>
184+ /// <param name="maxRetries">Requests will be attempted a number of times (defaults to 3)</param>
185+ /// <param name="traceInfo">Controls diagnostic trace information being logged</param>
179186 /// <example>
180187 /// For a console application, no authentication manager is needed as shown in this example.
181188 /// <code language="C#">
@@ -196,13 +203,15 @@ public string WebServiceUrl
196203 /// wpfAuthMgr = new RestApiAuthMgrWpf(applicationToken, encryptionKey, encryptionUtilities);
197204 /// </code>
198205 /// </example>
199- public RallyRestApi ( ApiAuthManager authManger = null , string webServiceVersion = DEFAULT_WSAPI_VERSION )
206+ public RallyRestApi ( ApiAuthManager authManger = null , string webServiceVersion = DEFAULT_WSAPI_VERSION , int maxRetries = 3 , TraceFieldEnum traceInfo = RallyRestApi . DEFAULT_TRACE_FIELDS )
200207 {
201208 // NOTE: The example for using the RestApiAuthMgrWpf is also shown there. Make sure you
202209 // update both if you change it.
203210
211+ TraceHelper . TraceFields = traceInfo ;
212+
204213 if ( authManger == null )
205- authManger = new ApiConsoleAuthManager ( ) ;
214+ authManger = new ApiConsoleAuthManager ( webServiceVersion , traceInfo ) ;
206215
207216 this . authManger = authManger ;
208217
@@ -211,6 +220,8 @@ public RallyRestApi(ApiAuthManager authManger = null, string webServiceVersion =
211220 WsapiVersion = DEFAULT_WSAPI_VERSION ;
212221
213222 AuthenticationState = AuthenticationResult . NotAuthorized ;
223+
224+ this . maxRetries = maxRetries ;
214225 }
215226 #endregion
216227
@@ -593,7 +604,7 @@ public QueryResult Query(Request request)
593604 alreadyDownloadedItems = request . Start - 1 + request . PageSize ;
594605 }
595606
596- Trace . TraceInformation ( "The number of threaded requests is : {0}" , subsequentQueries . Count ) ;
607+ TraceHelper . TraceMessage ( "The number of threaded requests is : {0}" , subsequentQueries . Count ) ;
597608
598609 var resultDictionary = new Dictionary < int , QueryResult > ( ) ;
599610 Parallel . ForEach ( subsequentQueries , new ParallelOptions { MaxDegreeOfParallelism = MAX_THREADS_ALLOWED } , request1 =>
@@ -1339,7 +1350,7 @@ private DynamicJsonObject DoGetAsPost(Request request, bool retry = true, int re
13391350 Dictionary < string , string > processedHeaders = GetProcessedHeaders ( ) ;
13401351 DynamicJsonObject response = serializer . Deserialize ( httpService . GetAsPost ( GetSecuredUri ( uri ) , data , processedHeaders ) ) ;
13411352
1342- if ( retry && response [ response . Fields . First ( ) ] . Errors . Count > 0 && retryCounter < 3 )
1353+ if ( retry && response [ response . Fields . First ( ) ] . Errors . Count > 0 && retryCounter < this . maxRetries )
13431354 {
13441355 ConnectionInfo . SecurityToken = GetSecurityToken ( ) ;
13451356 httpService = new HttpService ( authManger , ConnectionInfo ) ;
@@ -1351,7 +1362,7 @@ private DynamicJsonObject DoGetAsPost(Request request, bool retry = true, int re
13511362 }
13521363 catch ( Exception )
13531364 {
1354- if ( retryCounter < 3 )
1365+ if ( retryCounter < this . maxRetries )
13551366 {
13561367 Thread . Sleep ( retrySleepTime * retryCounter ) ;
13571368 return DoGetAsPost ( request , true , ++ retryCounter ) ;
@@ -1378,7 +1389,7 @@ private DynamicJsonObject DoGet(Uri uri, bool retry = true, int retryCounter = 1
13781389 Dictionary < string , string > processedHeaders = GetProcessedHeaders ( ) ;
13791390 DynamicJsonObject response = serializer . Deserialize ( httpService . Get ( uri , processedHeaders ) ) ;
13801391
1381- if ( retry && response [ response . Fields . First ( ) ] . Errors . Count > 0 && retryCounter < 3 )
1392+ if ( retry && response [ response . Fields . First ( ) ] . Errors . Count > 0 && retryCounter < this . maxRetries )
13821393 {
13831394 ConnectionInfo . SecurityToken = GetSecurityToken ( ) ;
13841395 httpService = new HttpService ( authManger , ConnectionInfo ) ;
@@ -1390,7 +1401,7 @@ private DynamicJsonObject DoGet(Uri uri, bool retry = true, int retryCounter = 1
13901401 }
13911402 catch ( Exception )
13921403 {
1393- if ( retryCounter < 3 )
1404+ if ( retryCounter < this . maxRetries )
13941405 {
13951406 Thread . Sleep ( retrySleepTime * retryCounter ) ;
13961407 return DoGet ( uri , true , ++ retryCounter ) ;
@@ -1417,7 +1428,7 @@ private DynamicJsonObject DoPost(Uri uri, DynamicJsonObject data, bool retry = t
14171428 Dictionary < string , string > processedHeaders = GetProcessedHeaders ( ) ;
14181429 var response = serializer . Deserialize ( httpService . Post ( GetSecuredUri ( uri ) , serializer . Serialize ( data ) , processedHeaders ) ) ;
14191430
1420- if ( retry && response [ response . Fields . First ( ) ] . Errors . Count > 0 && retryCounter < 3 )
1431+ if ( retry && response [ response . Fields . First ( ) ] . Errors . Count > 0 && retryCounter < this . maxRetries )
14211432 {
14221433 ConnectionInfo . SecurityToken = GetSecurityToken ( ) ;
14231434 httpService = new HttpService ( authManger , ConnectionInfo ) ;
@@ -1429,7 +1440,7 @@ private DynamicJsonObject DoPost(Uri uri, DynamicJsonObject data, bool retry = t
14291440 }
14301441 catch ( Exception )
14311442 {
1432- if ( retryCounter < 3 )
1443+ if ( retryCounter < this . maxRetries )
14331444 {
14341445 Thread . Sleep ( retrySleepTime * retryCounter ) ;
14351446 return DoPost ( uri , data , true , ++ retryCounter ) ;
@@ -1479,7 +1490,7 @@ private string GetSecurityToken()
14791490 {
14801491 try
14811492 {
1482- DynamicJsonObject securityTokenResponse = DoGet ( new Uri ( GetFullyQualifiedRef ( SECURITY_ENDPOINT ) ) ) ;
1493+ DynamicJsonObject securityTokenResponse = DoGet ( new Uri ( GetFullyQualifiedRef ( SECURITY_ENDPOINT ) ) , this . maxRetries > 1 ) ;
14831494 return securityTokenResponse [ "OperationResult" ] [ "SecurityToken" ] ;
14841495 }
14851496 catch
0 commit comments