public static bool TryDetermineRetryDelay(HttpResponseMessage httpResponseMessage, out RetryConditionValue result) { result = null; if (httpResponseMessage.Headers.RetryAfter == null) { return(false); } var retryAfterConditionHeaderValue = httpResponseMessage.Headers.RetryAfter; if (retryAfterConditionHeaderValue.Date.HasValue) { result = new RetryConditionValue(retryAfterConditionHeaderValue.Date.Value); return(true); } if (retryAfterConditionHeaderValue.Delta.HasValue) { result = new RetryConditionValue(retryAfterConditionHeaderValue.Delta.Value); return(true); } return(false); }
public void TestTopicMessageWithRetryTimeSpan() { using (var client = new FcmClient(new IntegrationTestOptions("TopicMessage_WithRetryTimeSpan"))) { CancellationTokenSource cts = new CancellationTokenSource(); var message = new TopicUnicastMessage <int>(new FcmMessageOptionsBuilder().Build(), new Topic("a"), 1); bool isRetryExceptionCaught = false; try { var result = client.SendAsync(message, cts.Token).GetAwaiter().GetResult(); } catch (FcmRetryAfterException e) { RetryConditionValue retryConditionValue = e.RetryConditionValue; Assert.IsNotNull(retryConditionValue); Assert.IsNull(retryConditionValue.Date); // 1 Minute Delta Assert.AreEqual(retryConditionValue.Delta, TimeSpan.FromMinutes(1)); isRetryExceptionCaught = true; } Assert.AreEqual(true, isRetryExceptionCaught); } }
public void TestTopicMessageWithRetryDateTimeOffset() { using (var client = new FcmClient(new IntegrationTestOptions("TopicMessage_WithRetry"))) { CancellationTokenSource cts = new CancellationTokenSource(); var message = new TopicUnicastMessage <int>(new FcmMessageOptionsBuilder().Build(), new Topic("a"), 1); bool isRetryExceptionCaught = false; try { var result = client.SendAsync(message, cts.Token).GetAwaiter().GetResult(); } catch (FcmRetryAfterException e) { RetryConditionValue retryConditionValue = e.RetryConditionValue; Assert.IsNotNull(retryConditionValue); Assert.IsNull(retryConditionValue.Delta); // Fri, 31 Dec 1999 23:59:59 GMT Assert.AreEqual(new DateTimeOffset(1999, 12, 31, 23, 59, 59, TimeSpan.FromHours(0)), retryConditionValue.Date); isRetryExceptionCaught = true; } Assert.AreEqual(true, isRetryExceptionCaught); } }
public FcmRetryAfterException(string message, Exception innerException, RetryConditionValue retryConditionValue) : base(message, innerException) { RetryConditionValue = retryConditionValue; }
public FcmRetryAfterException(RetryConditionValue retryConditionValue) { RetryConditionValue = retryConditionValue; }