From 77cb1efc2aeafbb4d42ff027586fffb5a02a14b6 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 22 Aug 2024 18:26:21 +0200 Subject: [PATCH] Completata review gestione chiave e sua scadenza --- .../Components/Compo/CmpTop.razor.cs | 9 +- GPW.CORE.SMART/Components/Pages/About.razor | 19 ++++ .../Components/Pages/About.razor.cs | 35 +++++- GPW.CORE.SMART/Components/Pages/Info.razor | 16 --- GPW.CORE.SMART/Data/LicenseService.cs | 106 ++++++++++++++++++ GPW.CORE6.Smart/GPW.CORE6.SMART.csproj | 2 +- Resources/ChangeLog.html | 2 +- Resources/VersNum.txt | 2 +- Resources/manifest.xml | 2 +- 9 files changed, 168 insertions(+), 25 deletions(-) delete mode 100644 GPW.CORE.SMART/Components/Pages/Info.razor diff --git a/GPW.CORE.SMART/Components/Compo/CmpTop.razor.cs b/GPW.CORE.SMART/Components/Compo/CmpTop.razor.cs index ed76d67..7541669 100644 --- a/GPW.CORE.SMART/Components/Compo/CmpTop.razor.cs +++ b/GPW.CORE.SMART/Components/Compo/CmpTop.razor.cs @@ -65,6 +65,11 @@ namespace GPW.CORE.Smart.Components.Compo // chiamo refresh licenze da remoto allOk = await LicServ.RefreshLicense(); } + // se non avesse info applicativo... + if(!LicServ.HasAppData) + { + await LicServ.RefreshApplic(); + } } await Task.Delay(1); @@ -178,10 +183,6 @@ namespace GPW.CORE.Smart.Components.Compo await CDService.FlushRedisCache(); // ritorno in home navManager.NavigateTo("Home", true); - - //await Task.Delay(1); - //await DoVerifyActiv(); - //navManager.NavigateTo($"ForceReset?nextPage=Home", true); } protected async Task VerifyActiv() diff --git a/GPW.CORE.SMART/Components/Pages/About.razor b/GPW.CORE.SMART/Components/Pages/About.razor index 26927ee..5d9463c 100644 --- a/GPW.CORE.SMART/Components/Pages/About.razor +++ b/GPW.CORE.SMART/Components/Pages/About.razor @@ -24,6 +24,25 @@
+
+

Version and license

+
+
+ GPW
+ v.@version +
+
+ License:
+ +
+

@Messaggio

diff --git a/GPW.CORE.SMART/Components/Pages/About.razor.cs b/GPW.CORE.SMART/Components/Pages/About.razor.cs index d65c548..f1bd65a 100644 --- a/GPW.CORE.SMART/Components/Pages/About.razor.cs +++ b/GPW.CORE.SMART/Components/Pages/About.razor.cs @@ -1,3 +1,4 @@ +using GPW.CORE.Smart.Data; using Microsoft.AspNetCore.Components; namespace GPW.CORE.Smart.Components.Pages @@ -22,19 +23,51 @@ namespace GPW.CORE.Smart.Components.Pages #region Protected Methods - protected override void OnInitialized() + protected override async Task OnInitializedAsync() { + await LicServ.RefreshApplic(); Titolo = Configuration.GetValue("Application:Name")!; Messaggio = Configuration.GetValue("Application:ContactText")!; } #endregion Protected Methods + private int numLicAvail + { + get + { + int answ = 0; + if (LicServ.HasActivData) + { + var licRec = LicServ.AKVList.Where(x => x.NomeVar == LicServ.Installazione).FirstOrDefault(); + if (licRec != null) + { + answ = licRec.ValInt ?? 0; + } + } + return answ; + } + } + + private string licStatus + { + get => LicServ.HasActivData ? $"{LicServ.ActivList.Count}/{numLicAvail}" : "N.A."; + } + private string licExpiry + { + get => LicServ.HasActivData ? $"{LicServ.AppLicense.Scadenza:yyyy-MM-dd}" : "N.A."; + } + #region Private Properties [Inject] private IConfiguration Configuration { get; set; } = null!; #endregion Private Properties + + [Inject] + protected LicenseService LicServ { get; set; } = null!; + + protected Version? version = typeof(Program).Assembly.GetName().Version; } } \ No newline at end of file diff --git a/GPW.CORE.SMART/Components/Pages/Info.razor b/GPW.CORE.SMART/Components/Pages/Info.razor deleted file mode 100644 index d06842e..0000000 --- a/GPW.CORE.SMART/Components/Pages/Info.razor +++ /dev/null @@ -1,16 +0,0 @@ -@page "/Info" -

Info

- -Pagina info generiche come https://iis01.egalware.com/GPW/SMART/Informazioni -
-In particolare -
    -
  • app + versione
  • -
  • copyright
  • -
  • dati cliente / licenze /scadenza
  • -
  • dati contatto e supporto
  • -
