From 52f71be90b468c8519705736c95613ca3b3ec5f5 Mon Sep 17 00:00:00 2001 From: DucDangAnh Date: Tue, 14 Jul 2020 14:48:53 +0700 Subject: [PATCH] ApiController - Update numberOfRetry --- AIParkingApplication/ApiController.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/AIParkingApplication/ApiController.cs b/AIParkingApplication/ApiController.cs index 0a02a20..1e2331d 100644 --- a/AIParkingApplication/ApiController.cs +++ b/AIParkingApplication/ApiController.cs @@ -9,19 +9,19 @@ namespace AIParkingApplication { public class ApiController : IDisposable { - private const int MAX_REQUEST = 3; private HttpClient httpClient; private bool isHttpClientDisposabled; + private int numberOfRetry; - public ApiController(string serverIPAddress, int numberOfRetry = 5) + public ApiController(string serverIPAddress, int numberOfRetry = 3) { - httpClient = new HttpClient { BaseAddress = new Uri($"http://{serverIPAddress}"), Timeout = TimeSpan.FromSeconds(5) }; isHttpClientDisposabled = false; + this.numberOfRetry = numberOfRetry; } ~ApiController() @@ -92,7 +92,7 @@ namespace AIParkingApplication requestCounter += 1; await Task.Delay(100); } - while (response.StatusCode != HttpStatusCode.OK && requestCounter < MAX_REQUEST); + while (response.StatusCode != HttpStatusCode.OK && requestCounter < numberOfRetry); var cardValication = await response.Content.ReadAsAsync(); return cardValication; @@ -135,7 +135,7 @@ namespace AIParkingApplication response.EnsureSuccessStatusCode(); requestCounter += 1; await Task.Delay(100); - } while (response.StatusCode != HttpStatusCode.OK && requestCounter < MAX_REQUEST); + } while (response.StatusCode != HttpStatusCode.OK && requestCounter < numberOfRetry); SaveLogRespone saveLogRespone = await response.Content.ReadAsAsync(); return saveLogRespone; }