Skip to content

Commit 4ce33fa

Browse files
Merge pull request #252 from steve-sweitzer/master
Support timeout being specified in seconds instead of minutes
2 parents 06d99ac + 6e119d9 commit 4ce33fa

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/AvaTaxClient.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public AvaTaxClient(string appName, string appVersion, string machineName, AvaTa
8383
_userConfiguration = userConfiguration;
8484
}
8585
#if PORTABLE
86-
this.httpClient = new HttpClient() { Timeout = TimeSpan.FromMinutes(_userConfiguration.TimeoutInMinutes) };
86+
this.httpClient = new HttpClient() { Timeout = _userConfiguration.GetTimeOutTimeSpan() };
8787
#endif
8888

8989
// Setup the URI
@@ -118,7 +118,7 @@ public AvaTaxClient(string appName, string appVersion, string machineName, Uri c
118118
_userConfiguration = userConfiguration;
119119
}
120120
#if PORTABLE
121-
this.httpClient = new HttpClient() { Timeout = TimeSpan.FromMinutes(_userConfiguration.TimeoutInMinutes) };
121+
this.httpClient = new HttpClient() { Timeout = _userConfiguration.GetTimeOutTimeSpan() };
122122
#endif
123123
_envUri = customEnvironment;
124124
}
@@ -145,7 +145,7 @@ public AvaTaxClient(HttpClient httpClient, string appName, string appVersion, st
145145
}
146146

147147
this.httpClient = httpClient ?? new HttpClient()
148-
{ Timeout = TimeSpan.FromMinutes(_userConfiguration.TimeoutInMinutes) };
148+
{ Timeout = _userConfiguration.GetTimeOutTimeSpan() };
149149

150150
// Setup the URI
151151
switch (environment)
@@ -181,7 +181,7 @@ public AvaTaxClient(HttpClient httpClient, string appName, string appVersion, st
181181
}
182182

183183
this.httpClient = httpClient ?? new HttpClient()
184-
{ Timeout = TimeSpan.FromMinutes(_userConfiguration.TimeoutInMinutes) };
184+
{ Timeout = _userConfiguration.GetTimeOutTimeSpan() };
185185

186186
_envUri = customEnvironment;
187187
}
@@ -1169,4 +1169,4 @@ private void LogFile_CallCompleted(object sender, EventArgs e)
11691169

11701170
#endregion
11711171
}
1172-
}
1172+
}

src/UserConfiguration.cs

+23-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace Avalara.AvaTax.RestClient
66
public class UserConfiguration
77
{
88
private int _timeOutInMinutes;
9+
private int _timeOutInSeconds;
910
private int _maxRetryAttempts;
1011

1112
/// <summary>
@@ -20,6 +21,26 @@ public int TimeoutInMinutes
2021
}
2122
}
2223

24+
/// <summary>
25+
/// Gets or sets timeout in seconds. If set to a non-zero value, overrides TimeoutInMinutes.
26+
/// </summary>
27+
public int TimeoutInSeconds
28+
{
29+
get { return _timeOutInSeconds; }
30+
set
31+
{
32+
_timeOutInSeconds = value <= 0 ? 0 : value;
33+
}
34+
}
35+
36+
/// <summary>
37+
/// Get <see cref="TimeSpan"/> for the currently set timeout period.
38+
/// </summary>
39+
public TimeSpan GetTimeOutTimeSpan()
40+
{
41+
return _timeOutInSeconds > 0 ? TimeSpan.FromSeconds(_timeOutInSeconds) : TimeSpan.FromMinutes(_timeOutInMinutes);
42+
}
43+
2344
/// <summary>
2445
/// Gets or sets Maximum retry attempts
2546
/// </summary>
@@ -39,6 +60,7 @@ public UserConfiguration()
3960
{
4061
this._maxRetryAttempts = 0;
4162
this._timeOutInMinutes = 20;
63+
this._timeOutInSeconds = 0;
4264
}
4365
}
44-
}
66+
}

0 commit comments

Comments
 (0)