protected override void DoExecute()
        {
            if (_directoryAdapter.Exists(_dstDirPath.Value))
            {
                RetryUtils.RetryOnException(
                    new[] { typeof(UnauthorizedAccessException) },
                    _DeleteDstDirRetriesCount,
                    _DeleteDstDirRetryDelay,
                    () =>
                {
                    _directoryAdapter.GetDirectories(_dstDirPath.Value)
                    .Where(x => !_excludedDirs.Any(s => x.EndsWith(s, StringComparison.CurrentCultureIgnoreCase)))
                    .ToList()
                    .ForEach(dirPath => _directoryAdapter.Delete(dirPath, true));

                    _directoryAdapter.GetFiles(_dstDirPath.Value)
                    .ToList()
                    .ForEach(_fileAdapter.Delete);
                });
            }
            else
            {
                _directoryAdapter.CreateDirectory(_dstDirPath.Value);
            }
        }
示例#2
0
        public void RetryOnException_doesnt_retry_on_a_unexpected_exception()
        {
            // arrange
            int triesCount = 0;

            Action action =
                () =>
            {
                triesCount++;

                throw new ArgumentOutOfRangeException();
            };

            // act & assert
            Assert.Throws <ArgumentOutOfRangeException>(
                () =>
            {
                RetryUtils.RetryOnException(
                    new[] { typeof(InvalidOperationException) },
                    1,
                    0,
                    action);
            });

            Assert.AreEqual(1, triesCount);
        }
示例#3
0
        public void RetryOnException_retries_the_given_number_of_times()
        {
            // arrange
            bool finished   = false;
            int  triesCount = 0;

            Action action =
                () =>
            {
                triesCount++;

                if (triesCount <= 3)
                {
                    throw new Exception();
                }
                else
                {
                    finished = true;
                }
            };

            // act
            RetryUtils.RetryOnException(
                new[] { typeof(Exception) },
                3,
                0,
                action);

            // assert
            Assert.AreEqual(4, triesCount);
            Assert.IsTrue(finished);
        }
示例#4
0
        public void RetryOnException_retries_on_a_derived_exception()
        {
            // arrange
            bool finished   = false;
            int  triesCount = 0;

            Action action =
                () =>
            {
                triesCount++;

                if (triesCount == 1)
                {
                    throw new InvalidFilterCriteriaException();
                }
                else
                {
                    finished = true;
                }
            };

            // act
            RetryUtils.RetryOnException(
                new[] { typeof(ApplicationException) },
                1,
                0,
                action);

            // assert
            Assert.IsTrue(finished);
            Assert.AreEqual(2, triesCount);
        }
示例#5
0
        public void RetryOnException_throws_after_retries_count_is_exceeded()
        {
            // arrange
            int triesCount = 0;

            Action action =
                () =>
            {
                triesCount++;

                throw new ArgumentOutOfRangeException();
            };

            // act & assert
            Assert.Throws <ArgumentOutOfRangeException>(
                () =>
            {
                RetryUtils.RetryOnException(
                    new[] { typeof(ArgumentOutOfRangeException) },
                    1,
                    0,
                    action);
            });

            Assert.AreEqual(2, triesCount);
        }
示例#6
0
 private void DeleteTemporaryDirectoryIfNeeded()
 {
     if (!string.IsNullOrEmpty(_tempDirPath) && Directory.Exists(_tempDirPath))
     {
         RetryUtils.RetryOnException(
             new[] { typeof(IOException) },
             retriesCount: 4,
             retryDelay: 500,
             action: () => Directory.Delete(_tempDirPath, true));
     }
 }