159 lines
4.0 KiB
C#
159 lines
4.0 KiB
C#
using MConnectSDK;
|
|
using System;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace TestClient
|
|
{
|
|
public partial class MainForm : Form
|
|
{
|
|
private CancellationTokenSource _cts;
|
|
|
|
|
|
private readonly SynchronizationContext synchronizationContext;
|
|
private DateTime previousTime = DateTime.Now;
|
|
|
|
protected MConnectClient MCC;
|
|
protected requestStatus reqStatus;
|
|
|
|
public MainForm()
|
|
{
|
|
InitializeComponent();
|
|
myInit();
|
|
synchronizationContext = SynchronizationContext.Current;
|
|
}
|
|
|
|
protected void myInit()
|
|
{
|
|
var clockTask = updateClockAsync();
|
|
fixDisplay();
|
|
lblConsole.Text = "";
|
|
}
|
|
|
|
private void fixDisplay()
|
|
{
|
|
// controllo se visualizzare parametri di testing...
|
|
bool showTP = chkTestMode.Checked;
|
|
chkCloudOk.Visible = showTP;
|
|
chkLocalOk.Visible = showTP;
|
|
chkEnrolled.Visible = showTP;
|
|
}
|
|
|
|
private async Task updateClockAsync()
|
|
{
|
|
await Task.Run(() =>
|
|
{
|
|
while (true)
|
|
{
|
|
Thread.Sleep(50);
|
|
UpdateUI();
|
|
}
|
|
});
|
|
}
|
|
|
|
public void UpdateUI()
|
|
{
|
|
var timeNow = DateTime.Now;
|
|
|
|
if ((DateTime.Now - previousTime).Milliseconds <= 250)
|
|
{
|
|
return;
|
|
}
|
|
|
|
synchronizationContext.Post(new SendOrPostCallback(o =>
|
|
{
|
|
lblClock.Text = timeNow.ToString("ddd dd.MM.yyyy HH:mm:ss");
|
|
}), "");
|
|
|
|
previousTime = timeNow;
|
|
}
|
|
|
|
private async void btnInit_Click(object sender, EventArgs e)
|
|
{
|
|
confParam param = new confParam
|
|
{
|
|
redisConn = txtConnParam.Text,
|
|
redisConnAdmin = txtConnParam.Text + ",allowAdmin=true",
|
|
testMode = chkTestMode.Checked
|
|
};
|
|
|
|
// init in modalità Task based...
|
|
await Task.Run(() =>
|
|
{
|
|
var initObj = doInitAsync(param);
|
|
});
|
|
|
|
// aggiorno log console
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.AppendLine("--------------------------------------------------");
|
|
sb.AppendLine(string.Format("{0:HH.mm.ss.fff} | START INIT", DateTime.Now));
|
|
sb.AppendLine("");
|
|
lblConsole.Text = sb.ToString();
|
|
}
|
|
|
|
private async Task doInitAsync(confParam param)
|
|
{
|
|
await Task.Run(() =>
|
|
{
|
|
MCC = new MConnectClient(txtMConnectID.Text.Trim(), txtClientID.Text.Trim(), param);
|
|
reqStatus = MCC.init();
|
|
|
|
synchronizationContext.Post(new SendOrPostCallback(o =>
|
|
{
|
|
refreshRequestStatus();
|
|
}), "");
|
|
});
|
|
}
|
|
|
|
public void refreshRequestStatus()
|
|
{
|
|
// mostro risultato
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.AppendLine("-------------------------");
|
|
sb.AppendLine("- Request Status");
|
|
sb.AppendLine("-------------------------");
|
|
sb.AppendLine("isHmiEnrolled: " + reqStatus.isHmiEnrolled);
|
|
sb.AppendLine("cloudConnection: " + reqStatus.cloudConnection);
|
|
sb.AppendLine("localConnection: " + reqStatus.localConnection);
|
|
sb.AppendLine("callSuccess: " + reqStatus.callSuccess);
|
|
sb.AppendLine("-------------------------");
|
|
lblReqStatus.Text = sb.ToString();
|
|
sb.AppendLine("");
|
|
sb.AppendLine(string.Format("{0:HH.mm.ss.fff} | END INIT", DateTime.Now));
|
|
sb.AppendLine("--------------------------------------------------");
|
|
lblConsole.Text += sb.ToString();
|
|
}
|
|
|
|
private void btnResetParam_Click(object sender, EventArgs e)
|
|
{
|
|
txtMConnectID.Text = "MCID-0000-1234-5678";
|
|
txtClientID.Text = "HMI_TEST_CLI";
|
|
chkTestMode.Checked = true;
|
|
txtConnParam.Text = "127.0.0.1,abortConnect=false,ssl=false";
|
|
fixDisplay();
|
|
}
|
|
|
|
private void chkCloudOk_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void chkLocalOk_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void chkEnrolled_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void chkTestMode_Click(object sender, EventArgs e)
|
|
{
|
|
fixDisplay();
|
|
}
|
|
}
|
|
}
|