public override TimeSpan? CalculateRetryDelay()

in src/Microsoft.Azure.NotificationHubs/BasicRetryPolicy.cs [63:108]


        public override TimeSpan? CalculateRetryDelay(
            Exception lastException,
            int attemptCount)
        {
            if (Options.MaxRetries <= 0
                || Options.Delay == TimeSpan.Zero
                || Options.MaxDelay == TimeSpan.Zero
                || attemptCount > Options.MaxRetries
                || !ShouldRetryException(lastException))
            {
                return null;
            }

            var baseJitterSeconds = Options.Delay.TotalSeconds * JitterFactor;

            TimeSpan retryDelay;

            if (lastException is MessagingException messagingException && messagingException.RetryAfter.HasValue)
            {
                retryDelay = messagingException.RetryAfter.Value;
            }
            else
            {
                switch (Options.Mode)
                {
                    case NotificationHubRetryMode.Fixed:
                        retryDelay = CalculateFixedDelay(Options.Delay.TotalSeconds, baseJitterSeconds, RandomNumberGenerator.Value);
                        break;
                    case NotificationHubRetryMode.Exponential:
                        retryDelay = CalculateExponentialDelay(attemptCount, Options.Delay.TotalSeconds, baseJitterSeconds, RandomNumberGenerator.Value);
                        break;
                    default:
                        throw new NotSupportedException($"Unsupported retry mode {Options.Mode}");
                };
            }

            // Adjust the delay, if needed, to keep within the maximum
            // duration.

            if (Options.MaxDelay < retryDelay)
            {
                return Options.MaxDelay;
            }

            return retryDelay;
        }