Amazon.Runtime.RetryPolicy.IsClockskew C# (CSharp) Method

IsClockskew() private method

private IsClockskew ( IExecutionContext executionContext, Exception exception ) : bool
executionContext IExecutionContext
exception System.Exception
return bool
        private bool IsClockskew(IExecutionContext executionContext, Exception exception)
        {
            var ase = exception as AmazonServiceException;

            var isHead =
                executionContext.RequestContext.Request != null &&
                string.Equals(executionContext.RequestContext.Request.HttpMethod, "HEAD", StringComparison.Ordinal);
            var isClockskewErrorCode =
                ase != null &&
                (ase.ErrorCode == null || clockSkewErrorCodes.Contains(ase.ErrorCode));

            if (isHead || isClockskewErrorCode)
            {
                var realNow = DateTime.UtcNow;
                var correctedNow = AWSSDKUtils.CorrectedUtcNow;

                DateTime serverTime;

                // Try getting server time from the headers
                bool serverTimeDetermined = TryParseDateHeader(ase, out serverTime);

                // If that fails, try to parse it from the exception message
                if (!serverTimeDetermined)
                    serverTimeDetermined = TryParseExceptionMessage(ase, out serverTime);

                if (serverTimeDetermined)
                {
                    // using accurate server time, calculate correction if local time is off
                    serverTime = serverTime.ToUniversalTime();
                    var diff = correctedNow - serverTime;
                    var absDiff = diff.Ticks < 0 ? -diff : diff;
                    if (absDiff > clockSkewMaxThreshold)
                    {
                        var newCorrection = serverTime - realNow;
                        Logger.InfoFormat(clockSkewMessageFormat,
                            realNow, correctedNow, AWSConfigs.ClockOffset, serverTime);

                        // Always set the correction, for informational purposes
                        AWSConfigs.ClockOffset = newCorrection;
                        var shouldRetry = AWSConfigs.CorrectForClockSkew;

                        // Only retry if clock skew correction is not disabled
                        if (shouldRetry)
                        {
                            // Set clock skew correction
                            Logger.InfoFormat(clockSkewUpdatedFormat, newCorrection);
                            executionContext.RequestContext.IsSigned = false;
                            return true;
                        }
                    }
                }
            }

            return false;
        }
        private static bool TryParseDateHeader(AmazonServiceException ase, out DateTime serverTime)