From f662e5a3e1690db4e7a3782810bd2f9826ed8fcb Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sat, 6 Nov 2021 11:39:25 +0100 Subject: [PATCH] Iniziata integrazioen licenze con chiamate RestSharp --- .../WebUserControls/mod_adminDipendenti.ascx | 12 ++- .../mod_adminDipendenti.ascx.cs | 16 ++++ .../mod_adminDipendenti.ascx.designer.cs | 27 ++++++ GPW_Admin/WebUserControls/mod_login.ascx.cs | 15 ++- GPW_Data/ObjLicenze.cs | 88 ++++++++++++++++++ GPW_Data/licenzeGPW.cs | 93 +++++++++++++++++++ GPW_Data/packages.config | 1 + GPW_data/GPW_data.csproj | 4 + 8 files changed, 250 insertions(+), 6 deletions(-) create mode 100644 GPW_Data/ObjLicenze.cs diff --git a/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx b/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx index 2f98497..3cd8626 100644 --- a/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx +++ b/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx @@ -7,7 +7,17 @@
- Licenze: disponibili <%: numLicenze %> / attivate <%: utentiAttivi %> +
+ Licenze locali: disponibili <%: numLicenze %> / attivate <%: utentiAttivi %> +
+
+
+
+ Licenze online: disponibili <%: numLicenzeOnline %> / attivate <%: attivazioniOnline %> +
+
+
+ Re-Validate
diff --git a/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.cs b/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.cs index d896c97..3e271a0 100644 --- a/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.cs +++ b/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.cs @@ -14,6 +14,11 @@ namespace GPW_Admin.WebUserControls { #region Public Properties + public int attivazioniOnline + { + get => licenzeGPW.attivazioniOnline; + } + public int IdxDipSel { get @@ -33,6 +38,11 @@ namespace GPW_Admin.WebUserControls get => licenzeGPW.licenzeAttive; } + public int numLicenzeOnline + { + get => licenzeGPW.licenzeOnline; + } + public bool showAll { get @@ -161,6 +171,12 @@ namespace GPW_Admin.WebUserControls ods.Insert(); } + protected void lbtRefresh_Click(object sender, EventArgs e) + { + // eseguo call di recupero da online + bool fatto = licenzeGPW.CheckOnline().Result; + } + /// /// check licenze in fase di update... /// diff --git a/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.designer.cs b/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.designer.cs index 0a3f91e..5a77e8d 100644 --- a/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.designer.cs +++ b/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.designer.cs @@ -14,6 +14,33 @@ namespace GPW_Admin.WebUserControls public partial class mod_adminDipendenti { + /// + /// divDB control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.HtmlControls.HtmlGenericControl divDB; + + /// + /// divOnline control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.HtmlControls.HtmlGenericControl divOnline; + + /// + /// lbtRefresh control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.LinkButton lbtRefresh; + /// /// chkshowAll control. /// diff --git a/GPW_Admin/WebUserControls/mod_login.ascx.cs b/GPW_Admin/WebUserControls/mod_login.ascx.cs index 9b50e51..661be6c 100644 --- a/GPW_Admin/WebUserControls/mod_login.ascx.cs +++ b/GPW_Admin/WebUserControls/mod_login.ascx.cs @@ -34,11 +34,16 @@ public partial class mod_login : ApplicationUserControl protected override void traduciObj() { - lblPwd.Text = user_std.UtSn.Traduci("lblPwd"); - lblUser.Text = user_std.UtSn.Traduci("lblUser"); - lblDominio.Text = user_std.UtSn.Traduci("lblDominio"); - lblTitolo.Text = user_std.UtSn.Traduci("ForzaUtente"); - btnOk.Text = user_std.UtSn.Traduci("btnCommit"); + try + { + lblPwd.Text = user_std.UtSn.Traduci("lblPwd"); + lblUser.Text = user_std.UtSn.Traduci("lblUser"); + lblDominio.Text = user_std.UtSn.Traduci("lblDominio"); + lblTitolo.Text = user_std.UtSn.Traduci("ForzaUtente"); + btnOk.Text = user_std.UtSn.Traduci("btnCommit"); + } + catch + { } } /// diff --git a/GPW_Data/ObjLicenze.cs b/GPW_Data/ObjLicenze.cs new file mode 100644 index 0000000..07fdf9e --- /dev/null +++ b/GPW_Data/ObjLicenze.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GPW_data +{ + public class LiManObj + { + #region Public Enums + + public enum TipoLicenza + { + ND = 0, + + /// + /// Licenza LEgacy Steamware + /// + GLS, + + /// + /// Master Key License, che ha una data di scadenza globale ed un token = numero di utenti/token massimi associati + /// + MasterKey, + + /// + /// UserKey License (licenza che consuma un token utente della licenza master) - es GPW + /// + UserKey, + + /// + /// Chiave tiupo Checksum basata su licenza masster + checksum MD5 di una serie di dati (child licenses) + /// + CheckSumKey + } + + #endregion Public Enums + + #region Public Classes + + public class ApplicativoDTO + { + #region Public Properties + + public string Chiave { get; set; } = ""; + public string CodApp { get; set; } = ""; + public string CodInst { get; set; } = ""; + public DateTime DataEnigma { get; set; } = DateTime.Today.AddYears(-1); + public string Descrizione { get; set; } = ""; + public string Enigma { get; set; } = ""; + public int IdxLic { get; set; } = 0; + + public bool IsActive + { + get => (Scadenza.Subtract(DateTime.Today).TotalDays > 0); + } + + public bool Locked { get; set; } = false; + public int NumLicenze { get; set; } = 0; + public int NumLicenzeAttive { get; set; } = 0; + public string Payload { get; set; } = ""; + public DateTime Scadenza { get; set; } = DateTime.Today.AddYears(-1); + public TipoLicenza Tipo { get; set; } = TipoLicenza.ND; + + #endregion Public Properties + } + + public class AttivazioneDTO + { + #region Public Properties + + public string Chiave { get; set; } = ""; + public string CodApp { get; set; } = ""; + public string CodImpiego { get; set; } = ""; + public string CodInst { get; set; } = ""; + public string Descrizione { get; set; } = ""; + public int IdxLic { get; set; } = 0; + public int IdxSubLic { get; set; } = 0; + public TipoLicenza Tipo { get; set; } = TipoLicenza.UserKey; + public DateTime VetoUnlock { get; set; } = DateTime.Today.AddMonths(2); + + #endregion Public Properties + } + + #endregion Public Classes + } +} \ No newline at end of file diff --git a/GPW_Data/licenzeGPW.cs b/GPW_Data/licenzeGPW.cs index 674b912..1d647c2 100644 --- a/GPW_Data/licenzeGPW.cs +++ b/GPW_Data/licenzeGPW.cs @@ -1,10 +1,22 @@ using SteamWare; using System; +using RestSharp; +using RestSharp.Authenticators; +using System.Threading.Tasks; +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Linq; namespace GPW_data { public class licenzeGPW { + #region Protected Fields + + protected static string appInfoKey = memLayer.ML.redHash($"LiMan:AppInfo"); + + #endregion Protected Fields + #region Public Properties /// @@ -19,6 +31,17 @@ namespace GPW_data } } + /// + /// numero di licenze attive da info online + /// + public static int attivazioniOnline + { + get + { + return InfoApplicativo.NumLicenzeAttive; + } + } + /// /// chaive licenza /// @@ -86,6 +109,38 @@ namespace GPW_data } } + /// + /// Info applicativo corrente (da cache con eventuale recupero online...) + /// + public static LiManObj.ApplicativoDTO InfoApplicativo + { + get + { + LiManObj.ApplicativoDTO answ = new LiManObj.ApplicativoDTO(); + // cerco da cache + string rawData = memLayer.ML.getRSV(appInfoKey); + // se no ci fosse --> refresh online! + if (string.IsNullOrEmpty(rawData)) + { + var fatto = CheckOnline().Result; + if (fatto) + { + rawData = memLayer.ML.getRSV(appInfoKey); + } + } + if (!string.IsNullOrEmpty(rawData)) + { + // POTREBBE darmi + di 1 risultato, prendo + recente... + List infoList = JsonConvert.DeserializeObject>(rawData); + if (infoList != null) + { + answ = infoList.OrderByDescending(x => x.Scadenza).FirstOrDefault(); + } + } + return answ; + } + } + /// /// nome installazione sw /// @@ -147,6 +202,17 @@ namespace GPW_data } } + /// + /// numero di licenze disponibili da info online + /// + public static int licenzeOnline + { + get + { + return InfoApplicativo.NumLicenze; + } + } + /// /// modalità applicazione (pagina test.aspx) /// @@ -192,5 +258,32 @@ namespace GPW_data } #endregion Public Properties + + #region Public Methods + + public static async Task CheckOnline() + { + bool answ = false; + string apiUrl = "https://localhost:44351/"; + //string apiUrl= "https://iis01.egalware.com/ELM.API/"; + + // cerco online + RestClient client = new RestClient(apiUrl); + //client.Authenticator = new HttpBasicAuthenticator("username", "password"); + var request = new RestRequest($"/api/applicazione/{installazione}?CodApp={applicazione}", DataFormat.Json); + var response = client.Get(request); + // controllo risposta + if (response.StatusCode == System.Net.HttpStatusCode.OK) + { + answ = true; + // salvo in redis contenuto serializzato + string rawData = response.Content; + // salvo in redis per 7 gg + memLayer.ML.setRSV(appInfoKey, rawData, 60 * 60 * 24 * 7); + } + return await Task.FromResult(answ); + } + + #endregion Public Methods } } \ No newline at end of file diff --git a/GPW_Data/packages.config b/GPW_Data/packages.config index 3b45909..856a37b 100644 --- a/GPW_Data/packages.config +++ b/GPW_Data/packages.config @@ -15,6 +15,7 @@ + diff --git a/GPW_data/GPW_data.csproj b/GPW_data/GPW_data.csproj index 8c355ff..448815d 100644 --- a/GPW_data/GPW_data.csproj +++ b/GPW_data/GPW_data.csproj @@ -85,6 +85,9 @@ ..\packages\Pipelines.Sockets.Unofficial.2.2.0\lib\net461\Pipelines.Sockets.Unofficial.dll True + + ..\packages\RestSharp.106.13.0\lib\net452\RestSharp.dll + ..\packages\SharpCompress.0.28.1\lib\netstandard2.0\SharpCompress.dll @@ -207,6 +210,7 @@ + True