示例#1
0
        public void ShouldTryToLimitAfterMaxIsNotReachedAndResetting()
        {
            var cnt     = 0;
            var subject = new RetryTracker(20, null, new LinearRetryInterval(TimeSpan.Zero));

            subject.Try();

            subject.Reset();

            cnt = 0;
            while (subject.Try())
            {
                cnt++;
            }

            cnt.Should().Be(21);
        }
示例#2
0
        void DeleteFile(string path, FailureOptions options, RetryTracker retry, CancellationToken cancel)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                return;
            }

            retry.Reset();
            while (retry.Try())
            {
                cancel.ThrowIfCancellationRequested();
                try
                {
                    if (File.Exists(path))
                    {
                        if (retry.IsNotFirstAttempt)
                        {
                            File.SetAttributes(path, FileAttributes.Normal);
                        }
                        File.Delete(path);
                    }

                    break;
                }
                catch (Exception ex)
                {
                    if (retry.CanRetry())
                    {
                        if (retry.ShouldLogWarning())
                        {
                            Log.VerboseFormat("Retry #{0} on delete file '{1}'. Exception: {2}", retry.CurrentTry, path, ex.Message);
                        }
                        Thread.Sleep(retry.Sleep());
                    }
                    else
                    {
                        if (options == FailureOptions.ThrowOnFailure)
                        {
                            throw;
                        }
                    }
                }
            }
        }