Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support timeout being specified in seconds instead of minutes #252

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/AvaTaxClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public AvaTaxClient(string appName, string appVersion, string machineName, AvaTa
_userConfiguration = userConfiguration;
}
#if PORTABLE
this.httpClient = new HttpClient() { Timeout = TimeSpan.FromMinutes(_userConfiguration.TimeoutInMinutes) };
this.httpClient = new HttpClient() { Timeout = _userConfiguration.GetTimeOutTimeSpan() };
#endif

// Setup the URI
Expand Down Expand Up @@ -118,7 +118,7 @@ public AvaTaxClient(string appName, string appVersion, string machineName, Uri c
_userConfiguration = userConfiguration;
}
#if PORTABLE
this.httpClient = new HttpClient() { Timeout = TimeSpan.FromMinutes(_userConfiguration.TimeoutInMinutes) };
this.httpClient = new HttpClient() { Timeout = _userConfiguration.GetTimeOutTimeSpan() };
#endif
_envUri = customEnvironment;
}
Expand All @@ -145,7 +145,7 @@ public AvaTaxClient(HttpClient httpClient, string appName, string appVersion, st
}

this.httpClient = httpClient ?? new HttpClient()
{ Timeout = TimeSpan.FromMinutes(_userConfiguration.TimeoutInMinutes) };
{ Timeout = _userConfiguration.GetTimeOutTimeSpan() };

// Setup the URI
switch (environment)
Expand Down Expand Up @@ -181,7 +181,7 @@ public AvaTaxClient(HttpClient httpClient, string appName, string appVersion, st
}

this.httpClient = httpClient ?? new HttpClient()
{ Timeout = TimeSpan.FromMinutes(_userConfiguration.TimeoutInMinutes) };
{ Timeout = _userConfiguration.GetTimeOutTimeSpan() };

_envUri = customEnvironment;
}
Expand Down Expand Up @@ -1169,4 +1169,4 @@ private void LogFile_CallCompleted(object sender, EventArgs e)

#endregion
}
}
}
24 changes: 23 additions & 1 deletion src/UserConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Avalara.AvaTax.RestClient
public class UserConfiguration
{
private int _timeOutInMinutes;
private int _timeOutInSeconds;
private int _maxRetryAttempts;

/// <summary>
Expand All @@ -20,6 +21,26 @@ public int TimeoutInMinutes
}
}

/// <summary>
/// Gets or sets timeout in seconds. If set to a non-zero value, overrides TimeoutInMinutes.
/// </summary>
public int TimeoutInSeconds
{
get { return _timeOutInSeconds; }
set
{
_timeOutInSeconds = value <= 0 ? 0 : value;
}
}

/// <summary>
/// Get <see cref="TimeSpan"/> for the currently set timeout period.
/// </summary>
public TimeSpan GetTimeOutTimeSpan()
{
return _timeOutInSeconds > 0 ? TimeSpan.FromSeconds(_timeOutInSeconds) : TimeSpan.FromMinutes(_timeOutInMinutes);
}

/// <summary>
/// Gets or sets Maximum retry attempts
/// </summary>
Expand All @@ -39,6 +60,7 @@ public UserConfiguration()
{
this._maxRetryAttempts = 0;
this._timeOutInMinutes = 20;
this._timeOutInSeconds = 0;
}
}
}
}