mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-18 17:37:01 +01:00
36 lines
936 B
C#
36 lines
936 B
C#
using JetBrains.Annotations;
|
|
using System.Threading;
|
|
using WireMock.Handlers;
|
|
using Stef.Validation;
|
|
|
|
namespace WireMock.Util
|
|
{
|
|
internal static class FileHelper
|
|
{
|
|
private const int NumberOfRetries = 3;
|
|
private const int DelayOnRetry = 500;
|
|
|
|
public static bool TryReadMappingFileWithRetryAndDelay([NotNull] IFileSystemHandler handler, [NotNull] string path, out string value)
|
|
{
|
|
Guard.NotNull(handler, nameof(handler));
|
|
Guard.NotNullOrEmpty(path, nameof(path));
|
|
|
|
value = null;
|
|
|
|
for (int i = 1; i <= NumberOfRetries; ++i)
|
|
{
|
|
try
|
|
{
|
|
value = handler.ReadMappingFile(path);
|
|
return true;
|
|
}
|
|
catch
|
|
{
|
|
Thread.Sleep(DelayOnRetry);
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
} |