|  |  | 1 |  | // Copyright (c) Microsoft. All rights reserved. | 
|  |  | 2 |  | // Licensed under the MIT license. See LICENSE file in the project root for full license information. | 
|  |  | 3 |  |  | 
|  |  | 4 |  | namespace Microsoft.Azure.ServiceBus | 
|  |  | 5 |  | { | 
|  |  | 6 |  |     using System; | 
|  |  | 7 |  |  | 
|  |  | 8 |  |     static class MessagingUtilities | 
|  |  | 9 |  |     { | 
|  |  | 10 |  |         public static TimeSpan CalculateRenewAfterDuration(DateTime lockedUntilUtc) | 
|  |  | 11 |  |         { | 
|  | 0 | 12 |  |             var remainingTime = lockedUntilUtc - DateTime.UtcNow; | 
|  |  | 13 |  |  | 
|  | 0 | 14 |  |             if(remainingTime < TimeSpan.FromMilliseconds(400)) | 
|  |  | 15 |  |             { | 
|  | 0 | 16 |  |                 return TimeSpan.Zero; | 
|  |  | 17 |  |             } | 
|  |  | 18 |  |  | 
|  | 0 | 19 |  |             var buffer = TimeSpan.FromTicks(Math.Min(remainingTime.Ticks / 2, Constants.MaximumRenewBufferDuration.Ticks | 
|  | 0 | 20 |  |             var renewAfter = remainingTime - buffer; | 
|  |  | 21 |  |  | 
|  | 0 | 22 |  |             return renewAfter; | 
|  |  | 23 |  |         } | 
|  |  | 24 |  |  | 
|  |  | 25 |  |         public static bool ShouldRetry(Exception exception) | 
|  |  | 26 |  |         { | 
|  | 0 | 27 |  |             var serviceBusException = exception as ServiceBusException; | 
|  | 0 | 28 |  |             return serviceBusException?.IsTransient == true; | 
|  |  | 29 |  |         } | 
|  |  | 30 |  |     } | 
|  |  | 31 |  | } |