From 81f380dc3c1db9efa07a84f245b76aef2f69f5a6 Mon Sep 17 00:00:00 2001 From: glax <--local> Date: Thu, 18 May 2023 17:41:44 +0200 Subject: [PATCH] Renamed fields to match private naming style. Fixed issue where _lastRequest in DownloadClient was not updated. --- Tranga/Connector.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Tranga/Connector.cs b/Tranga/Connector.cs index b859ba7..2012ad2 100644 --- a/Tranga/Connector.cs +++ b/Tranga/Connector.cs @@ -27,22 +27,23 @@ public abstract class Connector internal class DownloadClient { - private TimeSpan requestSpeed; - private DateTime lastRequest; + private readonly TimeSpan _requestSpeed; + private DateTime _lastRequest; static readonly HttpClient client = new HttpClient(); public DownloadClient(uint delay) { - this.requestSpeed = TimeSpan.FromMilliseconds(delay); - this.lastRequest = DateTime.Now.Subtract(requestSpeed); + _requestSpeed = TimeSpan.FromMilliseconds(delay); + _lastRequest = DateTime.Now.Subtract(_requestSpeed); } public RequestResult MakeRequest(string url) { - while((DateTime.Now - lastRequest) < requestSpeed) + while((DateTime.Now - _lastRequest) < _requestSpeed) Thread.Sleep(10); - - HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, url); + _lastRequest = DateTime.Now; + + HttpRequestMessage requestMessage = new(HttpMethod.Get, url); HttpResponseMessage response = client.Send(requestMessage); Stream resultString = response.IsSuccessStatusCode ? response.Content.ReadAsStream() : Stream.Null; return new RequestResult(response.StatusCode, resultString);