Files
WireMock.Net-wiremock/src/WireMock.Net/Util/FileHelper.cs
Stef Heyenrath e8e28c21a1 Use NuGet "Stef.Validation" (#707)
* Use NuGet "Stef.Validation"

* nuget

* .
2021-12-30 10:44:50 +01:00

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;
}
}
}