private void WaitBeforeRetry(int retryAttempt) { if (retryAttempt == 0) { return; } TimeSpan timeSpan; if (retryAttempt < 0 || retryAttempt >= EwsAuditClient.RetrySchedule.Length) { timeSpan = EwsAuditClient.RetrySchedule[EwsAuditClient.RetrySchedule.Length - 1]; } else { timeSpan = EwsAuditClient.RetrySchedule[retryAttempt]; } if (timeSpan > TimeSpan.Zero) { if (this.IsTraceEnabled(TraceType.DebugTrace)) { this.Tracer.TraceDebug <TimeSpan>(0L, "Sleeping before next retry for {0}.", timeSpan); } DiagnosticContext.TraceDword((LID)57676U, (uint)timeSpan.TotalMilliseconds); Thread.Sleep(timeSpan); } }
private void CallEwsWithRetries(LID lid, Func <BaseResponseMessageType> delegateEwsCall, Func <ResponseMessageType, int, bool> responseMessageProcessor, Func <ResponseMessageType, int, bool> responseErrorProcessor) { ExDateTime t = ExDateTime.UtcNow.Add((this.CallTimeout < EwsAuditClient.TotalRetryTimeWindow) ? EwsAuditClient.TotalRetryTimeWindow : this.CallTimeout); bool flag = false; Exception ex = null; int num = -1; do { if (flag) { this.WaitBeforeRetry(num); } ex = null; flag = false; num++; try { DiagnosticContext.TraceDword((LID)57532U, (uint)num); BaseResponseMessageType baseResponseMessageType; using (DiagnosticContext.TraceLatency(lid)) { baseResponseMessageType = delegateEwsCall(); } int i = 0; while (i < baseResponseMessageType.ResponseMessages.Items.Length) { ResponseMessageType responseMessageType = baseResponseMessageType.ResponseMessages.Items[i]; if (responseMessageProcessor != null && responseMessageProcessor(responseMessageType, i)) { DiagnosticContext.TraceLocation((LID)32956U); if (this.IsTraceEnabled(TraceType.DebugTrace)) { this.Tracer.TraceDebug(0L, "Successfully executed EWS call"); break; } break; } else { if (responseMessageType.ResponseClass == ResponseClassType.Error) { DiagnosticContext.TraceDwordAndString((LID)33100U, (uint)responseMessageType.ResponseCode, responseMessageType.ResponseCode.ToString()); if (responseMessageType.ResponseCode == ResponseCodeType.ErrorCrossSiteRequest) { if (this.IsTraceEnabled(TraceType.DebugTrace)) { this.Tracer.TraceDebug(0L, "Crosssite request error , recreate exchange binding and reset the url caches"); } flag = true; this.RefreshUrl(true); break; } if (!EwsAuditClient.TransientServiceErrors.Contains(responseMessageType.ResponseCode)) { if (responseErrorProcessor == null || !responseErrorProcessor(responseMessageType, i)) { if (this.IsTraceEnabled(TraceType.ErrorTrace)) { this.Tracer.TraceError <string, string, string>(0L, "Permanent error encountered: {0}, {1}, {2}", responseMessageType.ResponseClass.ToString(), responseMessageType.ResponseCode.ToString(), responseMessageType.MessageText.ToString()); } DiagnosticContext.TraceLocation((LID)65212U); throw new AuditLogServiceException(responseMessageType.ResponseClass.ToString(), responseMessageType.ResponseCode.ToString(), responseMessageType.MessageText.ToString()); } DiagnosticContext.TraceLocation((LID)48828U); if (this.IsTraceEnabled(TraceType.DebugTrace)) { this.Tracer.TraceDebug(0L, "Error encountered, but was handled by error callback: {0}, {1}, {2}, response index={3}", new object[] { responseMessageType.ResponseClass.ToString(), responseMessageType.ResponseCode.ToString(), responseMessageType.MessageText.ToString(), i }); } } else { DiagnosticContext.TraceLocation((LID)40636U); flag = true; ex = new AuditLogServiceException(responseMessageType.ResponseClass.ToString(), responseMessageType.ResponseCode.ToString(), responseMessageType.MessageText.ToString()); if (this.IsTraceEnabled(TraceType.DebugTrace)) { this.Tracer.TraceDebug(0L, "Transient error encountered, will attempt to retry, Exception: " + ex); } } } i++; } } } catch (CommunicationException ex2) { DiagnosticContext.TraceLocation((LID)57020U); ex = ex2; flag = true; } catch (TimeoutException ex3) { DiagnosticContext.TraceLocation((LID)44732U); ex = ex3; flag = false; } catch (SoapException ex4) { DiagnosticContext.TraceLocation((LID)61116U); ex = ex4; flag = false; } catch (WebException ex5) { DiagnosticContext.TraceLocation((LID)36540U); ex = ex5; flag = false; } catch (IOException ex6) { DiagnosticContext.TraceLocation((LID)52924U); ex = ex6; flag = false; } catch (InvalidOperationException ex7) { DiagnosticContext.TraceLocation((LID)46780U); ex = ex7; flag = false; } catch (LocalizedException ex8) { DiagnosticContext.TraceLocation((LID)63164U); ex = ex8; flag = false; } }while (flag && t > ExDateTime.UtcNow); if (ex != null) { if (this.IsTraceEnabled(TraceType.ErrorTrace)) { this.Tracer.TraceError <int, Exception>(0L, "Failed to make EWS call to audit log, Total attempts made {0}, Exception: {1} ", num, ex); } DiagnosticContext.TraceLocation((LID)38588U); throw this.GetSpecificException(ex); } }