Commit 67f9e30b authored by justcoding121's avatar justcoding121

remove polly dependency #458 ?

parent 863ddc93
using Polly;
using System;
using System;
using System.Threading.Tasks;
using Titanium.Web.Proxy.Network.Tcp;
......@@ -11,14 +10,11 @@ namespace Titanium.Web.Proxy.Network
private readonly TcpConnectionFactory tcpConnectionFactory;
private TcpServerConnection currentConnection;
private Policy policy;
internal RetryPolicy(int retries, TcpConnectionFactory tcpConnectionFactory)
{
this.retries = retries;
this.tcpConnectionFactory = tcpConnectionFactory;
policy = getRetryPolicy();
}
/// <summary>
......@@ -32,14 +28,14 @@ namespace Titanium.Web.Proxy.Network
Func<Task<TcpServerConnection>> generator, TcpServerConnection initialConnection)
{
currentConnection = initialConnection;
Exception exception = null;
bool @continue = true;
Exception exception = null;
try
var attempts = retries;
while (attempts >= 0)
{
//retry on error with polly policy
//do not use polly context to store connection; it does not save states b/w attempts
await policy.ExecuteAsync(async () =>
try
{
//setup connection
currentConnection = currentConnection as TcpServerConnection ??
......@@ -47,23 +43,27 @@ namespace Titanium.Web.Proxy.Network
//try
@continue = await action(currentConnection);
});
}
catch (Exception e) { exception = e; }
return new RetryResult(currentConnection, exception, @continue);
catch (T ex)
{
exception = ex;
await onRetry(ex);
}
//get the policy
private Policy getRetryPolicy()
if(exception == null)
{
return Policy.Handle<T>()
.RetryAsync(retries,
onRetryAsync: onRetry);
break;
}
exception = null;
attempts--;
}
return new RetryResult(currentConnection, exception, @continue);
}
//before retry clear connection
private async Task onRetry(Exception ex, int attempt)
private async Task onRetry(Exception ex)
{
if (currentConnection != null)
{
......
......@@ -12,7 +12,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Polly" Version="6.0.1" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.2" />
<PackageReference Include="StreamExtended" Version="1.0.179" />
</ItemGroup>
......
......@@ -16,7 +16,6 @@
<dependencies>
<dependency id="StreamExtended" version="1.0.179" />
<dependency id="Portable.BouncyCastle" version="1.8.2" />
<dependency id="Polly" version="6.0.1"/>
</dependencies>
</metadata>
<files>
......
......@@ -3,5 +3,4 @@
<packages>
<package id="Portable.BouncyCastle" version="1.8.2" targetFramework="net45" />
<package id="StreamExtended" version="1.0.179" targetFramework="net45" />
<package id="Polly" version="6.0.1" targetFramework="net45" />
</packages>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment