From d5da75b0661e925aefd3a6cea6743756bec9e325 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Tue, 16 Apr 2019 10:46:56 +0200 Subject: [PATCH] Update x problemi timeout download immagini con getUserList --- MConnectSDK/MConnectClient.cs | 92 ++++++++++++++++++++++++--------- MConnectSDK/Utils.cs | 48 ++++++++++++++++- SharedAssemblyInfo.cs | 4 +- TestClient/MainForm.Designer.cs | 39 +++++++++----- TestClient/MainForm.cs | 2 +- 5 files changed, 145 insertions(+), 40 deletions(-) diff --git a/MConnectSDK/MConnectClient.cs b/MConnectSDK/MConnectClient.cs index 56a2a25..1dbbe8c 100644 --- a/MConnectSDK/MConnectClient.cs +++ b/MConnectSDK/MConnectClient.cs @@ -328,10 +328,14 @@ namespace MConnectSDK } catch { } + // bonifico eventuali null... + answ.RemoveAll(item => item == null); return answ; } set { + value.RemoveAll(item => item == null); + value.Sort(); string serVal = JsonConvert.SerializeObject(value); ML.setRSV(ML.redHash("UserListCache"), serVal); } @@ -1035,29 +1039,8 @@ namespace MConnectSDK Image userImg = null; UserStatus currStatus = UserStatus.NOT_IMPORTED; // recupero effettivi dati utente e restituisco... - Parallel.ForEach(resp.result, item => + foreach (var item in resp.result) { - // se richiesto aggiungo immagine... - if (getImages) - { - userImg = null; - try - { - // creo obj userData... SE HO immagine... - if (item.Image_Url != "") - { - var imgRes = Task.Run(() => Utils.getImageAsync(pageUrlImgDownload, item.Image_Url)); - imgRes.Wait(); - if (imgRes.Result != null) - { - userImg = imgRes.Result; - } - } - } - catch - { - } - } // verifica SE FOSSE GIA' esistente --> tengo STATUS... resFilt = userListOld.FindAll(X => X.Username == item.Username); if (resFilt.Count > 0) @@ -1085,7 +1068,8 @@ namespace MConnectSDK UserImage = userImg }; answ.Add(_newUser); - }); + } + // se ne avessi ricevuti (da cloud) meno di quanti ne avevo --> cerco DELETED... if (numFound != numImp) { @@ -1111,6 +1095,68 @@ namespace MConnectSDK } } } + + // se richiesto aggiungo immagine... + if (getImages) + { + // in modalità parallela TENTO scaricamento imagini... + Parallel.ForEach(resp.result, item => + { + userImg = null; + try + { + // creo obj userData... SE HO immagine... + if (item.Image_Url != "") + { + var imgRes = Task.Run(() => Utils.getImageAsync(pageUrlImgDownload, item.Image_Url)); + imgRes.Wait(); + if (imgRes.Result != null) + { + userImg = imgRes.Result; + } + } + } + catch + { + } + resFilt = answ.FindAll(X => X.Username == item.Username); + if (resFilt.Count == 1) + { + resFilt[0].UserImage = userImg; + } + +#if false + // verifica SE FOSSE GIA' esistente --> tengo STATUS... + resFilt = userListOld.FindAll(X => X.Username == item.Username); + if (resFilt.Count > 0) + { + currStatus = resFilt[0].LoginStatus; + if (currStatus == UserStatus.IMPORTED) + { + numFound++; + } + } + else + { + currStatus = UserStatus.NOT_IMPORTED; + } + // creo utente + _newUser = new UserData + { + UserId = item.Id, + IsAdmin = item.IsAdmin, + Username = item.Username, + Email = item.Email, + Cognome = item.Lastname, + Nome = item.Firstname, + LoginStatus = currStatus, + UserImage = userImg + }; + answ.Add(_newUser); +#endif + }); + } + return answ; } diff --git a/MConnectSDK/Utils.cs b/MConnectSDK/Utils.cs index 863d267..20e05da 100644 --- a/MConnectSDK/Utils.cs +++ b/MConnectSDK/Utils.cs @@ -709,6 +709,51 @@ namespace MConnectSDK public string link { get; set; } = ""; public string expiry { get; set; } = ""; } + /// + /// Classe ordinabile x UserData + /// + public class UserData : IComparable + { + /// + /// Codice utente (es asfd.0002) + /// + public string UserId = ""; + /// + /// Indica se sia ADMIN + /// + public bool IsAdmin = false; + /// + /// Indica lo stsatus dell'utente + /// + public UserStatus LoginStatus = UserStatus.NOT_IMPORTED; + /// + /// UserName (univoco) + /// + public string Username = ""; + /// + /// Email + /// + public string Email = ""; + /// + /// Cognome + /// + public string Cognome = ""; + /// + /// Nome + /// + public string Nome = ""; + /// + /// Immagine utente + /// + [JsonConverter(typeof(ImageConverter))] + public Image UserImage = null; + public int CompareTo(UserData other) + { + return this.UserId.CompareTo(other.UserId); + } + + } +#if false /// /// Classe info UTENTE /// @@ -747,7 +792,8 @@ namespace MConnectSDK /// [JsonConverter(typeof(ImageConverter))] public Image UserImage = null; - } + } +#endif /// /// Classe info UTENTE + pwd (cifrata...) x cache localedi login /// diff --git a/SharedAssemblyInfo.cs b/SharedAssemblyInfo.cs index 08b7c73..b5e5d02 100644 --- a/SharedAssemblyInfo.cs +++ b/SharedAssemblyInfo.cs @@ -8,5 +8,5 @@ using System.Runtime.InteropServices; [assembly: AssemblyCopyright("Copyright © Steamware 2019")] [assembly: AssemblyTrademark("_")] [assembly: ComVisible(false)] -[assembly: AssemblyVersion("1.1.1904.81")] -[assembly: AssemblyFileVersion("1.1.1904.81")] +[assembly: AssemblyVersion("1.1.1904.83")] +[assembly: AssemblyFileVersion("1.1.1904.83")] diff --git a/TestClient/MainForm.Designer.cs b/TestClient/MainForm.Designer.cs index 0f21ab9..e571075 100644 --- a/TestClient/MainForm.Designer.cs +++ b/TestClient/MainForm.Designer.cs @@ -33,6 +33,7 @@ this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar(); this.lblClock = new System.Windows.Forms.ToolStripStatusLabel(); this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.btnFakeQR = new System.Windows.Forms.Button(); this.txtUploadFile = new System.Windows.Forms.TextBox(); this.btnUploadFile = new System.Windows.Forms.Button(); this.lblUserCode = new System.Windows.Forms.Label(); @@ -65,7 +66,7 @@ this.pictBox = new System.Windows.Forms.PictureBox(); this.label6 = new System.Windows.Forms.Label(); this.lblConsole = new System.Windows.Forms.Label(); - this.btnFakeQR = new System.Windows.Forms.Button(); + this.chkGetImg = new System.Windows.Forms.CheckBox(); this.statusStrip1.SuspendLayout(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); @@ -122,6 +123,16 @@ this.groupBox1.TabStop = false; this.groupBox1.Text = "Connection Parameters"; // + // btnFakeQR + // + this.btnFakeQR.Location = new System.Drawing.Point(932, 23); + this.btnFakeQR.Name = "btnFakeQR"; + this.btnFakeQR.Size = new System.Drawing.Size(111, 32); + this.btnFakeQR.TabIndex = 33; + this.btnFakeQR.Text = "fake QR"; + this.btnFakeQR.UseVisualStyleBackColor = true; + this.btnFakeQR.Click += new System.EventHandler(this.btnFakeQR_Click); + // // txtUploadFile // this.txtUploadFile.Location = new System.Drawing.Point(454, 28); @@ -171,6 +182,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.chkGetImg); this.groupBox2.Controls.Add(this.btnTryEnroll); this.groupBox2.Controls.Add(this.btnDeleteUserCloud); this.groupBox2.Controls.Add(this.btnDeleteUserHMI); @@ -237,7 +249,7 @@ // // btnGetUserCreatedList // - this.btnGetUserCreatedList.Location = new System.Drawing.Point(519, 59); + this.btnGetUserCreatedList.Location = new System.Drawing.Point(506, 59); this.btnGetUserCreatedList.Name = "btnGetUserCreatedList"; this.btnGetUserCreatedList.Size = new System.Drawing.Size(132, 32); this.btnGetUserCreatedList.TabIndex = 26; @@ -268,7 +280,7 @@ // label10 // this.label10.AutoSize = true; - this.label10.Location = new System.Drawing.Point(669, 67); + this.label10.Location = new System.Drawing.Point(684, 67); this.label10.Name = "label10"; this.label10.Size = new System.Drawing.Size(33, 17); this.label10.TabIndex = 23; @@ -284,7 +296,7 @@ // label9 // this.label9.AutoSize = true; - this.label9.Location = new System.Drawing.Point(669, 29); + this.label9.Location = new System.Drawing.Point(684, 29); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(36, 17); this.label9.TabIndex = 21; @@ -310,7 +322,7 @@ // // btnGetUserList // - this.btnGetUserList.Location = new System.Drawing.Point(519, 21); + this.btnGetUserList.Location = new System.Drawing.Point(506, 21); this.btnGetUserList.Name = "btnGetUserList"; this.btnGetUserList.Size = new System.Drawing.Size(132, 32); this.btnGetUserList.TabIndex = 18; @@ -459,15 +471,15 @@ this.lblConsole.TabIndex = 7; this.lblConsole.Text = "..."; // - // btnFakeQR + // chkGetImg // - this.btnFakeQR.Location = new System.Drawing.Point(932, 23); - this.btnFakeQR.Name = "btnFakeQR"; - this.btnFakeQR.Size = new System.Drawing.Size(111, 32); - this.btnFakeQR.TabIndex = 33; - this.btnFakeQR.Text = "fake QR"; - this.btnFakeQR.UseVisualStyleBackColor = true; - this.btnFakeQR.Click += new System.EventHandler(this.btnFakeQR_Click); + this.chkGetImg.AutoSize = true; + this.chkGetImg.Location = new System.Drawing.Point(645, 29); + this.chkGetImg.Name = "chkGetImg"; + this.chkGetImg.Size = new System.Drawing.Size(52, 21); + this.chkGetImg.TabIndex = 31; + this.chkGetImg.Text = "img"; + this.chkGetImg.UseVisualStyleBackColor = true; // // MainForm // @@ -533,6 +545,7 @@ private System.Windows.Forms.Button btnUploadFile; private System.Windows.Forms.TextBox txtUploadFile; private System.Windows.Forms.Button btnFakeQR; + private System.Windows.Forms.CheckBox chkGetImg; } } diff --git a/TestClient/MainForm.cs b/TestClient/MainForm.cs index 31d0ce2..3c73826 100644 --- a/TestClient/MainForm.cs +++ b/TestClient/MainForm.cs @@ -341,7 +341,7 @@ namespace TestClient { await Task.Run(() => { - var userResult = MCC.getUserListAsync(true); + var userResult = MCC.getUserListAsync(chkGetImg.Checked); List userList = ((UserPayload)userResult.Result.Payload).UserList; synchronizationContext.Post(new SendOrPostCallback(o =>