Fix errori segnalati da Damiano e Ferdinando

This commit is contained in:
Samuele E. Locatelli
2019-03-13 19:39:54 +01:00
parent c167dcb1e4
commit 757a81bb3f
5 changed files with 141 additions and 69 deletions
+36 -27
View File
@@ -319,7 +319,7 @@ namespace MConnectSDK
Result answ = new Result()
{
// init in stato ND...
isHmiEnrolled = false,
IsHmiEnrolled = false,
CloudStatusOk = false,
LocalStatusOk = false,
Source = SourceType.OFFLINE,
@@ -330,8 +330,8 @@ namespace MConnectSDK
if (answ.LocalStatusOk)
{
// cerco i TOKEN in REDIS...
answ.isAuth = !string.IsNullOrEmpty(refresh_token);
answ.isHmiEnrolled = enrollDate < DateTime.Now;
answ.IsAuth = !string.IsNullOrEmpty(refresh_token);
answ.IsHmiEnrolled = enrollDate < DateTime.Now;
answ.Source = SourceType.LOCAL;
}
@@ -341,7 +341,6 @@ namespace MConnectSDK
// Fingo che tutto vada bene e di conseguenza setto risposta...
answ.CloudStatusOk = true;
answ.Source = SourceType.CLOUD;
answ.CallResultOk = true;
// attesa random...
Random r = new Random();
Thread.Sleep(100 + r.Next(0, 100));
@@ -350,6 +349,7 @@ namespace MConnectSDK
{
/// TBD !!!FARE!!! le vere chiamate di testing remoto...
}
answ.CallResultOk = (answ.CloudStatusOk || answ.LocalStatusOk);
return answ;
}
/// <summary>
@@ -473,13 +473,12 @@ namespace MConnectSDK
/// <summary>
/// Inizializzazione classe specificando il file di conf con i parametri
/// </summary>
/// <param name="confFilePath"></param>
public MConnectClient(string confFilePath = "mconnect.conf.yaml")
public MConnectClient()
{
parseConfFile(confFilePath);
lg = LogManager.GetCurrentClassLogger();
ML = new memLayer(_currParam);
confParam param = new confParam();
ML = new memLayer(param);
}
/// <summary>
/// Parsing file di configurazione
@@ -527,16 +526,21 @@ namespace MConnectSDK
{ }
// registro parametri...
_currParam = param;
ML = new memLayer(_currParam);
}
/// <summary>
/// Metodo di INIT della classe di comunicazione
/// </summary>
/// </summary>
/// <param name="confFilePath"></param>
/// <param name="token">Token, che può benissimo essere CancellationToken.None</param>
/// <param name="progress"></param>
/// <returns></returns>
public async Task<Result> initSDKAsync(CancellationToken token, IProgress<Result> progress = null)
public async Task<Result> InitSDKAsync(string confFilePath, CancellationToken token, IProgress<Result> progress = null)
{
// controlloare file di conf se valido... = "mconnect.conf.yaml"
parseConfFile(confFilePath);
Result _currStatus = new Result();
await Task.Run(() =>
{
// svuoto TUTTI i dati x INIT...
@@ -545,9 +549,10 @@ namespace MConnectSDK
// iniziod a watchdog...
setWatchdog();
// init output
reqStatus = preCheckStatus();
_currStatus = preCheckStatus();
reqStatus = _currStatus;
});
return reqStatus;
return _currStatus;
}
/// <summary>
/// Recupera status del client
@@ -559,8 +564,6 @@ namespace MConnectSDK
{
// iniziod a watchdog...
setWatchdog();
// init output
reqStatus = preCheckStatus();
});
return reqStatus;
}
@@ -573,10 +576,13 @@ namespace MConnectSDK
// init output
ActivationPayload answ = new ActivationPayload();
StringBuilder sb = new StringBuilder();
#if false
// init altro
reqStatus = preCheckStatus();
reqStatus = preCheckStatus();
#endif
var _currReq = reqStatus;
// verifico autorizzazione... se non c'è TENTO auth...
if (!reqStatus.isHmiEnrolled)
if (!reqStatus.IsHmiEnrolled)
{
// attesa come richiesto da call precedente...
Thread.Sleep(tokResp.interval);
@@ -608,9 +614,9 @@ namespace MConnectSDK
answ.QrCode = "";
// registro che è OK x AUTH
answ.HasAuth = true;
reqStatus.isAuth = true;
_currReq.IsAuth = true;
answ.IsEnrolled = false;
reqStatus.isHmiEnrolled = false;
_currReq.IsHmiEnrolled = false;
}
// non autorizzato...
else
@@ -625,6 +631,7 @@ namespace MConnectSDK
answ.Message = sb.ToString();
}
}
reqStatus = _currReq;
// ritorno!
return answ;
}
@@ -641,7 +648,7 @@ namespace MConnectSDK
// init altro
reqStatus = preCheckStatus();
// verifico autorizzazione... se non c'è TENTO auth...
if (!reqStatus.isHmiEnrolled)
if (!reqStatus.IsHmiEnrolled)
{
// attesa come richiesto da call precedente...
Thread.Sleep(tokResp.interval);
@@ -673,9 +680,9 @@ namespace MConnectSDK
answ.QrCode = "";
// registro che è OK x AUTH
answ.HasAuth = true;
reqStatus.isAuth = true;
reqStatus.IsAuth = true;
answ.IsEnrolled = false;
reqStatus.isHmiEnrolled = false;
reqStatus.IsHmiEnrolled = false;
// controllo se sia stato arruolato, altrimenti lo arruolo...
if (_currParam.testMode)
{
@@ -683,7 +690,7 @@ namespace MConnectSDK
if (enrollDate < DateTime.Now.AddSeconds(10))
{
answ.IsEnrolled = true;
reqStatus.isHmiEnrolled = true;
reqStatus.IsHmiEnrolled = true;
}
else
{
@@ -923,7 +930,7 @@ namespace MConnectSDK
bool processRequest = true;
var _currReq = reqStatus;
// fino a quanod NON è auth --> cicla...
while (!reqStatus.isAuth && processRequest)
while (!reqStatus.IsAuth && processRequest)
{
await Task.Run(() =>
{
@@ -938,7 +945,7 @@ namespace MConnectSDK
authData.Message += sb.ToString();
// verifico SE sia stato x autorizzato...
if (reqStatus.isAuth || authData.HasAuth)
if (reqStatus.IsAuth || authData.HasAuth)
{
sb.AppendLine("");
sb.AppendLine("SUCCESS 200: AUTH RECEIVED!");
@@ -986,21 +993,23 @@ namespace MConnectSDK
bool processRequest = true;
var _currReq = reqStatus;
// fino a quanod NON è auth --> cicla...
while (!reqStatus.isHmiEnrolled && processRequest)
while (!_currReq.IsHmiEnrolled && processRequest)
{
await Task.Run(() =>
{
authData = tryEnroll();
// recupero nuova reqStatus...
reqStatus = reqStatusUpd;
_currReq = reqStatusUpd;
// verifico SE sia stato registrato...
if (reqStatus.isHmiEnrolled || authData.IsEnrolled)
if (_currReq.IsHmiEnrolled || authData.IsEnrolled)
{
sb.AppendLine("");
sb.AppendLine(string.Format("{0:HH.mm.ss.fff} | ENROLL DONE", DateTime.Now));
authData.Message += sb.ToString();
processRequest = false;
_currReq.IsAuth = true;
_currReq.IsHmiEnrolled = true;
}
// verifico se richiesta cancellazione... CHIUDO!
+2 -2
View File
@@ -101,11 +101,11 @@ namespace MConnectSDK
/// <summary>
/// indica se l'applicazione abbia token di auth validi
/// </summary>
public bool isAuth = false;
public bool IsAuth = false;
/// <summary>
/// indica se l'HMI risulti già registrato (ENROLLED) su piattaforma
/// </summary>
public bool isHmiEnrolled = false;
public bool IsHmiEnrolled = false;
/// <summary>
/// Indica lo stato di disponibilità del CLOUD (= connesso)
/// </summary>
+2 -2
View File
@@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("Copyright © Steamware 2019")]
[assembly: AssemblyTrademark("_")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("1.0.1902.15")]
[assembly: AssemblyFileVersion("1.0.1902.15")]
[assembly: AssemblyVersion("1.0.1903.20")]
[assembly: AssemblyFileVersion("1.0.1903.20")]
+43 -30
View File
@@ -36,6 +36,7 @@
this.btnSetRetVal = new System.Windows.Forms.Button();
this.lblTokRet = new System.Windows.Forms.Label();
this.txtTokenRet = new System.Windows.Forms.TextBox();
this.chkTestMode = new System.Windows.Forms.CheckBox();
this.txtConfFile = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
@@ -58,7 +59,7 @@
this.pictBox = new System.Windows.Forms.PictureBox();
this.label6 = new System.Windows.Forms.Label();
this.lblConsole = new System.Windows.Forms.Label();
this.chkTestMode = new System.Windows.Forms.CheckBox();
this.btnGetClientStatus = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
@@ -75,7 +76,7 @@
this.lblClock});
this.statusStrip1.Location = new System.Drawing.Point(0, 685);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(1007, 25);
this.statusStrip1.Size = new System.Drawing.Size(1094, 25);
this.statusStrip1.TabIndex = 7;
this.statusStrip1.Text = "statusStrip1";
//
@@ -110,7 +111,7 @@
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Location = new System.Drawing.Point(13, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(982, 74);
this.groupBox1.Size = new System.Drawing.Size(1069, 74);
this.groupBox1.TabIndex = 11;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Connection Parameters";
@@ -142,6 +143,17 @@
this.txtTokenRet.TabIndex = 23;
this.txtTokenRet.Text = "403";
//
// chkTestMode
//
this.chkTestMode.AutoSize = true;
this.chkTestMode.Location = new System.Drawing.Point(435, 29);
this.chkTestMode.Name = "chkTestMode";
this.chkTestMode.Size = new System.Drawing.Size(97, 21);
this.chkTestMode.TabIndex = 13;
this.chkTestMode.Text = "Test Mode";
this.chkTestMode.UseVisualStyleBackColor = true;
this.chkTestMode.Click += new System.EventHandler(this.chkTestMode_Click);
//
// txtConfFile
//
this.txtConfFile.Location = new System.Drawing.Point(103, 30);
@@ -162,6 +174,7 @@
//
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox2.Controls.Add(this.btnGetClientStatus);
this.groupBox2.Controls.Add(this.label10);
this.groupBox2.Controls.Add(this.txtPwd);
this.groupBox2.Controls.Add(this.label9);
@@ -174,7 +187,7 @@
this.groupBox2.Controls.Add(this.btnResetParam);
this.groupBox2.Location = new System.Drawing.Point(13, 88);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(982, 100);
this.groupBox2.Size = new System.Drawing.Size(1069, 100);
this.groupBox2.TabIndex = 14;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Metodi";
@@ -182,7 +195,7 @@
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(822, 45);
this.label10.Location = new System.Drawing.Point(908, 45);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(33, 17);
this.label10.TabIndex = 23;
@@ -190,7 +203,7 @@
//
// txtPwd
//
this.txtPwd.Location = new System.Drawing.Point(874, 42);
this.txtPwd.Location = new System.Drawing.Point(960, 42);
this.txtPwd.Name = "txtPwd";
this.txtPwd.Size = new System.Drawing.Size(100, 22);
this.txtPwd.TabIndex = 22;
@@ -198,7 +211,7 @@
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(822, 16);
this.label9.Location = new System.Drawing.Point(908, 16);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(36, 17);
this.label9.TabIndex = 21;
@@ -206,14 +219,14 @@
//
// txtUser
//
this.txtUser.Location = new System.Drawing.Point(874, 13);
this.txtUser.Location = new System.Drawing.Point(960, 13);
this.txtUser.Name = "txtUser";
this.txtUser.Size = new System.Drawing.Size(100, 22);
this.txtUser.TabIndex = 20;
//
// btnTryUserLogin
//
this.btnTryUserLogin.Location = new System.Drawing.Point(825, 70);
this.btnTryUserLogin.Location = new System.Drawing.Point(911, 70);
this.btnTryUserLogin.Name = "btnTryUserLogin";
this.btnTryUserLogin.Size = new System.Drawing.Size(149, 27);
this.btnTryUserLogin.TabIndex = 19;
@@ -223,7 +236,7 @@
//
// btnGetUserList
//
this.btnGetUserList.Location = new System.Drawing.Point(674, 32);
this.btnGetUserList.Location = new System.Drawing.Point(760, 32);
this.btnGetUserList.Name = "btnGetUserList";
this.btnGetUserList.Size = new System.Drawing.Size(118, 49);
this.btnGetUserList.TabIndex = 18;
@@ -233,7 +246,7 @@
//
// btnGetOrgCode
//
this.btnGetOrgCode.Location = new System.Drawing.Point(550, 32);
this.btnGetOrgCode.Location = new System.Drawing.Point(636, 32);
this.btnGetOrgCode.Name = "btnGetOrgCode";
this.btnGetOrgCode.Size = new System.Drawing.Size(118, 49);
this.btnGetOrgCode.TabIndex = 17;
@@ -294,7 +307,7 @@
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(983, 491);
this.tableLayoutPanel1.Size = new System.Drawing.Size(1070, 491);
this.tableLayoutPanel1.TabIndex = 15;
//
// label1
@@ -309,7 +322,7 @@
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(199, 0);
this.label2.Location = new System.Drawing.Point(217, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(85, 17);
this.label2.TabIndex = 1;
@@ -318,7 +331,7 @@
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(395, 0);
this.label5.Location = new System.Drawing.Point(431, 0);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(64, 17);
this.label5.TabIndex = 2;
@@ -336,7 +349,7 @@
// lblRetData
//
this.lblRetData.AutoSize = true;
this.lblRetData.Location = new System.Drawing.Point(199, 53);
this.lblRetData.Location = new System.Drawing.Point(217, 53);
this.lblRetData.Name = "lblRetData";
this.lblRetData.Size = new System.Drawing.Size(20, 17);
this.lblRetData.TabIndex = 4;
@@ -345,16 +358,16 @@
// pictBox
//
this.pictBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictBox.Location = new System.Drawing.Point(395, 56);
this.pictBox.Location = new System.Drawing.Point(431, 56);
this.pictBox.Name = "pictBox";
this.pictBox.Size = new System.Drawing.Size(288, 432);
this.pictBox.Size = new System.Drawing.Size(315, 432);
this.pictBox.TabIndex = 5;
this.pictBox.TabStop = false;
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(689, 0);
this.label6.Location = new System.Drawing.Point(752, 0);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(38, 17);
this.label6.TabIndex = 6;
@@ -366,28 +379,27 @@
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, 53);
this.lblConsole.Location = new System.Drawing.Point(752, 53);
this.lblConsole.Name = "lblConsole";
this.lblConsole.Size = new System.Drawing.Size(291, 438);
this.lblConsole.Size = new System.Drawing.Size(315, 438);
this.lblConsole.TabIndex = 7;
this.lblConsole.Text = "...";
//
// chkTestMode
// btnGetClientStatus
//
this.chkTestMode.AutoSize = true;
this.chkTestMode.Location = new System.Drawing.Point(435, 29);
this.chkTestMode.Name = "chkTestMode";
this.chkTestMode.Size = new System.Drawing.Size(97, 21);
this.chkTestMode.TabIndex = 13;
this.chkTestMode.Text = "Test Mode";
this.chkTestMode.UseVisualStyleBackColor = true;
this.chkTestMode.Click += new System.EventHandler(this.chkTestMode_Click);
this.btnGetClientStatus.Location = new System.Drawing.Point(512, 32);
this.btnGetClientStatus.Name = "btnGetClientStatus";
this.btnGetClientStatus.Size = new System.Drawing.Size(118, 49);
this.btnGetClientStatus.TabIndex = 24;
this.btnGetClientStatus.Text = "getClientStatus";
this.btnGetClientStatus.UseVisualStyleBackColor = true;
this.btnGetClientStatus.Click += new System.EventHandler(this.btnGetClientStatus_Click);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1007, 710);
this.ClientSize = new System.Drawing.Size(1094, 710);
this.Controls.Add(this.tableLayoutPanel1);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
@@ -440,6 +452,7 @@
private System.Windows.Forms.Label label9;
private System.Windows.Forms.TextBox txtUser;
private System.Windows.Forms.CheckBox chkTestMode;
private System.Windows.Forms.Button btnGetClientStatus;
}
}
+58 -8
View File
@@ -119,11 +119,13 @@ namespace TestClient
sb.AppendLine("-------------------------");
if (reqStatus != null)
{
sb.AppendLine("isAuth: " + reqStatus.isAuth);
sb.AppendLine("isHmiEnrolled: " + reqStatus.isHmiEnrolled);
sb.AppendLine("isAuth: " + reqStatus.IsAuth);
sb.AppendLine("isHmiEnrolled: " + reqStatus.IsHmiEnrolled);
sb.AppendLine("cloudConnection: " + reqStatus.CloudStatusOk);
sb.AppendLine("localConnection: " + reqStatus.LocalStatusOk);
sb.AppendLine("callSuccess: " + reqStatus.CallResultOk);
sb.AppendLine("");
sb.AppendLine(string.Format("{0:HH.mm.ss.fff}", DateTime.Now));
sb.AppendLine("-------------------------");
}
lblReqStatus.Text = sb.ToString();
@@ -135,7 +137,7 @@ namespace TestClient
if (reqStatus != null)
{
// se NON enrolled --> abilita tryAuth...
btnTryAuth.Enabled = !reqStatus.isHmiEnrolled;
btnTryAuth.Enabled = !reqStatus.IsHmiEnrolled;
}
}
@@ -148,11 +150,11 @@ namespace TestClient
// aggiorno console...
lblConsole.Text = authData.Message;
// verifico se sia AUTH (altrimenti NON mostro codice e QR...)
if (authData.HasAuth || reqStatus.isAuth)
if (authData.HasAuth || reqStatus.IsAuth)
{
var currColor = Color.Orange;
// se fosse ANCHE enrolled cambio colore...
if (authData.IsEnrolled || reqStatus.isHmiEnrolled)
if (authData.IsEnrolled || reqStatus.IsHmiEnrolled)
{
currColor = Color.Green;
}
@@ -168,7 +170,7 @@ namespace TestClient
pictBox.Image = bitmap;
StringBuilder sb = new StringBuilder();
sb.AppendLine("AUTH DONE!");
if (authData.IsEnrolled || reqStatus.isHmiEnrolled)
if (authData.IsEnrolled || reqStatus.IsHmiEnrolled)
{
sb.AppendLine("------");
sb.AppendLine("ENROLLED!");
@@ -225,10 +227,10 @@ namespace TestClient
await Task.Run(() =>
{
// NUOVA istanza da file di conf...
MCC = new MConnectClient(confFilePath);
MCC = new MConnectClient();
// init async...
var taskResult = MCC.initSDKAsync(CancellationToken.None);
var taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
// ora leggo lo status...
taskResult = MCC.GetClientStatusAsync();
@@ -267,6 +269,24 @@ namespace TestClient
});
}
/// <summary>
/// Recupero client status
/// </summary>
/// <returns></returns>
private async Task getClientStatus()
{
await Task.Run(() =>
{
var taskResult = MCC.GetClientStatusAsync();
// salvo il risultato restituito...
reqStatus = taskResult.Result;
synchronizationContext.Post(new SendOrPostCallback(o =>
{
refreshRequestStatus();
}), "");
});
}
/// <summary>
/// Recupero UserList
/// </summary>
/// <returns></returns>
@@ -362,6 +382,9 @@ namespace TestClient
chkTestMode.Checked = true;
txtConfFile.Text = "mconnect.conf.yaml";
txtTokenRet.Text = "403";
reqStatus = new Result();
lblReqStatus.Text = "";
lblConsole.Text = "";
fixDisplay();
}
/// <summary>
@@ -428,6 +451,9 @@ namespace TestClient
// gestione progress...
var progressHandler = new Progress<Result>(value =>
{
// aggiorno richeista live...
reqStatus = value;
refreshRequestStatus();
// mostro i dati SPECIFICI x AUTH...
updateAuthData((ActivationPayload)value.Payload);
});
@@ -441,6 +467,15 @@ namespace TestClient
var initObj = MCC.TryActivationAsync(token, progress);
// ora processo attivazione
initObj = MCC.EnrollMachineAsync(token, progress);
// recupero dati e aggiorno display...
var taskResult = MCC.GetClientStatusAsync();
// salvo il risultato restituito...
reqStatus = taskResult.Result;
// aggiorno display
synchronizationContext.Post(new SendOrPostCallback(o =>
{
refreshRequestStatus();
}), "");
});
}
catch (OperationCanceledException)
@@ -525,5 +560,20 @@ namespace TestClient
#endregion
private async void btnGetClientStatus_Click(object sender, EventArgs e)
{
// init in modalità Task based...
await Task.Run(() =>
{
var retObj = getClientStatus();
});
// aggiorno log console
StringBuilder sb = new StringBuilder();
sb.AppendLine("--------------------------------------------------");
sb.AppendLine(string.Format("{0:HH.mm.ss.fff} | ClientStatus requested", DateTime.Now));
sb.AppendLine("");
lblConsole.Text = sb.ToString();
}
}
}