Add IFileSystemHandler to support Azure for StaticMapping location (#180)

* wip

* CustomStaticMappingFileHandler

* Add unit-tests

* Tests

* IFileSystemHandler

* version
This commit is contained in:
Stef Heyenrath
2018-08-14 18:54:53 +02:00
committed by GitHub
parent c92e733ef9
commit 4b91c05fe7
21 changed files with 505 additions and 59 deletions

View File

@@ -1,5 +1,8 @@
using System.IO;
using System.Threading;
using JetBrains.Annotations;
using WireMock.Handlers;
using WireMock.Validation;
namespace WireMock.Util
{
@@ -8,17 +11,19 @@ namespace WireMock.Util
private const int NumberOfRetries = 3;
private const int DelayOnRetry = 500;
public static string ReadAllText(string path)
public static string ReadAllTextWithRetryAndDelay([NotNull] IFileSystemHandler filehandler, [NotNull] string path)
{
Check.NotNull(filehandler, nameof(filehandler));
Check.NotNullOrEmpty(path, nameof(path));
for (int i = 1; i <= NumberOfRetries; ++i)
{
try
{
return File.ReadAllText(path);
return filehandler.ReadMappingFile(path);
}
catch
{
// You may check error code to filter some exceptions, not every error can be recovered.
Thread.Sleep(DelayOnRetry);
}
}