diff --git a/WD7UVN_HFT_2023241.Client/Program.cs b/WD7UVN_HFT_2023241.Client/Program.cs index 982467a..53277cb 100644 --- a/WD7UVN_HFT_2023241.Client/Program.cs +++ b/WD7UVN_HFT_2023241.Client/Program.cs @@ -9,6 +9,8 @@ namespace WD7UVN_HFT_2023241.Client { private static async Task Main(string[] args) { + RestService.Init(); + var commonConfig = new MenuConfig { Selector = "--> ", diff --git a/WD7UVN_HFT_2023241.Client/RestService.cs b/WD7UVN_HFT_2023241.Client/RestService.cs index f2409cd..a8579d9 100644 --- a/WD7UVN_HFT_2023241.Client/RestService.cs +++ b/WD7UVN_HFT_2023241.Client/RestService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Net; @@ -12,17 +12,7 @@ namespace WD7UVN_HFT_2023241.Client { private static HttpClient client; - public RestService(string baseurl = "https://localhost:5001", string pingableEndpoint = "/swagger") - { - bool isOk = false; - do - { - isOk = Ping(baseurl + pingableEndpoint); - } while (isOk == false); - Init(baseurl); - } - - private bool Ping(string url) + private static bool Ping(string url) { try { @@ -38,8 +28,21 @@ namespace WD7UVN_HFT_2023241.Client } } - private void Init(string baseurl) + public static void Init(string baseurl = "https://localhost:5001", string pingableEndpoint = "/swagger") { + int tries = 0; + bool isOk = false; + do + { + isOk = Ping(baseurl + pingableEndpoint); + tries++; + } while (isOk == false || tries > 5); + + if (isOk == false) + { + throw new EndpointNotAvailableException("Endpoint is not available!"); + } + HttpClientHandler handler = new HttpClientHandler(); handler.ClientCertificateOptions = ClientCertificateOption.Manual; handler.ServerCertificateCustomValidationCallback =