INIT su cloud by param yaml

This commit is contained in:
Samuele E. Locatelli
2019-03-28 09:08:05 +01:00
parent 148edf7dde
commit 1a4fe23cb7
3 changed files with 54 additions and 24 deletions
+29 -18
View File
@@ -55,7 +55,15 @@ namespace MConnectSDK
/// <summary>
/// URL BASE per le chiamate
/// </summary>
protected string baseUrl = @"https://stg.maestroconnect.scmgroup.com/";
protected string BaseUrl = @"https://stg.maestroconnect.scmgroup.com/";
/// <summary>
/// URL BASE per le chiamate
/// </summary>
protected string PingTarget = @"stg.maestroconnect.scmgroup.com";
/// <summary>
/// URL per test HEALT del cloud
/// </summary>
protected string AliveTarget = @"https://stg.api.maestroconnect.scmgroup.com/health";
/// <summary>
/// DateTime di watchdog
/// </summary>
@@ -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"];
+22 -5
View File
@@ -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
/// <summary>
/// Test ping x indirizzo indicato
/// </summary>
/// <param name="address"></param>
/// <param name="address">Hostname or Address</param>
/// <returns></returns>
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;
}
/// <summary>
/// Effettua download async della pagina indicata
/// </summary>
/// <param name="pageURL"></param>
public static async Task<string> 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
/// <summary>
/// Effettua chaimata URL e restituisce risultato
+3 -1
View File
@@ -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: