Renamed fields to match private naming style.

Fixed issue where _lastRequest in DownloadClient was not updated.
This commit is contained in:
glax 2023-05-18 17:41:44 +02:00
parent 2b7f759e7e
commit 81f380dc3c

View File

@ -27,22 +27,23 @@ public abstract class Connector
internal class DownloadClient internal class DownloadClient
{ {
private TimeSpan requestSpeed; private readonly TimeSpan _requestSpeed;
private DateTime lastRequest; private DateTime _lastRequest;
static readonly HttpClient client = new HttpClient(); static readonly HttpClient client = new HttpClient();
public DownloadClient(uint delay) public DownloadClient(uint delay)
{ {
this.requestSpeed = TimeSpan.FromMilliseconds(delay); _requestSpeed = TimeSpan.FromMilliseconds(delay);
this.lastRequest = DateTime.Now.Subtract(requestSpeed); _lastRequest = DateTime.Now.Subtract(_requestSpeed);
} }
public RequestResult MakeRequest(string url) public RequestResult MakeRequest(string url)
{ {
while((DateTime.Now - lastRequest) < requestSpeed) while((DateTime.Now - _lastRequest) < _requestSpeed)
Thread.Sleep(10); Thread.Sleep(10);
_lastRequest = DateTime.Now;
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, url); HttpRequestMessage requestMessage = new(HttpMethod.Get, url);
HttpResponseMessage response = client.Send(requestMessage); HttpResponseMessage response = client.Send(requestMessage);
Stream resultString = response.IsSuccessStatusCode ? response.Content.ReadAsStream() : Stream.Null; Stream resultString = response.IsSuccessStatusCode ? response.Content.ReadAsStream() : Stream.Null;
return new RequestResult(response.StatusCode, resultString); return new RequestResult(response.StatusCode, resultString);