diff --git a/MConnectSDK/MConnectClient.cs b/MConnectSDK/MConnectClient.cs
index b7f6b26..59b2d33 100644
--- a/MConnectSDK/MConnectClient.cs
+++ b/MConnectSDK/MConnectClient.cs
@@ -55,7 +55,15 @@ namespace MConnectSDK
///
/// URL BASE per le chiamate
///
- protected string baseUrl = @"https://stg.maestroconnect.scmgroup.com/";
+ protected string BaseUrl = @"https://stg.maestroconnect.scmgroup.com/";
+ ///
+ /// URL BASE per le chiamate
+ ///
+ protected string PingTarget = @"stg.maestroconnect.scmgroup.com";
+ ///
+ /// URL per test HEALT del cloud
+ ///
+ protected string AliveTarget = @"https://stg.api.maestroconnect.scmgroup.com/health";
///
/// DateTime di watchdog
///
@@ -341,24 +349,25 @@ namespace MConnectSDK
answ.Source = SourceType.LOCAL;
}
- // verifico chiamata server...
- if (_currParam.testMode)
+ // verifico STATO sistema A VALLE...
+
+ // STEP 1: PING a server (locale/remoto)
+ bool pingOk = false;
+ if (PingTarget != "")
{
- // Fingo che tutto vada bene e di conseguenza setto risposta...
- answ.CloudStatusOk = true;
- answ.Source = SourceType.CLOUD;
- // attesa random...
- Random r = new Random();
- Thread.Sleep(100 + r.Next(0, 100));
+ pingOk = Utils.pingAddress(PingTarget);
}
- else
+ // STEP 2: test HEALTH page...
+ if (pingOk)
{
- // TBD !!!FARE!!! le vere chiamate di testing remoto...
-
- // PING a server (locale/remoto)
-
- // verifica chiamapa pagina HEALT con reply = "HELLO" | https://stg.api.maestroconnect.scmgroup.com/health
-
+ // verifica chiamata pagina HEALT con reply = "HELLO" | https://stg.api.maestroconnect.scmgroup.com/health
+ var pageRes = Utils.DownloadPageAsync(AliveTarget);
+ pageRes.Wait();
+ if (pageRes.Result.IndexOf("HELLO") >= 0)
+ {
+ answ.CloudStatusOk = true;
+ answ.Source = SourceType.CLOUD;
+ }
}
answ.CallResultOk = (answ.CloudStatusOk || answ.LocalStatusOk);
return answ;
@@ -514,8 +523,10 @@ namespace MConnectSDK
// imposto val da file YAML...
_MConnectID = config["MachineID"].ToString();
_ClientID = config["Client_ID"].ToString();
- // URL base x le chiamate REALI
- baseUrl = config["BaseUrl"].ToString();
+ // URL base x le chiamate REALI
+ BaseUrl = config["BaseUrl"].ToString();
+ PingTarget = config["PingTarget"].ToString();
+ AliveTarget = config["AliveTarget"].ToString();
var redisConf = config["MemoryLayer"]["Redis"];
diff --git a/MConnectSDK/Utils.cs b/MConnectSDK/Utils.cs
index 05d08aa..a5b40c9 100644
--- a/MConnectSDK/Utils.cs
+++ b/MConnectSDK/Utils.cs
@@ -2,8 +2,9 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
-using System.Net;
+using System.Net.Http;
using System.Net.NetworkInformation;
+using System.Threading.Tasks;
namespace MConnectSDK
{
@@ -12,13 +13,13 @@ namespace MConnectSDK
///
/// Test ping x indirizzo indicato
///
- ///
+ /// Hostname or Address
///
- public static bool pingAddress(IPAddress address)
+ public static bool pingAddress(string target)
{
bool answ = false;
Ping pingSender = new Ping();
- PingReply reply = pingSender.Send(address, 100);
+ PingReply reply = pingSender.Send(target, 100);
// se passa il ping do OK...
if (reply.Status == IPStatus.Success)
{
@@ -74,7 +75,23 @@ namespace MConnectSDK
}
return sMacAddress;
}
-
+ ///
+ /// Effettua download async della pagina indicata
+ ///
+ ///
+ public static async Task DownloadPageAsync(string pageURL)
+ {
+ string result = "";
+ // ... Use HttpClient.
+ using (HttpClient client = new HttpClient())
+ using (HttpResponseMessage response = await client.GetAsync(pageURL))
+ using (HttpContent content = response.Content)
+ {
+ // ... lettura contenuto...
+ result = await content.ReadAsStringAsync();
+ }
+ return result;
+ }
#if false
///
/// Effettua chaimata URL e restituisce risultato
diff --git a/TestClient/mconnect.conf.yaml b/TestClient/mconnect.conf.yaml
index 1dbe01f..5d383cc 100644
--- a/TestClient/mconnect.conf.yaml
+++ b/TestClient/mconnect.conf.yaml
@@ -1,7 +1,9 @@
#File di conf per MConnectClientSDK
conf:
Client_ID: "test"
- MachineID: "MCID-0009-1234-5678"
+ MachineID: "MCID-0009-1234-5678"
+ PingTarget: "stg.api.maestroconnect.scmgroup.com"
+ AliveTarget: "https://stg.api.maestroconnect.scmgroup.com/health"
BaseUrl: "https://stg.api.maestroconnect.scmgroup.com/api"
MemoryLayer:
Redis: