From e4a96abd8f45af84a7b099321be8018e82c413df Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sat, 6 Nov 2021 12:44:49 +0100 Subject: [PATCH] refresh metodi recupero info licenze --- .../WebUserControls/mod_adminDipendenti.ascx | 22 ++--- .../mod_adminDipendenti.ascx.cs | 4 +- GPW_Data/licenzeGPW.cs | 88 ++++++++++++++++++- 3 files changed, 99 insertions(+), 15 deletions(-) diff --git a/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx b/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx index 3cd8626..d722ffb 100644 --- a/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx +++ b/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx @@ -7,18 +7,20 @@
-
- Licenze locali: disponibili <%: numLicenze %> / attivate <%: utentiAttivi %> +
+
+ Licenze locali: disponibili <%: numLicenze %> / attivate <%: utentiAttivi %> + +
+
+ Licenze online: disponibili <%: numLicenzeOnline %> / attivate <%: attivazioniOnline %> + +
+
+ Re-Validate +
-
-
- 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 3e271a0..4d73113 100644 --- a/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.cs +++ b/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.cs @@ -174,7 +174,9 @@ namespace GPW_Admin.WebUserControls protected void lbtRefresh_Click(object sender, EventArgs e) { // eseguo call di recupero da online - bool fatto = licenzeGPW.CheckOnline().Result; + bool refreshAct = licenzeGPW.RefreshActInfo().Result; + bool refreshApp = licenzeGPW.RefreshAppInfo().Result; + bool refreshLic = licenzeGPW.RefreshLicInfo().Result; } /// diff --git a/GPW_Data/licenzeGPW.cs b/GPW_Data/licenzeGPW.cs index 1d647c2..4d29649 100644 --- a/GPW_Data/licenzeGPW.cs +++ b/GPW_Data/licenzeGPW.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; +using System.Web; namespace GPW_data { @@ -13,7 +14,12 @@ namespace GPW_data { #region Protected Fields + //protected static string apiUrl = "https://localhost:44351/"; + protected static string actInfoKey = memLayer.ML.redHash($"LiMan:ActInfo"); + + protected static string apiUrl = "https://iis01.egalware.com/ELM.API/"; protected static string appInfoKey = memLayer.ML.redHash($"LiMan:AppInfo"); + protected static string licInfoKey = memLayer.ML.redHash($"LiMan:LicInfo"); #endregion Protected Fields @@ -122,7 +128,7 @@ namespace GPW_data // se no ci fosse --> refresh online! if (string.IsNullOrEmpty(rawData)) { - var fatto = CheckOnline().Result; + var fatto = RefreshAppInfo().Result; if (fatto) { rawData = memLayer.ML.getRSV(appInfoKey); @@ -213,6 +219,26 @@ namespace GPW_data } } + /// + /// Chaive Licenza Master + /// + public static string MasterKey + { + get + { + string answ = ""; + try + { + answ = DataProxy.DP.taAKV.getByKey(installazione)[0].valString; + } + catch (Exception exc) + { + logger.lg.scriviLog(string.Format("Errore recupero chiave MasterKey da AKV: {0}", exc), tipoLog.EXCEPTION); + } + return answ; + } + } + /// /// modalità applicazione (pagina test.aspx) /// @@ -261,11 +287,39 @@ namespace GPW_data #region Public Methods - public static async Task CheckOnline() + /// + /// Effettua refresh ActivationInfo con chiamata remota (sovrascrivendo info locali Redis) + /// + /// + public static async Task RefreshActInfo() + { + bool answ = false; + + // cerco online + RestClient client = new RestClient(apiUrl); + //client.Authenticator = new HttpBasicAuthenticator("username", "password"); + string MKeyEnc = HttpUtility.UrlEncode(MasterKey); + var request = new RestRequest($"/api/attivazioni/?chiave={MKeyEnc}", 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(actInfoKey, rawData, 60 * 60 * 24 * 7); + } + return await Task.FromResult(answ); + } + + /// + /// Effettua refresh AppInfo con chiamata remota (sovrascrivendo info locali Redis) + /// + /// + public static async Task RefreshAppInfo() { bool answ = false; - string apiUrl = "https://localhost:44351/"; - //string apiUrl= "https://iis01.egalware.com/ELM.API/"; // cerco online RestClient client = new RestClient(apiUrl); @@ -284,6 +338,32 @@ namespace GPW_data return await Task.FromResult(answ); } + /// + /// Effettua refresh LicenseInfo con chiamata remota (sovrascrivendo info locali Redis) + /// + /// + public static async Task RefreshLicInfo() + { + bool answ = false; + + // cerco online + RestClient client = new RestClient(apiUrl); + //client.Authenticator = new HttpBasicAuthenticator("username", "password"); + string MKeyEnc = HttpUtility.UrlEncode(MasterKey); + var request = new RestRequest($"/api/licenza/{installazione}?CodApp={applicazione}&Chiave={MKeyEnc}", 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(licInfoKey, rawData, 60 * 60 * 24 * 7); + } + return await Task.FromResult(answ); + } + #endregion Public Methods } } \ No newline at end of file