private bool ShouldFastFail( HttpRetryAfterApiState apiState, DateTime currentTime ) { if (apiState.Exception == null) { return(false); } TimeSpan remainingTimeBeforeRetryAfter = apiState.RetryAfterTime - currentTime; if (remainingTimeBeforeRetryAfter.Ticks <= 0) { return(false); } DateTime timeoutTime = this.firstCallStartTime + this.contextSettings.HttpTimeoutWindow; // If the Retry-After will happen first, just wait till Retry-After is done, and don't fast fail if (apiState.RetryAfterTime < timeoutTime) { Sleep(remainingTimeBeforeRetryAfter); return(false); } else { return(true); } }
public bool GetState( XboxLiveAPIName xboxLiveApi, out HttpRetryAfterApiState returnValue ) { lock (instanceLock) { return(this.apiStateMap.TryGetValue(xboxLiveApi, out returnValue)); } }
public void SetState( XboxLiveAPIName xboxLiveApi, HttpRetryAfterApiState state ) { lock (instanceLock) { this.apiStateMap[xboxLiveApi] = state; } }
private Task <XboxLiveHttpResponse> HandleFastFail(HttpRetryAfterApiState apiState) { XboxLiveHttpResponse httpCallResponse = apiState.HttpCallResponse; this.RouteServiceCall(httpCallResponse); TaskCompletionSource <XboxLiveHttpResponse> taskCompletionSource = new TaskCompletionSource <XboxLiveHttpResponse>(); taskCompletionSource.SetException(apiState.Exception); return(taskCompletionSource.Task); }
private void RecordServiceResult(XboxLiveHttpResponse httpCallResponse, Exception exception) { // Only remember result if there was an error and there was a Retry-After header if (this.XboxLiveAPI != XboxLiveAPIName.Unspecified && httpCallResponse.HttpStatus >= 400 //&& //httpCallResponse.RetryAfter.TotalSeconds > 0 ) { DateTime currentTime = DateTime.UtcNow; HttpRetryAfterApiState state = new HttpRetryAfterApiState(); state.RetryAfterTime = currentTime + httpCallResponse.RetryAfter; state.HttpCallResponse = httpCallResponse; state.Exception = exception; HttpRetryAfterManager.Instance.SetState(this.XboxLiveAPI, state); } }