protected override IEnumerator <IteratorAsyncResult <MessageBrowser.RetryBrowserAsyncResult> .AsyncStep> GetAsyncSteps() { TimeSpan timeSpan; bool flag; bool flag1; int num = 0; timeSpan = (this.browser.RetryPolicy.IsServerBusy ? Microsoft.ServiceBus.RetryPolicy.ServerBusyBaseSleepTime : TimeSpan.Zero); TimeSpan timeSpan1 = timeSpan; if (!this.browser.RetryPolicy.IsServerBusy || !(Microsoft.ServiceBus.RetryPolicy.ServerBusyBaseSleepTime >= base.OriginalTimeout)) { do { flag1 = false; if (timeSpan1 != TimeSpan.Zero) { yield return(base.CallAsyncSleep(timeSpan1)); } MessageBrowser.RetryBrowserAsyncResult retryBrowserAsyncResult = this; IteratorAsyncResult <MessageBrowser.RetryBrowserAsyncResult> .BeginCall beginCall = (MessageBrowser.RetryBrowserAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.browser.OnBeginPeek(thisPtr.trackingContext, thisPtr.fromSequenceNumber, thisPtr.messageCount, t, c, s); yield return(retryBrowserAsyncResult.CallAsync(beginCall, (MessageBrowser.RetryBrowserAsyncResult thisPtr, IAsyncResult r) => thisPtr.Messages = thisPtr.browser.OnEndPeek(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue)); if (base.LastAsyncStepException == null) { this.browser.RetryPolicy.ResetServerBusy(); } else { MessagingPerformanceCounters.IncrementExceptionPerSec(this.browser.MessagingFactory.Address, 1, base.LastAsyncStepException); flag = (base.TransactionExists ? false : this.browser.RetryPolicy.ShouldRetry(base.RemainingTime(), num, base.LastAsyncStepException, out timeSpan1)); flag1 = flag; if (!flag1) { continue; } MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteRetryPolicyIteration(this.trackingContext.Activity, this.trackingContext.TrackingId, this.browser.RetryPolicy.GetType().Name, "Peek", num, timeSpan1.ToString(), this.LastAsyncStepException.GetType().FullName, this.LastAsyncStepException.Message)); num++; } }while (flag1); base.Complete(base.LastAsyncStepException); } else { string str = this.browser.RetryPolicy.ServerBusyExceptionMessage; yield return(base.CallAsyncSleep(base.RemainingTime())); base.Complete(new ServerBusyException(str, this.trackingContext)); } }
protected override IEnumerator <IteratorAsyncResult <T> .AsyncStep> GetAsyncSteps() { bool flag; TimeSpan timeSpan; while (true) { bool flag1 = false; if (!this.bypassCache) { lock (this.TokenProvider.mutex) { TokenProvider.TokenInfo tokenInfoFromCache = this.TokenProvider.GetTokenInfoFromCache(this.cacheKey); flag = this.OnProcessCachedEntryFromTokenProvider(tokenInfoFromCache); } if (flag) { break; } } Stopwatch stopwatch = Stopwatch.StartNew(); try { TokenProvider.GetTokenAsyncResultBase <T> getTokenAsyncResultBase = this; IteratorAsyncResult <T> .BeginCall getTokenBeginCall = this.GetTokenBeginCall; yield return(getTokenAsyncResultBase.CallAsync(getTokenBeginCall, (T thisPtr, IAsyncResult r) => thisPtr.OnCompletion(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue)); if (base.LastAsyncStepException != null) { goto Label0; } stopwatch.Stop(); MessagingPerformanceCounters.IncrementTokenAcquisitionLatency(this.appliesToUri, stopwatch.ElapsedTicks); MessagingPerformanceCounters.IncrementTokensAcquiredPerSec(this.appliesToUri, 1); break; } finally { stopwatch.Stop(); } Label0: MessagingPerformanceCounters.IncrementTokenAcquisitionFailuresPerSec(this.appliesToUri, 1); SecurityTokenException lastAsyncStepException = base.LastAsyncStepException as SecurityTokenException; TokenProviderException tokenProviderException = base.LastAsyncStepException as TokenProviderException; TimeoutException timeoutException = base.LastAsyncStepException as TimeoutException; if (timeoutException != null && timeoutException.InnerException != null && timeoutException.InnerException is WebException) { flag1 = true; } else if (tokenProviderException != null && tokenProviderException.InnerException != null && tokenProviderException.InnerException is WebException) { flag1 = true; } else if (lastAsyncStepException != null) { TokenProviderHelper.InternalSecurityTokenException internalSecurityTokenException = lastAsyncStepException as TokenProviderHelper.InternalSecurityTokenException; flag1 = true; if (internalSecurityTokenException != null) { base.LastAsyncStepException = new SecurityTokenException(internalSecurityTokenException.Message, internalSecurityTokenException.InnerException); switch (internalSecurityTokenException.StatusCode) { case HttpStatusCode.BadRequest: case HttpStatusCode.Unauthorized: { flag1 = false; break; } } } } if (flag1) { TimeSpan timeSpan1 = base.RemainingTime(); if (timeSpan1 <= TimeSpan.Zero) { flag1 = false; } else { yield return(base.CallAsyncSleep(TimeoutHelper.Min(this.retrySleepTime, timeSpan1))); TimeSpan timeSpan2 = this.retrySleepTime.Add(this.retrySleepTime); TokenProvider.GetTokenAsyncResultBase <T> getTokenAsyncResultBase1 = this; timeSpan = (timeSpan2 < TokenProvider.MaxRetrySleepTime ? timeSpan2 : TokenProvider.MaxRetrySleepTime); getTokenAsyncResultBase1.retrySleepTime = timeSpan; } } if (!flag1) { if (base.LastAsyncStepException == null) { break; } base.Complete(base.LastAsyncStepException); break; } } }
protected override IEnumerator <IteratorAsyncResult <MessageSession.RetrySessionAsyncResult> .AsyncStep> GetAsyncSteps() { TimeSpan timeSpan; bool flag; bool flag1; int num = 0; timeSpan = (this.session.RetryPolicy.IsServerBusy ? Microsoft.ServiceBus.RetryPolicy.ServerBusyBaseSleepTime : TimeSpan.Zero); TimeSpan zero = timeSpan; if (!this.session.RetryPolicy.IsServerBusy || !(Microsoft.ServiceBus.RetryPolicy.ServerBusyBaseSleepTime >= base.OriginalTimeout)) { do { flag1 = false; if (zero != TimeSpan.Zero) { yield return(base.CallAsyncSleep(zero)); } switch (this.operation) { case MessageSession.SessionOperation.GetState: { MessageSession.RetrySessionAsyncResult retrySessionAsyncResult = this; Transaction ambientTransaction = base.AmbientTransaction; IteratorAsyncResult <MessageSession.RetrySessionAsyncResult> .BeginCall beginCall = (MessageSession.RetrySessionAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.session.OnBeginGetState(thisPtr.trackingContext, t, c, s); yield return(retrySessionAsyncResult.CallTransactionalAsync(ambientTransaction, beginCall, (MessageSession.RetrySessionAsyncResult thisPtr, IAsyncResult r) => thisPtr.SessionState = thisPtr.session.OnEndGetState(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue)); break; } case MessageSession.SessionOperation.SetState: { if (this.stream != null && this.stream.CanSeek && this.stream.Position != (long)0) { this.stream.Position = (long)0; } MessageSession.RetrySessionAsyncResult retrySessionAsyncResult1 = this; Transaction transaction = base.AmbientTransaction; IteratorAsyncResult <MessageSession.RetrySessionAsyncResult> .BeginCall beginCall1 = (MessageSession.RetrySessionAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.session.OnBeginSetState(thisPtr.trackingContext, thisPtr.stream, t, c, s); yield return(retrySessionAsyncResult1.CallTransactionalAsync(transaction, beginCall1, (MessageSession.RetrySessionAsyncResult thisPtr, IAsyncResult r) => thisPtr.session.OnEndSetState(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue)); break; } case MessageSession.SessionOperation.RenewSessionLock: { MessageSession.RetrySessionAsyncResult retrySessionAsyncResult2 = this; IteratorAsyncResult <MessageSession.RetrySessionAsyncResult> .BeginCall beginCall2 = (MessageSession.RetrySessionAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.session.OnBeginRenewLock(thisPtr.trackingContext, t, c, s); yield return(retrySessionAsyncResult2.CallAsync(beginCall2, (MessageSession.RetrySessionAsyncResult thisPtr, IAsyncResult r) => thisPtr.LockedUntilUtcTime = thisPtr.session.OnEndRenewLock(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue)); break; } } if (base.LastAsyncStepException == null) { this.session.RetryPolicy.ResetServerBusy(); } else { base.LastAsyncStepException = this.session.ProcessException(base.LastAsyncStepException); MessagingPerformanceCounters.IncrementExceptionPerSec(this.session.MessagingFactory.Address, 1, base.LastAsyncStepException); flag = (base.TransactionExists ? false : this.session.RetryPolicy.ShouldRetry(base.RemainingTime(), num, base.LastAsyncStepException, out zero)); flag1 = flag; if (this.operation == MessageSession.SessionOperation.SetState && this.stream != null && !this.stream.CanSeek) { flag1 = false; zero = TimeSpan.Zero; MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteRetryPolicyStreamNotSeekable(this.trackingContext.Activity, this.trackingContext.TrackingId, this.session.RetryPolicy.GetType().Name, this.operation.ToString())); } if (!flag1) { continue; } MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteRetryPolicyIteration(this.trackingContext.Activity, this.trackingContext.TrackingId, this.session.RetryPolicy.GetType().Name, this.operation.ToString(), num, zero.ToString(), this.LastAsyncStepException.GetType().FullName, this.LastAsyncStepException.Message)); num++; } }while (flag1); base.Complete(base.LastAsyncStepException); } else { string str = this.session.RetryPolicy.ServerBusyExceptionMessage; yield return(base.CallAsyncSleep(base.RemainingTime())); base.Complete(new ServerBusyException(str, this.trackingContext)); } }