| | | 1 | | using System.IO; |
| | | 2 | | using System.Threading; |
| | | 3 | | |
| | | 4 | | namespace WireMock.Util |
| | | 5 | | { |
| | | 6 | | internal static class FileHelper |
| | | 7 | | { |
| | | 8 | | private const int NumberOfRetries = 3; |
| | | 9 | | private const int DelayOnRetry = 500; |
| | | 10 | | |
| | | 11 | | public static string ReadAllText(string path) |
| | 4 | 12 | | { |
| | 8 | 13 | | for (int i = 1; i <= NumberOfRetries; ++i) |
| | 4 | 14 | | { |
| | | 15 | | try |
| | 4 | 16 | | { |
| | 4 | 17 | | return File.ReadAllText(path); |
| | | 18 | | } |
| | 0 | 19 | | catch |
| | 0 | 20 | | { |
| | | 21 | | // You may check error code to filter some exceptions, not every error can be recovered. |
| | 0 | 22 | | Thread.Sleep(DelayOnRetry); |
| | 0 | 23 | | } |
| | 0 | 24 | | } |
| | | 25 | | |
| | 0 | 26 | | throw new IOException(); |
| | 4 | 27 | | } |
| | | 28 | | } |
| | | 29 | | } |