update struttura classi x migliorare output offuscamento
This commit is contained in:
+78
-60
@@ -45,48 +45,27 @@ namespace GPW_data
|
||||
|
||||
#endregion Public Fields
|
||||
|
||||
#region Protected Constructors
|
||||
#region Private Constructors
|
||||
|
||||
protected DataProxy()
|
||||
private DataProxy()
|
||||
{
|
||||
initTA();
|
||||
setupConnectionStringBase();
|
||||
}
|
||||
|
||||
#endregion Protected Constructors
|
||||
#endregion Private Constructors
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Verifica se il dip corrente ha un record valido in payload
|
||||
/// </summary>
|
||||
public static bool currDipHasPayloadActive
|
||||
{
|
||||
get
|
||||
{
|
||||
bool answ = licenzeGPW.userPayloadOk(idxDipendente);
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
public static bool currDipHasPayloadActive => _currDipHasPayloadActive();
|
||||
|
||||
/// <summary>
|
||||
/// Verifica se il dip corrente sia attivo
|
||||
/// </summary>
|
||||
public static bool currDipIsActive
|
||||
{
|
||||
get
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
DS_Applicazione.DipendentiRow rigaDip = DP.taDipendenti.getByIdx(idxDipendente)[0];
|
||||
answ = rigaDip.attivo;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
public static bool currDipIsActive => _currDipIsActive();
|
||||
|
||||
/// <summary>
|
||||
/// idxDipendente in sessione
|
||||
@@ -112,12 +91,79 @@ namespace GPW_data
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Protected Methods
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Verifica se il dip corrente ha un record valido in payload
|
||||
/// </summary>
|
||||
private static bool _currDipHasPayloadActive()
|
||||
{
|
||||
bool answ = licenzeGPW.userPayloadOk(idxDipendente);
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifica se il dip corrente sia attivo
|
||||
/// </summary>
|
||||
private static bool _currDipIsActive()
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
DS_Applicazione.DipendentiRow rigaDip = DP.taDipendenti.getByIdx(idxDipendente)[0];
|
||||
answ = rigaDip.attivo;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifica se il dip RICHIESTO sia attivo
|
||||
/// </summary>
|
||||
/// <param name="_idxDipendente"></param>
|
||||
/// <returns></returns>
|
||||
private bool checkDipIsActive(int _idxDipendente)
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
DS_Applicazione.DipendentiRow rigaDip = DP.taDipendenti.getByIdx(_idxDipendente)[0];
|
||||
answ = rigaDip.attivo;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calcola HASH del codice impiego
|
||||
/// </summary>
|
||||
/// <param name="rigaDip"></param>
|
||||
/// <returns></returns>
|
||||
private string getHashCodImpiego(DS_Applicazione.DipendentiRow rigaDip)
|
||||
{
|
||||
string hash = "";
|
||||
string answ = "";
|
||||
if (rigaDip != null)
|
||||
{
|
||||
answ = $"{rigaDip.idxDipendente}|{rigaDip.Cognome}.{rigaDip.Nome}|{rigaDip.CF}|{rigaDip.dataAssunzione:yyyyMMdd}|{rigaDip.email}|{rigaDip.matricola}";
|
||||
}
|
||||
// hashing!
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
byte[] InputBytes = Encoding.UTF8.GetBytes(answ);
|
||||
var byteHash = md5.ComputeHash(InputBytes);
|
||||
hash = BitConverter.ToString(byteHash).Replace("-", "").ToLowerInvariant();
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// init dei table adapters
|
||||
/// </summary>
|
||||
protected void initTA()
|
||||
private void initTA()
|
||||
{
|
||||
taAnCli = new DS_ApplicazioneTableAdapters.AnagClientiTableAdapter();
|
||||
taTimb = new DS_ApplicazioneTableAdapters.TimbratureTableAdapter();
|
||||
@@ -149,7 +195,7 @@ namespace GPW_data
|
||||
/// <summary>
|
||||
/// effettua setup dei connection strings da web.config delal singola applicazione
|
||||
/// </summary>
|
||||
protected virtual void setupConnectionStringBase()
|
||||
private void setupConnectionStringBase()
|
||||
{
|
||||
string connGPW = memLayer.ML.confReadString("GPWConnectionString");
|
||||
// connections del db
|
||||
@@ -180,7 +226,7 @@ namespace GPW_data
|
||||
taExpComm.Connection.ConnectionString = connGPW;
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
#endregion Private Methods
|
||||
|
||||
#region Public Methods
|
||||
|
||||
@@ -202,18 +248,7 @@ namespace GPW_data
|
||||
/// </summary>
|
||||
/// <param name="_idxDipendente"></param>
|
||||
/// <returns></returns>
|
||||
public bool dipIsActive(int _idxDipendente)
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
DS_Applicazione.DipendentiRow rigaDip = DP.taDipendenti.getByIdx(_idxDipendente)[0];
|
||||
answ = rigaDip.attivo;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
public bool dipIsActive(int _idxDipendente) => checkDipIsActive(_idxDipendente);
|
||||
|
||||
/// <summary>
|
||||
/// effettua enroll del device
|
||||
@@ -300,24 +335,7 @@ namespace GPW_data
|
||||
/// </summary>
|
||||
/// <param name="rigaDip"></param>
|
||||
/// <returns></returns>
|
||||
public string hashCodImpiego(DS_Applicazione.DipendentiRow rigaDip)
|
||||
{
|
||||
string hash = "";
|
||||
string answ = "";
|
||||
if (rigaDip != null)
|
||||
{
|
||||
answ = $"{rigaDip.idxDipendente}|{rigaDip.Cognome}.{rigaDip.Nome}|{rigaDip.CF}|{rigaDip.dataAssunzione:yyyyMMdd}|{rigaDip.email}|{rigaDip.matricola}";
|
||||
}
|
||||
// hashing!
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
byte[] InputBytes = Encoding.UTF8.GetBytes(answ);
|
||||
var byteHash = md5.ComputeHash(InputBytes);
|
||||
hash = BitConverter.ToString(byteHash).Replace("-", "").ToLowerInvariant();
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
public string hashCodImpiego(DS_Applicazione.DipendentiRow rigaDip) => getHashCodImpiego(rigaDip);
|
||||
|
||||
/// <summary>
|
||||
/// invia una mail al destinatario x linkare nuovi devices tramite URL
|
||||
|
||||
+346
-330
@@ -15,32 +15,34 @@ namespace GPW_data
|
||||
{
|
||||
public class licenzeGPW
|
||||
{
|
||||
#region Protected Fields
|
||||
#region Private Fields
|
||||
|
||||
private static string _applicazione = memLayer.ML.confReadString("appName");
|
||||
|
||||
/// <summary>
|
||||
/// Url di base chiamate API gestione licenze
|
||||
/// </summary>
|
||||
//protected static string apiUrl = "https://localhost:44351/";
|
||||
protected static string apiUrl = "https://liman.egalware.com/ELM.API/";
|
||||
//private static string apiUrl = "https://localhost:44351/";
|
||||
private static string apiUrl = "https://liman.egalware.com/ELM.API/";
|
||||
|
||||
protected static string rkeyActInfo = memLayer.ML.redHash($"LiMan:ActInfo");
|
||||
private static string rkeyActInfo = memLayer.ML.redHash($"LiMan:ActInfo");
|
||||
|
||||
protected static string rkeyAppInfo = memLayer.ML.redHash($"LiMan:AppInfo");
|
||||
private static string rkeyAppInfo = memLayer.ML.redHash($"LiMan:AppInfo");
|
||||
|
||||
protected static string rkeyLicInfo = memLayer.ML.redHash($"LiMan:LicInfo");
|
||||
private static string rkeyLicInfo = memLayer.ML.redHash($"LiMan:LicInfo");
|
||||
|
||||
protected static string rkeyPayload = memLayer.ML.redHash($"LiMan:Payload");
|
||||
private static string rkeyPayload = memLayer.ML.redHash($"LiMan:Payload");
|
||||
|
||||
protected static string rkeyVetoRefPayL = memLayer.ML.redHash($"LiMan:VetoRefPayL");
|
||||
private static string rkeyVetoRefPayL = memLayer.ML.redHash($"LiMan:VetoRefPayL");
|
||||
|
||||
#endregion Protected Fields
|
||||
#endregion Private Fields
|
||||
|
||||
#region Protected Properties
|
||||
#region Private Properties
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache statica locale dati licenza, random circa 1 h
|
||||
/// </summary>
|
||||
protected static int LicCacheTTL
|
||||
private static int LicCacheTTL
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -49,354 +51,347 @@ namespace GPW_data
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Protected Properties
|
||||
#endregion Private Properties
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// nome applicazione sw
|
||||
/// </summary>
|
||||
public static string applicazione
|
||||
{
|
||||
get
|
||||
{
|
||||
string answ = memLayer.ML.confReadString("appName");
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
public static string applicazione => _applicazione;
|
||||
|
||||
/// <summary>
|
||||
/// numero di licenze attive da info online
|
||||
/// </summary>
|
||||
public static int attivazioniOnline
|
||||
{
|
||||
get
|
||||
{
|
||||
return InfoApplicativo.NumLicenzeAttive;
|
||||
}
|
||||
}
|
||||
public static int attivazioniOnline => _attivazioniOnline();
|
||||
|
||||
/// <summary>
|
||||
/// chaive licenza
|
||||
/// </summary>
|
||||
public static string authKey
|
||||
{
|
||||
get
|
||||
{
|
||||
string answ = "";
|
||||
// controllo su db...
|
||||
try
|
||||
{
|
||||
answ = DataProxy.DP.taAKV.getByKey(installazione)[0].valString;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
public static string authKey => _authKey();
|
||||
|
||||
/// <summary>
|
||||
/// verifica se numero licenze copre utenti attivi...
|
||||
/// </summary>
|
||||
public static bool checkLicenze
|
||||
{
|
||||
get
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
// effettua refresh attivazioni...
|
||||
var fatto = RefreshActInfo().Result;
|
||||
answ = utentiAttivi <= licenzeAttive;
|
||||
if (!answ && memLayer.ML.confReadInt("_logLevel") > 5)
|
||||
{
|
||||
logger.lg.scriviLog(string.Format("WARNING licenze: utenti attivi {0} / licenziati {1}", utentiAttivi, licenzeAttive), tipoLog.WARNING);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
public static bool checkLicenze => _checkLicenze();
|
||||
|
||||
/// <summary>
|
||||
/// verifica se il payload delle licenze attivate sia valido (con server online)
|
||||
/// </summary>
|
||||
public static bool checkPayload
|
||||
{
|
||||
get
|
||||
{
|
||||
bool answ = false;
|
||||
string currPayload = "";
|
||||
tryCheckPayloadOnline(ref answ, ref currPayload);
|
||||
|
||||
// se OK resetto counter, altrimenti incremento
|
||||
if (!answ)
|
||||
{
|
||||
bool okRefreshPayload = string.IsNullOrEmpty(memLayer.ML.getRSV(rkeyVetoRefPayL));
|
||||
if (okRefreshPayload)
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
// richiedo update payload impostando TTL a 1 sec...
|
||||
memLayer.ML.setRSV(rkeyPayload, "", 1);
|
||||
var okApp = RefreshAppInfo().Result;
|
||||
var okLic = RefreshActInfo().Result;
|
||||
var okAct = RefreshLicInfo().Result;
|
||||
var okPld = RefreshPayload().Result;
|
||||
|
||||
// evito ricalcolo x 5 sec...
|
||||
memLayer.ML.setRSV(rkeyVetoRefPayL, "Veto", 5);
|
||||
sw.Stop();
|
||||
logger.lg.scriviLog($"Trovato payload non valido, effettuato reset variabili in {sw.ElapsedMilliseconds} ms");
|
||||
|
||||
sw.Start();
|
||||
tryCheckPayloadOnline(ref answ, ref currPayload);
|
||||
sw.Stop();
|
||||
logger.lg.scriviLog($"Rivalutato payload con esito {answ} in {sw.ElapsedMilliseconds} ms");
|
||||
}
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Info applicativo corrente (da cache con eventuale recupero online...)
|
||||
/// </summary>
|
||||
public static LiManObj.ApplicativoDTO InfoApplicativo
|
||||
{
|
||||
get
|
||||
{
|
||||
LiManObj.ApplicativoDTO answ = new LiManObj.ApplicativoDTO();
|
||||
// cerco da cache
|
||||
string rawData = memLayer.ML.getRSV(rkeyLicInfo);
|
||||
// se no ci fosse --> refresh online!
|
||||
if (string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
var fatto = RefreshAppInfo().Result;
|
||||
if (fatto)
|
||||
{
|
||||
rawData = memLayer.ML.getRSV(rkeyLicInfo);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
try
|
||||
{
|
||||
// verifico se ho 1 risultato o molti...se inizia per "[" è molti
|
||||
if (rawData.StartsWith("["))
|
||||
{
|
||||
// POTREBBE darmi + di 1 risultato, prendo + recente...
|
||||
List<LiManObj.ApplicativoDTO> infoList = JsonConvert.DeserializeObject<List<LiManObj.ApplicativoDTO>>(rawData);
|
||||
if (infoList != null)
|
||||
{
|
||||
answ = infoList.OrderByDescending(x => x.Scadenza).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = JsonConvert.DeserializeObject<LiManObj.ApplicativoDTO>(rawData);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
public static bool checkPayload => _checkPayload();
|
||||
|
||||
/// <summary>
|
||||
/// nome installazione sw
|
||||
/// </summary>
|
||||
public static string installazione
|
||||
{
|
||||
get
|
||||
{
|
||||
string answ = "";
|
||||
try
|
||||
{
|
||||
answ = DataProxy.DP.taAKV.getByKey("installazione")[0].valString;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog(string.Format("Errore recupero chiave installazione da AKV: {0}", exc), tipoLog.EXCEPTION);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
public static string installazione => _installazione();
|
||||
|
||||
/// <summary>
|
||||
/// numero di licenze attive sul sw (SE CONFORMI A CHIAVE) altrimenti da dll steamware
|
||||
/// numero di licenze attive sul sw (SE CONFORMI A CHIAVE)
|
||||
/// </summary>
|
||||
public static int licenzeAttive
|
||||
{
|
||||
get
|
||||
{
|
||||
int answ = 0;
|
||||
int licenzeMax = licenseMan.getLicenseNum(installazione, applicazione);
|
||||
// verifico dato su DB sia valido... expiry date con quel numero sia > della data odierna
|
||||
if (scadenzaLicenza >= DateTime.Today)
|
||||
{
|
||||
answ = licenzeDb;
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = licenzeMax;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
public static int licenzeAttive => _licenzeAttive();
|
||||
|
||||
/// <summary>
|
||||
/// numero di licenze attive su DB (NON verificate!)
|
||||
/// </summary>
|
||||
public static int licenzeDb
|
||||
{
|
||||
get
|
||||
{
|
||||
int answ = 0;
|
||||
// controllo su db...
|
||||
try
|
||||
{
|
||||
answ = DataProxy.DP.taAKV.getByKey(installazione)[0].valInt;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
public static int licenzeDb => _licenzeDb();
|
||||
|
||||
/// <summary>
|
||||
/// numero di licenze disponibili da info online
|
||||
/// </summary>
|
||||
public static int licenzeOnline
|
||||
{
|
||||
get
|
||||
{
|
||||
return InfoApplicativo.NumLicenze;
|
||||
}
|
||||
}
|
||||
public static int licenzeOnline => _licenzeOnline();
|
||||
|
||||
/// <summary>
|
||||
/// Elenco attivazioni attuali
|
||||
/// </summary>
|
||||
public static List<LiManObj.AttivazioneDTO> ListaAttivazioni
|
||||
{
|
||||
get
|
||||
{
|
||||
List<LiManObj.AttivazioneDTO> answ = new List<LiManObj.AttivazioneDTO>();
|
||||
// cerco da cache
|
||||
string rawData = memLayer.ML.getRSV(rkeyActInfo);
|
||||
// se no ci fosse --> refresh online!
|
||||
if (string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
var fatto = RefreshActInfo().Result;
|
||||
if (fatto)
|
||||
{
|
||||
rawData = memLayer.ML.getRSV(rkeyActInfo);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
answ = JsonConvert.DeserializeObject<List<LiManObj.AttivazioneDTO>>(rawData);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
public static List<LiManObj.AttivazioneDTO> ListaAttivazioni => _ListaAttivazioni();
|
||||
|
||||
/// <summary>
|
||||
/// Chaive Licenza Master
|
||||
/// Chiave 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;
|
||||
}
|
||||
}
|
||||
public static string MasterKey => _MasterKey();
|
||||
|
||||
/// <summary>
|
||||
/// modalità applicazione (pagina test.aspx)
|
||||
/// </summary>
|
||||
public static string modApp
|
||||
{
|
||||
get
|
||||
{
|
||||
string answ = "";
|
||||
try
|
||||
{
|
||||
answ = DataProxy.DP.taAKV.getByKey("appMode")[0].valString;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog(string.Format("Errore recupero chiave appMode da AKV: {0}", exc), tipoLog.EXCEPTION);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
public static string modApp => _modApp();
|
||||
|
||||
/// <summary>
|
||||
/// scadenza licenze x applicativo
|
||||
/// </summary>
|
||||
public static DateTime scadenzaLicenza
|
||||
{
|
||||
get
|
||||
{
|
||||
DateTime answ = licenseMan.expiryDateByAuthKey(installazione, applicazione, DataProxy.DP.taAKV.getByKey(installazione)[0].valInt, DataProxy.DP.taAKV.getByKey(installazione)[0].valString);
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
public static DateTime scadenzaLicenza => _scadenzaLicenza();
|
||||
|
||||
/// <summary>
|
||||
/// numero di utenti attivi
|
||||
/// </summary>
|
||||
public static int utentiAttivi
|
||||
{
|
||||
get
|
||||
{
|
||||
int answ = DataProxy.DP.taDipendenti.getAttivi(false).Count;
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
public static int utentiAttivi => _utentiAttivi();
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static void tryCheckPayloadOnline(ref bool answ, ref string currPayload)
|
||||
/// <summary>
|
||||
/// numero di licenze attive da info online
|
||||
/// </summary>
|
||||
private static int _attivazioniOnline()
|
||||
{
|
||||
return InfoApplicativo().NumLicenzeAttive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// chaive licenza
|
||||
/// </summary>
|
||||
private static string _authKey()
|
||||
{
|
||||
string answ = "";
|
||||
// controllo su db...
|
||||
try
|
||||
{
|
||||
// cerco payload licenze locale...
|
||||
currPayload = memLayer.ML.getRSV(rkeyPayload);
|
||||
// se no ci fosse --> refresh online!
|
||||
if (string.IsNullOrEmpty(currPayload))
|
||||
{
|
||||
currPayload = calcPayload();
|
||||
memLayer.ML.setRSV(rkeyPayload, currPayload, LicCacheTTL);
|
||||
}
|
||||
// confronto payload calc con quello della licenza
|
||||
answ = InfoApplicativo.Payload == currPayload;
|
||||
answ = DataProxy.DP.taAKV.getByKey(installazione)[0].valString;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
/// <summary>
|
||||
/// verifica se numero licenze copre utenti attivi...
|
||||
/// </summary>
|
||||
private static bool _checkLicenze()
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
// effettua refresh attivazioni...
|
||||
var fatto = RefreshActInfo().Result;
|
||||
answ = utentiAttivi <= licenzeAttive;
|
||||
if (!answ && memLayer.ML.confReadInt("_logLevel") > 5)
|
||||
{
|
||||
logger.lg.scriviLog(string.Format("WARNING licenze: utenti attivi {0} / licenziati {1}", utentiAttivi, licenzeAttive), tipoLog.WARNING);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
|
||||
#region Protected Methods
|
||||
/// <summary>
|
||||
/// verifica se il payload delle licenze attivate sia valido (con server online)
|
||||
/// </summary>
|
||||
private static bool _checkPayload()
|
||||
{
|
||||
bool answ = false;
|
||||
string currPayload = "";
|
||||
tryCheckPayloadOnline(ref answ, ref currPayload);
|
||||
|
||||
protected static string calcPayload()
|
||||
// se OK resetto counter, altrimenti incremento
|
||||
if (!answ)
|
||||
{
|
||||
bool okRefreshPayload = string.IsNullOrEmpty(memLayer.ML.getRSV(rkeyVetoRefPayL));
|
||||
if (okRefreshPayload)
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
// richiedo update payload impostando TTL a 1 sec...
|
||||
memLayer.ML.setRSV(rkeyPayload, "", 1);
|
||||
var okApp = RefreshAppInfo().Result;
|
||||
var okLic = RefreshActInfo().Result;
|
||||
var okAct = RefreshLicInfo().Result;
|
||||
var okPld = RefreshPayload().Result;
|
||||
|
||||
// evito ricalcolo x 5 sec...
|
||||
memLayer.ML.setRSV(rkeyVetoRefPayL, "Veto", 5);
|
||||
sw.Stop();
|
||||
logger.lg.scriviLog($"Trovato payload non valido, effettuato reset variabili in {sw.ElapsedMilliseconds} ms");
|
||||
|
||||
sw.Start();
|
||||
tryCheckPayloadOnline(ref answ, ref currPayload);
|
||||
sw.Stop();
|
||||
logger.lg.scriviLog($"Rivalutato payload con esito {answ} in {sw.ElapsedMilliseconds} ms");
|
||||
}
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// nome installazione sw
|
||||
/// </summary>
|
||||
private static string _installazione()
|
||||
{
|
||||
string answ = "";
|
||||
try
|
||||
{
|
||||
answ = DataProxy.DP.taAKV.getByKey("installazione")[0].valString;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog(string.Format("Errore recupero chiave installazione da AKV: {0}", exc), tipoLog.EXCEPTION);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// numero di licenze attive sul sw (SE CONFORMI A CHIAVE)
|
||||
/// </summary>
|
||||
private static int _licenzeAttive()
|
||||
{
|
||||
int answ = 0;
|
||||
int licenzeMax = licenseMan.getLicenseNum(installazione, applicazione);
|
||||
// verifico dato su DB sia valido... expiry date con quel numero sia > della data odierna
|
||||
if (scadenzaLicenza >= DateTime.Today)
|
||||
{
|
||||
answ = licenzeDb;
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = licenzeMax;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// numero di licenze attive su DB (NON verificate!)
|
||||
/// </summary>
|
||||
private static int _licenzeDb()
|
||||
{
|
||||
int answ = 0;
|
||||
// controllo su db...
|
||||
try
|
||||
{
|
||||
answ = DataProxy.DP.taAKV.getByKey(installazione)[0].valInt;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// numero di licenze disponibili da info online
|
||||
/// </summary>
|
||||
private static int _licenzeOnline()
|
||||
{
|
||||
return InfoApplicativo().NumLicenze;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco attivazioni attuali
|
||||
/// </summary>
|
||||
private static List<LiManObj.AttivazioneDTO> _ListaAttivazioni()
|
||||
{
|
||||
List<LiManObj.AttivazioneDTO> answ = new List<LiManObj.AttivazioneDTO>();
|
||||
// cerco da cache
|
||||
string rawData = memLayer.ML.getRSV(rkeyActInfo);
|
||||
// se no ci fosse --> refresh online!
|
||||
if (string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
var fatto = RefreshActInfo().Result;
|
||||
if (fatto)
|
||||
{
|
||||
rawData = memLayer.ML.getRSV(rkeyActInfo);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
answ = JsonConvert.DeserializeObject<List<LiManObj.AttivazioneDTO>>(rawData);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chiave Licenza Master
|
||||
/// </summary>
|
||||
private static string _MasterKey()
|
||||
{
|
||||
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>
|
||||
private static string _modApp()
|
||||
{
|
||||
string answ = "";
|
||||
try
|
||||
{
|
||||
answ = DataProxy.DP.taAKV.getByKey("appMode")[0].valString;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog(string.Format("Errore recupero chiave appMode da AKV: {0}", exc), tipoLog.EXCEPTION);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// scadenza licenze x applicativo
|
||||
/// </summary>
|
||||
private static DateTime _scadenzaLicenza()
|
||||
{
|
||||
DateTime answ = licenseMan.expiryDateByAuthKey(installazione, applicazione, DataProxy.DP.taAKV.getByKey(installazione)[0].valInt, DataProxy.DP.taAKV.getByKey(installazione)[0].valString);
|
||||
return answ;
|
||||
}
|
||||
|
||||
private static bool _userPayloadOk(int idxDip)
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
// recupero riga dip
|
||||
var userTab = DataProxy.DP.taDipendenti.getByIdx(idxDip);
|
||||
if (userTab != null && userTab.Count > 0)
|
||||
{
|
||||
var userRow = userTab[0];
|
||||
// calcolo suo codice...
|
||||
var codImpCurr = DataProxy.DP.hashCodImpiego(userRow);
|
||||
// cerco dip tra elenco json
|
||||
var userLocalList = ListaAttivazioni;
|
||||
var foundRec = userLocalList.Where(x => x.CodImpiego == codImpCurr);
|
||||
answ = foundRec.Count() > 0;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// numero di utenti attivi
|
||||
/// </summary>
|
||||
private static int _utentiAttivi()
|
||||
{
|
||||
int answ = DataProxy.DP.taDipendenti.getAttivi(false).Count;
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calcolo Hash data stringa input
|
||||
/// </summary>
|
||||
/// <param name="rawData"></param>
|
||||
/// <returns></returns>
|
||||
private static string calcHash(string rawData)
|
||||
{
|
||||
string hash = "";
|
||||
// hashing!
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
byte[] InputBytes = Encoding.UTF8.GetBytes(rawData);
|
||||
var byteHash = md5.ComputeHash(InputBytes);
|
||||
hash = BitConverter.ToString(byteHash).Replace("-", "").ToLowerInvariant();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
private static string calcPayload()
|
||||
{
|
||||
string answ = "";
|
||||
// costruisco stringa da elenco impieghi...
|
||||
@@ -428,28 +423,71 @@ namespace GPW_data
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
/// <summary>
|
||||
/// Info applicativo corrente (da cache con eventuale recupero online...)
|
||||
/// </summary>
|
||||
private static LiManObj.ApplicativoDTO InfoApplicativo()
|
||||
{
|
||||
LiManObj.ApplicativoDTO answ = new LiManObj.ApplicativoDTO();
|
||||
// cerco da cache
|
||||
string rawData = memLayer.ML.getRSV(rkeyLicInfo);
|
||||
// se no ci fosse --> refresh online!
|
||||
if (string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
var fatto = RefreshAppInfo().Result;
|
||||
if (fatto)
|
||||
{
|
||||
rawData = memLayer.ML.getRSV(rkeyLicInfo);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
try
|
||||
{
|
||||
// verifico se ho 1 risultato o molti...se inizia per "[" è molti
|
||||
if (rawData.StartsWith("["))
|
||||
{
|
||||
// POTREBBE darmi + di 1 risultato, prendo + recente...
|
||||
List<LiManObj.ApplicativoDTO> infoList = JsonConvert.DeserializeObject<List<LiManObj.ApplicativoDTO>>(rawData);
|
||||
if (infoList != null)
|
||||
{
|
||||
answ = infoList.OrderByDescending(x => x.Scadenza).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = JsonConvert.DeserializeObject<LiManObj.ApplicativoDTO>(rawData);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
private static void tryCheckPayloadOnline(ref bool answ, ref string currPayload)
|
||||
{
|
||||
try
|
||||
{
|
||||
// cerco payload licenze locale...
|
||||
currPayload = memLayer.ML.getRSV(rkeyPayload);
|
||||
// se no ci fosse --> refresh online!
|
||||
if (string.IsNullOrEmpty(currPayload))
|
||||
{
|
||||
currPayload = calcPayload();
|
||||
memLayer.ML.setRSV(rkeyPayload, currPayload, LicCacheTTL);
|
||||
}
|
||||
// confronto payload calc con quello della licenza
|
||||
answ = InfoApplicativo().Payload == currPayload;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Calcolo Hash data stringa input
|
||||
/// </summary>
|
||||
/// <param name="rawData"></param>
|
||||
/// <returns></returns>
|
||||
public static string calcHash(string rawData)
|
||||
{
|
||||
string hash = "";
|
||||
// hashing!
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
byte[] InputBytes = Encoding.UTF8.GetBytes(rawData);
|
||||
var byteHash = md5.ComputeHash(InputBytes);
|
||||
hash = BitConverter.ToString(byteHash).Replace("-", "").ToLowerInvariant();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifica attivazione licenza dato codice impiego
|
||||
/// </summary>
|
||||
@@ -741,29 +779,7 @@ namespace GPW_data
|
||||
return await Task.FromResult(answ);
|
||||
}
|
||||
|
||||
public static bool userPayloadOk(int idxDip)
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
// recupero riga dip
|
||||
var userTab = DataProxy.DP.taDipendenti.getByIdx(idxDip);
|
||||
if (userTab != null && userTab.Count > 0)
|
||||
{
|
||||
var userRow = userTab[0];
|
||||
// calcolo suo codice...
|
||||
var codImpCurr = DataProxy.DP.hashCodImpiego(userRow);
|
||||
// cerco dip tra elenco json
|
||||
var userLocalList = ListaAttivazioni;
|
||||
var foundRec = userLocalList.Where(x => x.CodImpiego == codImpCurr);
|
||||
answ = foundRec.Count() > 0;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
|
||||
return answ;
|
||||
}
|
||||
public static bool userPayloadOk(int idxDip) => _userPayloadOk(idxDip);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user