| | | 1 | | using System.IO; |
| | | 2 | | using System.Threading; |
| | | 3 | | using JetBrains.Annotations; |
| | | 4 | | using WireMock.Handlers; |
| | | 5 | | using WireMock.Validation; |
| | | 6 | | |
| | | 7 | | namespace WireMock.Util |
| | | 8 | | { |
| | | 9 | | internal static class FileHelper |
| | | 10 | | { |
| | | 11 | | private const int NumberOfRetries = 3; |
| | | 12 | | private const int DelayOnRetry = 500; |
| | | 13 | | |
| | | 14 | | public static string ReadAllTextWithRetryAndDelay([NotNull] IFileSystemHandler filehandler, [NotNull] string pat |
| | 2 | 15 | | { |
| | 2 | 16 | | Check.NotNull(filehandler, nameof(filehandler)); |
| | 2 | 17 | | Check.NotNullOrEmpty(path, nameof(path)); |
| | | 18 | | |
| | 10 | 19 | | for (int i = 1; i <= NumberOfRetries; ++i) |
| | 4 | 20 | | { |
| | | 21 | | try |
| | 4 | 22 | | { |
| | 4 | 23 | | return filehandler.ReadMappingFile(path); |
| | | 24 | | } |
| | 3 | 25 | | catch |
| | 3 | 26 | | { |
| | 3 | 27 | | Thread.Sleep(DelayOnRetry); |
| | 3 | 28 | | } |
| | 3 | 29 | | } |
| | | 30 | | |
| | 1 | 31 | | throw new IOException(); |
| | 1 | 32 | | } |
| | | 33 | | } |
| | | 34 | | } |