Completo sim INIT come async..

This commit is contained in:
Samuele E. Locatelli
2019-02-23 09:17:41 +01:00
parent f008106660
commit c74cfb0335
3 changed files with 92 additions and 21 deletions
+6 -1
View File
@@ -1,4 +1,7 @@
namespace MConnectSDK
using System;
using System.Threading;
namespace MConnectSDK
{
/// <summary>
/// Client per connessione a MaestroConnect
@@ -74,6 +77,8 @@
source = comSource.cloud,
callSuccess = true
};
Random r = new Random();
Thread.Sleep(1000 + r.Next(0, 200));
}
else
{
+42 -11
View File
@@ -55,6 +55,8 @@
this.lblReqStatus = new System.Windows.Forms.Label();
this.lblRetData = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label6 = new System.Windows.Forms.Label();
this.lblConsole = new System.Windows.Forms.Label();
this.statusStrip1.SuspendLayout();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
@@ -203,7 +205,7 @@
this.groupBox2.Controls.Add(this.btnTryAuth);
this.groupBox2.Controls.Add(this.btnInit);
this.groupBox2.Controls.Add(this.btnResetParam);
this.groupBox2.Location = new System.Drawing.Point(12, 171);
this.groupBox2.Location = new System.Drawing.Point(13, 119);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(982, 100);
this.groupBox2.TabIndex = 14;
@@ -268,22 +270,28 @@
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 3;
this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tableLayoutPanel1.ColumnCount = 4;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 30F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 30F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 40F));
this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.label2, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.label5, 2, 0);
this.tableLayoutPanel1.Controls.Add(this.lblReqStatus, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.lblRetData, 1, 1);
this.tableLayoutPanel1.Controls.Add(this.pictureBox1, 2, 1);
this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 302);
this.tableLayoutPanel1.Controls.Add(this.label6, 3, 0);
this.tableLayoutPanel1.Controls.Add(this.lblConsole, 3, 1);
this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 225);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10.90909F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 89.09091F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(807, 330);
this.tableLayoutPanel1.Size = new System.Drawing.Size(983, 457);
this.tableLayoutPanel1.TabIndex = 15;
//
// label1
@@ -298,7 +306,7 @@
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(245, 0);
this.label2.Location = new System.Drawing.Point(199, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(85, 17);
this.label2.TabIndex = 1;
@@ -307,7 +315,7 @@
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(487, 0);
this.label5.Location = new System.Drawing.Point(395, 0);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(64, 17);
this.label5.TabIndex = 2;
@@ -316,7 +324,7 @@
// lblReqStatus
//
this.lblReqStatus.AutoSize = true;
this.lblReqStatus.Location = new System.Drawing.Point(3, 36);
this.lblReqStatus.Location = new System.Drawing.Point(3, 49);
this.lblReqStatus.Name = "lblReqStatus";
this.lblReqStatus.Size = new System.Drawing.Size(20, 17);
this.lblReqStatus.TabIndex = 3;
@@ -325,7 +333,7 @@
// lblRetData
//
this.lblRetData.AutoSize = true;
this.lblRetData.Location = new System.Drawing.Point(245, 36);
this.lblRetData.Location = new System.Drawing.Point(199, 49);
this.lblRetData.Name = "lblRetData";
this.lblRetData.Size = new System.Drawing.Size(20, 17);
this.lblRetData.TabIndex = 4;
@@ -334,12 +342,33 @@
// pictureBox1
//
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Location = new System.Drawing.Point(487, 39);
this.pictureBox1.Location = new System.Drawing.Point(395, 52);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(317, 288);
this.pictureBox1.Size = new System.Drawing.Size(288, 402);
this.pictureBox1.TabIndex = 5;
this.pictureBox1.TabStop = false;
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(689, 0);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(38, 17);
this.label6.TabIndex = 6;
this.label6.Text = "LOG";
//
// lblConsole
//
this.lblConsole.AutoSize = true;
this.lblConsole.BackColor = System.Drawing.SystemColors.Desktop;
this.lblConsole.Dock = System.Windows.Forms.DockStyle.Fill;
this.lblConsole.ForeColor = System.Drawing.Color.Lime;
this.lblConsole.Location = new System.Drawing.Point(689, 49);
this.lblConsole.Name = "lblConsole";
this.lblConsole.Size = new System.Drawing.Size(291, 408);
this.lblConsole.TabIndex = 7;
this.lblConsole.Text = "...";
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
@@ -392,6 +421,8 @@
private System.Windows.Forms.Label lblReqStatus;
private System.Windows.Forms.Label lblRetData;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label lblConsole;
}
}
+44 -9
View File
@@ -16,13 +16,20 @@ namespace TestClient
private DateTime previousTime = DateTime.Now;
protected MConnectClient MCC;
protected requestStatus reqStatus;
public MainForm()
{
InitializeComponent();
myInit();
synchronizationContext = SynchronizationContext.Current;
var clockTask = myInitAsync();
}
protected void myInit()
{
var clockTask = updateClockAsync();
fixDisplay();
lblConsole.Text = "";
}
private void fixDisplay()
@@ -34,11 +41,6 @@ namespace TestClient
chkEnrolled.Visible = showTP;
}
private async Task myInitAsync()
{
await updateClockAsync();
}
private async Task updateClockAsync()
{
await Task.Run(() =>
@@ -68,7 +70,7 @@ namespace TestClient
previousTime = timeNow;
}
private void btnInit_Click(object sender, EventArgs e)
private async void btnInit_Click(object sender, EventArgs e)
{
confParam param = new confParam
{
@@ -76,8 +78,37 @@ namespace TestClient
redisConnAdmin = txtConnParam.Text + ",allowAdmin=true",
testMode = chkTestMode.Checked
};
MCC = new MConnectClient(txtMConnectID.Text, param);
var reqStatus = MCC.init();
// 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, param);
reqStatus = MCC.init();
synchronizationContext.Post(new SendOrPostCallback(o =>
{
refreshRequestStatus();
}), "");
});
}
public void refreshRequestStatus()
{
// mostro risultato
StringBuilder sb = new StringBuilder();
sb.AppendLine("-------------------------");
@@ -89,6 +120,10 @@ namespace TestClient
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)