Skip to content

Commit

Permalink
Added logic in the Select so it takes all columnmappings for the same…
Browse files Browse the repository at this point in the history
… SourceTable, for storing this into the SaveRequestResponseFile so it can be reused on the same source-table-mappings if the setting for readFromLastRequestResponse is used.
  • Loading branch information
MatthiasSort committed Mar 1, 2024
1 parent a57e109 commit a7a62bb
Show file tree
Hide file tree
Showing 9 changed files with 2,061 additions and 2,060 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.0.19</Version>
<Version>10.0.20</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>OData Provider</Title>
<Description>The Odata Provider lets you fetch and map data from or to any OData endpoint.</Description>
Expand Down
227 changes: 113 additions & 114 deletions src/Interfaces/IHttpRestClient.cs

Large diffs are not rendered by default.

793 changes: 396 additions & 397 deletions src/Model/HttpRestClient.cs

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions src/Model/ResponseFromEndpoint.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Dynamicweb.DataIntegration.Providers.ODataProvider.Model
namespace Dynamicweb.DataIntegration.Providers.ODataProvider.Model;

internal class ResponseFromEndpoint<T>
{
internal class ResponseFromEndpoint<T>
{
[JsonPropertyName("@odata.context")]
public string Odata { get; set; }
[JsonPropertyName("value")]
public List<T> Value { get; set; }
[JsonPropertyName("@odata.nextLink")]
public string OdataNextLink { get; set; }
}
[JsonPropertyName("@odata.context")]
public string Odata { get; set; }
[JsonPropertyName("value")]
public List<T> Value { get; set; }
[JsonPropertyName("@odata.nextLink")]
public string OdataNextLink { get; set; }
}
43 changes: 21 additions & 22 deletions src/Model/RestResponse.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
using System.Collections.Generic;
using System.Net;

namespace Dynamicweb.DataIntegration.Providers.ODataProvider.Model
namespace Dynamicweb.DataIntegration.Providers.ODataProvider.Model;

/// <summary>
/// Wrap an HTTP response, with headers, content and status code.
/// </summary>
internal class RestResponse<T>
{
/// <summary>
/// Wrap an HTTP response, with headers, content and status code.
/// Content of the response.
/// </summary>
internal class RestResponse<T>
{
/// <summary>
/// Content of the response.
/// </summary>
internal T Content { get; set; }
internal T Content { get; set; }

/// <summary>
/// HTTP headers of the response.
/// </summary>
internal Dictionary<string, string> Headers { get; set; }
/// <summary>
/// HTTP headers of the response.
/// </summary>
internal Dictionary<string, string> Headers { get; set; }

/// <summary>
/// Status response code for the request.
/// </summary>
internal HttpStatusCode Status { get; set; }
/// <summary>
/// Status response code for the request.
/// </summary>
internal HttpStatusCode Status { get; set; }

/// <summary>
/// Will only be populated if request is not successful, at which point the
/// response content can be found in this property.
/// </summary>
internal string Error { get; set; }
}
/// <summary>
/// Will only be populated if request is not successful, at which point the
/// response content can be found in this property.
/// </summary>
internal string Error { get; set; }
}
97 changes: 48 additions & 49 deletions src/Model/RetryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,68 @@
using System.Linq;
using System.Threading.Tasks;

namespace Dynamicweb.DataIntegration.Providers.ODataProvider.Model
namespace Dynamicweb.DataIntegration.Providers.ODataProvider.Model;

