refresh metodi recupero info licenze

This commit is contained in:
Samuele Locatelli
2021-11-06 12:44:49 +01:00
parent f662e5a3e1
commit e4a96abd8f
3 changed files with 99 additions and 15 deletions
@@ -7,18 +7,20 @@
<div class="d-flex justify-content-between text-right table-secondary">
<div class="p-2">
<div class="border border-info p-2" runat="server" id="divDB">
Licenze locali: disponibili <b><%: numLicenze %></b> / attivate <b><%: utentiAttivi %></b>
<div class="d-flex justify-content-between">
<div class="p-2">
<span class="border border-info p-2" runat="server" id="divDB">Licenze locali: disponibili <b><%: numLicenze %></b> / attivate <b><%: utentiAttivi %></b>
</span>
</div>
<div class="p-2">
<span class="border border-success p-2" runat="server" id="divOnline">Licenze online: disponibili <b><%: numLicenzeOnline %></b> / attivate <b><%: attivazioniOnline %></b>
</span>
</div>
<div class="py-1 px-2">
<asp:LinkButton runat="server" ID="lbtRefresh" CssClass="btn btn-success btn-sm" OnClick="lbtRefresh_Click">Re-Validate</asp:LinkButton>
</div>
</div>
</div>
<div class="p-2">
<div class="border border-success p-2" runat="server" id="divOnline">
Licenze online: disponibili <b><%: numLicenzeOnline %></b> / attivate <b><%: attivazioniOnline %></b>
</div>
</div>
<div class="p-2">
<asp:LinkButton runat="server" ID="lbtRefresh" CssClass="btn btn-success btn-sm" OnClick="lbtRefresh_Click">Re-Validate</asp:LinkButton>
</div>
<div class="p-2">
<asp:CheckBox runat="server" ID="chkshowAll" Text="Mostra tutti" OnCheckedChanged="chkshowAll_CheckedChanged" AutoPostBack="true" ToolTip="Mostra tutti gli utenti (anche cessati/inattivi)" Checked="true" />
</div>
@@ -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;
}
/// <summary>
+84 -4
View File
@@ -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
}
}
/// <summary>
/// Chaive Licenza Master
/// </summary>
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;
}
}
/// <summary>
/// modalità applicazione (pagina test.aspx)
/// </summary>
@@ -261,11 +287,39 @@ namespace GPW_data
#region Public Methods
public static async Task<bool> CheckOnline()
/// <summary>
/// Effettua refresh ActivationInfo con chiamata remota (sovrascrivendo info locali Redis)
/// </summary>
/// <returns></returns>
public static async Task<bool> 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);
}
/// <summary>
/// Effettua refresh AppInfo con chiamata remota (sovrascrivendo info locali Redis)
/// </summary>
/// <returns></returns>
public static async Task<bool> 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);
}
/// <summary>
/// Effettua refresh LicenseInfo con chiamata remota (sovrascrivendo info locali Redis)
/// </summary>
/// <returns></returns>
public static async Task<bool> 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
}
}