From a62bfcc0c10e0483014ef6cdb2f50e89467f90dd Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Thu, 28 Feb 2019 16:40:05 +0100 Subject: [PATCH] Affinata SIM prima aprte --- MConnectSDK/MConnectClient.cs | 25 +++++++++++++++++++++---- TestClient/MainForm.cs | 7 ++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/MConnectSDK/MConnectClient.cs b/MConnectSDK/MConnectClient.cs index ff43aa0..bd574a5 100644 --- a/MConnectSDK/MConnectClient.cs +++ b/MConnectSDK/MConnectClient.cs @@ -193,7 +193,10 @@ namespace MConnectSDK userAuthData answ = new userAuthData(); // init altro requestStatus reqSt = preCheckStatus(); - tokResp = new tokenResponse(); + if (tokResp == null) + { + tokResp = new tokenResponse(); + } // verifico autorizzazione... se non c'รจ TENTO auth... if (!reqSt.isHmiEnrolled) { @@ -203,14 +206,28 @@ namespace MConnectSDK // verifico chiamata server... if (_currParam.testMode) { - Random r = new Random(); + int user_code = 0; + // verifico SE CI SIA in redis il valore dell'user_code ed uso quello, altrimenti genero e lascio su redis... + if (redServAlive) + { + var szUserCode = ML.getRSV(ML.redHash("SIM:USER_CODE")); + int.TryParse(szUserCode, out user_code); + } + // se non trovato... + if (user_code <= 0) + { + Random r = new Random(); + user_code = r.Next(1, 999999); + // salvo!!! + ML.setRSV(ML.redHash("SIM:USER_CODE"), user_code.ToString(), 5); + } tokResp = new tokenResponse() { device_code = "TEST-DEV", - user_code = string.Format("{0:000000}", r.Next(1, 999999)), + user_code = string.Format("{0:000000}", user_code), verification_uri = "localhost:3000/client-auth/verification", - interval = 1000, + interval = 100, expires_in = 60000 }; } diff --git a/TestClient/MainForm.cs b/TestClient/MainForm.cs index 177bad2..fb3ede8 100644 --- a/TestClient/MainForm.cs +++ b/TestClient/MainForm.cs @@ -205,7 +205,7 @@ namespace TestClient } else { - Thread.Sleep(500); + Thread.Sleep(1000); } }); } @@ -217,8 +217,9 @@ namespace TestClient private void updateAuthData(userAuthData authData) { StringBuilder sb = new StringBuilder(); - sb.AppendLine("--------------------------------------------------"); - sb.AppendLine(string.Format("user_code: {0}", authData.userCode)); + //sb.AppendLine("--------------------------------------------------"); + sb.AppendLine("user_code:"); + sb.AppendLine(authData.userCode.ToString()); sb.AppendLine(""); lblRetData.Text = sb.ToString(); // mostro QR-code