This commit is contained in:
2021-08-11 18:05:02 +00:00
parent 5c0c09beb1
commit 168eaf8e37
2 changed files with 20 additions and 11 deletions

View File

@@ -139,7 +139,7 @@ namespace AyaNova.PlugIn.V8
} }
//#endif //#endif
util.Initialized = false;
Auth d = new Auth(); Auth d = new Auth();
var res = d.ShowDialog(); ; var res = d.ShowDialog(); ;
if (res == DialogResult.Cancel) if (res == DialogResult.Cancel)

View File

@@ -21,7 +21,7 @@ namespace AyaNova.PlugIn.V8
public static GZTW.AyaNova.BLL.LocalizedTextTable LocaleText = null; public static GZTW.AyaNova.BLL.LocalizedTextTable LocaleText = null;
const string TEST_ROUTE = "notify/hello"; const string TEST_ROUTE = "notify/hello";
const string API_BASE_ROUTE = "api/v8/"; const string API_BASE_ROUTE = "api/v8/";
static HttpClient client = new HttpClient(); public static HttpClient client = null;
//url once known to be good //url once known to be good
internal static string ApiBaseUrl { get; set; } internal static string ApiBaseUrl { get; set; }
internal static string JWT { get; set; } internal static string JWT { get; set; }
@@ -40,6 +40,10 @@ namespace AyaNova.PlugIn.V8
private static void InitClient() private static void InitClient()
{ {
if (Initialized) return; if (Initialized) return;
if (client != null)
client.Dispose();
client = null;
client = new HttpClient();
client.BaseAddress = new Uri(ApiBaseUrl); client.BaseAddress = new Uri(ApiBaseUrl);
client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
@@ -63,22 +67,27 @@ namespace AyaNova.PlugIn.V8
} }
if (!serverUrl.StartsWith("http")) serverUrl = "http://" + serverUrl; if (!serverUrl.StartsWith("http")) serverUrl = "http://" + serverUrl;
ApiBaseUrl = serverUrl;
InitClient();
//try to connect, ping the server api //try to connect, ping the server api
if (!Initialized) //if (!Initialized)
{ //{
client.BaseAddress = new Uri(serverUrl); // client.BaseAddress = new Uri(serverUrl);
client.DefaultRequestHeaders.Accept.Clear(); // client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
Initialized = true; // Initialized = true;
} //}
try try
{ {
// TimeSpan tsDefault = client.Timeout;
// client.Timeout = new TimeSpan(0, 0, 20);
HttpResponseMessage response = await client.GetAsync(serverUrl + TEST_ROUTE); HttpResponseMessage response = await client.GetAsync(serverUrl + TEST_ROUTE);
// client.Timeout = tsDefault;
if (response.IsSuccessStatusCode) if (response.IsSuccessStatusCode)
{ {
ApiBaseUrl = serverUrl;
return "OK"; return "OK";
} }
else else