public static class RetryHelper
{
public static class RetryHelper
public static async Task RetryOnExceptionAsync(int maxRetryAttempts, Func<Task> operation, ILogger _logger)
{
public static async Task RetryOnExceptionAsync(int maxRetryAttempts, Func<Task> operation, ILogger _logger)
await RetryOnExceptionAsync<Exception>(maxRetryAttempts, operation, _logger);
}

public static async Task RetryOnExceptionAsync<TException>(int maxRetryAttempts, Func<Task> operation, ILogger _logger) where TException : Exception
{
if (maxRetryAttempts <= 0)
{
await RetryOnExceptionAsync<Exception>(maxRetryAttempts, operation, _logger);
throw new ArgumentOutOfRangeException(nameof(maxRetryAttempts));
}

public static async Task RetryOnExceptionAsync<TException>(int maxRetryAttempts, Func<Task> operation, ILogger _logger) where TException : Exception
var retryattempts = 0;
do
{
if (maxRetryAttempts <= 0)
try
{
throw new ArgumentOutOfRangeException(nameof(maxRetryAttempts));
retryattempts++;
await operation();
break;
}
var retryattempts = 0;
do
catch (TException ex)
{
try
if (retryattempts == maxRetryAttempts)
{
retryattempts++;
await operation();
break;
_logger?.Error($"After {maxRetryAttempts} attempts, and no response", ex);
}
catch (TException ex)
{
if (retryattempts == maxRetryAttempts)
{
_logger?.Error($"After {maxRetryAttempts} attempts, and no response", ex);
}
int delay = IncreasingDelayInSeconds(retryattempts);
_logger?.Log($"Attempt {retryattempts} of {maxRetryAttempts} failed. New retry after {delay} seconds.");
await CreateRetryDelayForException(maxRetryAttempts, retryattempts, delay);
}
} while (true);
}
int delay = IncreasingDelayInSeconds(retryattempts);
_logger?.Log($"Attempt {retryattempts} of {maxRetryAttempts} failed. New retry after {delay} seconds.");
await CreateRetryDelayForException(maxRetryAttempts, retryattempts, delay);
}
} while (true);
}

private static Task CreateRetryDelayForException(int maxRetryAttempts, int attempts, int delay)
{
return Task.Delay(delay);
}
private static Task CreateRetryDelayForException(int maxRetryAttempts, int attempts, int delay)
{
return Task.Delay(delay);
}

internal static int[] DelayPerAttemptInSeconds =
{
(int) TimeSpan.FromSeconds(5).TotalSeconds,
(int) TimeSpan.FromSeconds(15).TotalSeconds,
(int) TimeSpan.FromSeconds(30).TotalSeconds,
(int) TimeSpan.FromSeconds(45).TotalSeconds,
(int) TimeSpan.FromMinutes(1).TotalSeconds,
(int) TimeSpan.FromMinutes(3).TotalSeconds,
(int) TimeSpan.FromMinutes(5).TotalSeconds,
(int) TimeSpan.FromMinutes(10).TotalSeconds,
(int) TimeSpan.FromMinutes(15).TotalSeconds,
(int) TimeSpan.FromMinutes(30).TotalSeconds
};
internal static int[] DelayPerAttemptInSeconds =
{
(int) TimeSpan.FromSeconds(5).TotalSeconds,
(int) TimeSpan.FromSeconds(15).TotalSeconds,
(int) TimeSpan.FromSeconds(30).TotalSeconds,
(int) TimeSpan.FromSeconds(45).TotalSeconds,
(int) TimeSpan.FromMinutes(1).TotalSeconds,
(int) TimeSpan.FromMinutes(3).TotalSeconds,
(int) TimeSpan.FromMinutes(5).TotalSeconds,
(int) TimeSpan.FromMinutes(10).TotalSeconds,
(int) TimeSpan.FromMinutes(15).TotalSeconds,
(int) TimeSpan.FromMinutes(30).TotalSeconds
};

static int IncreasingDelayInSeconds(int failedAttempts)
static int IncreasingDelayInSeconds(int failedAttempts)
{
if (failedAttempts <= 0)
{
if (failedAttempts <= 0)
{
throw new ArgumentOutOfRangeException();
}
return failedAttempts >= DelayPerAttemptInSeconds.Length ? DelayPerAttemptInSeconds.Last() : DelayPerAttemptInSeconds[failedAttempts];
throw new ArgumentOutOfRangeException();
}
return failedAttempts >= DelayPerAttemptInSeconds.Length ? DelayPerAttemptInSeconds.Last() : DelayPerAttemptInSeconds[failedAttempts];
}
}
Loading

0 comments on commit a7a62bb

Please sign in to comment.