Example #1
0
        public RetryInfo Evaluate(RetryContext retryContext, OperationContext operationContext)
        {
            CommonUtility.AssertNotNull("retryContext", retryContext);
            if (retryContext.LastRequestResult.TargetLocation == StorageLocation.Primary)
            {
                lastPrimaryAttempt = retryContext.LastRequestResult.EndTime;
            }
            else
            {
                lastSecondaryAttempt = retryContext.LastRequestResult.EndTime;
            }
            bool flag = retryContext.LastRequestResult.TargetLocation == StorageLocation.Secondary && retryContext.LastRequestResult.HttpStatusCode == 404;

            if (ShouldRetry(retryContext.CurrentRetryCount, flag ? 500 : retryContext.LastRequestResult.HttpStatusCode, retryContext.LastRequestResult.Exception, out TimeSpan retryInterval, operationContext))
            {
                RetryInfo retryInfo = new RetryInfo(retryContext);
                if (flag && retryContext.LocationMode != LocationMode.SecondaryOnly)
                {
                    retryInfo.UpdatedLocationMode = LocationMode.PrimaryOnly;
                    retryInfo.TargetLocation      = StorageLocation.Primary;
                }
                DateTimeOffset?dateTimeOffset = (retryInfo.TargetLocation == StorageLocation.Primary) ? lastPrimaryAttempt : lastSecondaryAttempt;
                if (dateTimeOffset.HasValue)
                {
                    TimeSpan t = CommonUtility.MaxTimeSpan(DateTimeOffset.Now - dateTimeOffset.Value, TimeSpan.Zero);
                    retryInfo.RetryInterval = retryInterval - t;
                }
                else
                {
                    retryInfo.RetryInterval = TimeSpan.Zero;
                }
                return(retryInfo);
            }
            return(null);
        }
Example #2
0
 public RetryInfo(RetryContext retryContext)
 {
     CommonUtility.AssertNotNull("retryContext", retryContext);
     TargetLocation      = retryContext.NextLocation;
     UpdatedLocationMode = retryContext.LocationMode;
 }