- -@code { - -} diff --git a/GPW.CORE.SMART/Data/LicenseService.cs b/GPW.CORE.SMART/Data/LicenseService.cs index 01de50f..2653b54 100644 --- a/GPW.CORE.SMART/Data/LicenseService.cs +++ b/GPW.CORE.SMART/Data/LicenseService.cs @@ -39,6 +39,9 @@ namespace GPW.CORE.Smart.Data #region Public Properties + + public LiManObj.ApplicativoDTO AppLicense { get; set; } = new LiManObj.ApplicativoDTO(); + public List ActivList { get; set; } = new List(); public List AKVList { get; set; } = new List(); public string Applicazione { get; set; } = ""; @@ -67,6 +70,25 @@ namespace GPW.CORE.Smart.Data } } + public bool HasAppData + { + get + { + bool answ = !string.IsNullOrEmpty(AppLicense.CodApp); + // se ok controllo che ci siano attivazioni + if (!answ) + { + var pUpd = Task.Run(async () => + { + AppLicense = await AppLicCache(); + }); + pUpd.Wait(); + answ = !string.IsNullOrEmpty(AppLicense.CodApp); + } + return answ; + } + } + public DateTime infoExpiry { get; set; } = DateTime.Today.AddDays(1); public string Installazione { get; set; } = ""; public string MasterKey { get; set; } = ""; @@ -102,6 +124,23 @@ namespace GPW.CORE.Smart.Data return await Task.FromResult(dbResult); } + public async Task AppLicCache() + { + LiManObj.ApplicativoDTO dbResult = new LiManObj.ApplicativoDTO(); + string cacheKey = $"{rKeyLic}:{MasterKey}"; + string rawData = await getRSV(cacheKey); + if (!string.IsNullOrEmpty(rawData)) + { + var cacheRes = JsonConvert.DeserializeObject(rawData); + if (cacheRes != null) + { + dbResult = cacheRes; + } + } + + return await Task.FromResult(dbResult); + } + /// /// Init della classe con variabili di base da Redis/DB /// @@ -114,6 +153,27 @@ namespace GPW.CORE.Smart.Data return fatto; } + /// + /// Init della classe x licenza applicativo + /// + public async Task RefreshApplic() + { + bool fatto = false; + if (string.IsNullOrEmpty(AppLicense.CodApp)) + { + var onlineLic = await OnlineApplicationData(); + if (onlineLic != null) + { + // scadenza info a 15 gg... + int numDays = 15; + AppLicense = onlineLic; + fatto = await setAppLicData(AppLicense, numDays); + } + } + await Task.Delay(1); + return fatto; + } + /// /// Init della classe con variabili di base da Redis/DB /// @@ -150,10 +210,28 @@ namespace GPW.CORE.Smart.Data return fatto; } + public async Task setAppLicData(LiManObj.ApplicativoDTO newAppDto, int numDays) + { + bool fatto = false; + string cacheKey = $"{rKeyLic}:{MasterKey}"; + var rawData = JsonConvert.SerializeObject(newAppDto); + await setRSV(cacheKey, rawData, numDays * 24); + fatto = true; + if (EA_InfoUpdated != null) + { + EA_InfoUpdated?.Invoke(); + } + return fatto; + } + #endregion Public Methods #region Protected Fields + /// + /// Chiave redis x info licenza + /// + protected const string rKeyLic = "LongCache:LicData"; /// /// Chiave redis x attivazioni della licenza /// @@ -283,6 +361,34 @@ namespace GPW.CORE.Smart.Data return await Task.FromResult(answ); } + + /// + /// Dati Applicativo + /// + private async Task OnlineApplicationData() + { + LiManObj.ApplicativoDTO? answ = new LiManObj.ApplicativoDTO(); + // cerco online + RestClient client = new RestClient(apiUrl); + //client.Authenticator = new HttpBasicAuthenticator("username", "password"); + string ValEnc = HttpUtility.UrlEncode(Applicazione); + var request = new RestRequest($"/api/applicazione/{Installazione}?CodApp={ValEnc}", Method.Get); + var response = await client.GetAsync(request); + // controllo risposta + if (response.StatusCode == System.Net.HttpStatusCode.OK) + { + // salvo in redis contenuto serializzato + string rawData = $"{response.Content}"; + var rawList = JsonConvert.DeserializeObject>(rawData); + if (rawList != null) + { + answ = rawList.FirstOrDefault(); + } + //answ = JsonConvert.DeserializeObject(rawData); + } + return await Task.FromResult(answ); + } + private void ReportUpdated() { if (EA_InfoUpdated != null) diff --git a/GPW.CORE6.Smart/GPW.CORE6.SMART.csproj b/GPW.CORE6.Smart/GPW.CORE6.SMART.csproj index 49dfab1..e003101 100644 --- a/GPW.CORE6.Smart/GPW.CORE6.SMART.csproj +++ b/GPW.CORE6.Smart/GPW.CORE6.SMART.csproj @@ -2,7 +2,7 @@ net8.0 enable - 3.0.2408.2217 + 3.0.2408.2218 enable www.egalware.com GPW Smart UI diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html index 7ce7c6d..ba9dce6 100644 --- a/Resources/ChangeLog.html +++ b/Resources/ChangeLog.html @@ -1,6 +1,6 @@ GPW - Gestione Presenze Web -

Versione: 3.0.2408.2217

+

Versione: 3.0.2408.2218


Note di rilascio:
  • diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt index ac68f4c..4d7a83f 100644 --- a/Resources/VersNum.txt +++ b/Resources/VersNum.txt @@ -1 +1 @@ -3.0.2408.2217 +3.0.2408.2218 diff --git a/Resources/manifest.xml b/Resources/manifest.xml index 83a5a46..72d6ebe 100644 --- a/Resources/manifest.xml +++ b/Resources/manifest.xml @@ -1,6 +1,6 @@ - 3.0.2408.2217 + 3.0.2408.2218 http://nexus.steamware.net/repository/SWS/GPW/stable/GPW.Smart.zip http://nexus.steamware.net/repository/SWS/GPW/stable/ChangeLog.html false