コード例 #1
0
        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);
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
 public FcmRetryAfterException(string message, Exception innerException, RetryConditionValue retryConditionValue) : base(message, innerException)
 {
     RetryConditionValue = retryConditionValue;
 }
コード例 #5
0
 public FcmRetryAfterException(RetryConditionValue retryConditionValue)
 {
     RetryConditionValue = retryConditionValue;
 }