diff --git a/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx b/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx
index 5a9414f..67e0a22 100644
--- a/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx
+++ b/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx
@@ -22,6 +22,9 @@
diff --git a/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.cs b/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.cs
index b1794c3..da16038 100644
--- a/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.cs
+++ b/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.cs
@@ -57,6 +57,11 @@ namespace GPW_Admin.WebUserControls
get => licenzeGPW.licenzeOnline;
}
+ public int numTickets
+ {
+ get => licenzeGPW.numTickets;
+ }
+
public bool showAll
{
get
@@ -72,24 +77,106 @@ namespace GPW_Admin.WebUserControls
#endregion Public Properties
- #region Private Methods
+ #region Public Methods
- private static void fullRefresh()
+ ///
+ /// Verifica licenza (se sia libera x modifca o prima associazione)
+ ///
+ ///
+ ///
+ public bool checkFreeEdit(object idxDip)
{
- // eseguo call di recupero da online
- bool refreshApp = licenzeGPW.RefreshAppInfo().Result;
- bool refreshAct = licenzeGPW.RefreshActInfo().Result;
- bool refreshPayload = licenzeGPW.RefreshPayload().Result;
- //bool refreshLic = licenzeGPW.RefreshLicInfo().Result;
+ bool answ = false;
+ int IdxDip = 0;
+ int.TryParse($"{idxDip}", out IdxDip);
+ if (IdxDip > 0)
+ {
+ var localUserList = DataProxy.DP.taDipendenti.getAttivi(false);
+ // cerco!
+ var currUser = localUserList.Where(x => x.idxDipendente == IdxDip).FirstOrDefault();
+
+ // verifico SE sia disponibile licenza...
+ var activationsList = licenzeGPW.ListaAttivazioni;
+ var currHash = DataProxy.DP.hashCodImpiego(currUser);
+ var currAct = activationsList.Where(x => x.CodImpiego == currHash).FirstOrDefault();
+ // se NON c'è licenza è ok (editabile)
+ answ = (currAct == null);
+ // ora verifico: se NON ha licenza OK, altrimenti deve essere scaduta...
+ if (!answ)
+ {
+ answ = currAct.VetoUnlock <= DateTime.Today;
+ }
+ }
+ return answ;
}
- private void fixVisibility()
+ ///
+ /// Verifica licenza (se sia validata/associata a quelle in memoria)
+ ///
+ ///
+ ///
+ public bool checkLic(object idxDip)
{
- lbtFixMissing.Visible = (numLicenzeOnline == numLicenze && attivazioniOnline != utentiAttivi);
- grView.PageSize = utils.pageSize;
+ bool answ = false;
+ int IdxDip = 0;
+ int.TryParse($"{idxDip}", out IdxDip);
+ if (IdxDip > 0)
+ {
+ var localUserList = DataProxy.DP.taDipendenti.getAttivi(false);
+ // cerco!
+ var currUser = localUserList.Where(x => x.idxDipendente == IdxDip).FirstOrDefault();
+
+ // verifico SE sia disponibile licenza...
+ var activationsList = licenzeGPW.ListaAttivazioni;
+ var currHash = DataProxy.DP.hashCodImpiego(currUser);
+ var currAct = activationsList.Where(x => x.CodImpiego == currHash).FirstOrDefault();
+ answ = (currAct != null && currAct.CodImpiego == currHash);
+ }
+ return answ;
}
- #endregion Private Methods
+ ///
+ /// determina se sia eliminabile il record (=non usato)
+ ///
+ ///
+ ///
+ public bool delEnabled(object idxObj)
+ {
+ bool answ = true;
+ // solo se ha diritti scrittura controllo
+ if (idxObj != null)
+ {
+ int trovati = 0;
+ int idxDip = 0;
+ _ = int.TryParse(idxObj.ToString(), out idxDip);
+ trovati = DataProxy.DP.taTimb.getLastByDip(idxDip).Count;
+ // controllo se ci sono record correlati...
+ if (trovati > 0)
+ {
+ answ = false;
+ }
+ }
+ return answ;
+ }
+
+ public void doUpdate()
+ {
+ fullRefresh();
+ fixVisibility();
+ grView.DataBind();
+ }
+
+ ///
+ /// resetta la selezione dei valori in caso di modifiche su altri controlli
+ ///
+ public void resetSelezione()
+ {
+ grView.SelectedIndex = -1;
+ grView.DataBind();
+ raiseReset();
+ }
+
+ #endregion Public Methods
#region Protected Methods
@@ -257,6 +344,12 @@ namespace GPW_Admin.WebUserControls
isTicketReq = false;
}
+ protected void lbtShowTickets_Click(object sender, EventArgs e)
+ {
+ // mostro blocco tickets
+ // !!! FARE FixMe !!! TODO
+ }
+
///
/// Richiesta inserimento ticket supporto
///
@@ -376,105 +469,23 @@ namespace GPW_Admin.WebUserControls
#endregion Protected Methods
- #region Public Methods
+ #region Private Methods
- ///
- /// Verifica licenza (se sia libera x modifca o prima associazione)
- ///
- ///
- ///
- public bool checkFreeEdit(object idxDip)
+ private static void fullRefresh()
{
- bool answ = false;
- int IdxDip = 0;
- int.TryParse($"{idxDip}", out IdxDip);
- if (IdxDip > 0)
- {
- var localUserList = DataProxy.DP.taDipendenti.getAttivi(false);
- // cerco!
- var currUser = localUserList.Where(x => x.idxDipendente == IdxDip).FirstOrDefault();
-
- // verifico SE sia disponibile licenza...
- var activationsList = licenzeGPW.ListaAttivazioni;
- var currHash = DataProxy.DP.hashCodImpiego(currUser);
- var currAct = activationsList.Where(x => x.CodImpiego == currHash).FirstOrDefault();
- // se NON c'è licenza è ok (editabile)
- answ = (currAct == null);
- // ora verifico: se NON ha licenza OK, altrimenti deve essere scaduta...
- if (!answ)
- {
- answ = currAct.VetoUnlock <= DateTime.Today;
- }
- }
- return answ;
+ // eseguo call di recupero da online
+ bool refreshApp = licenzeGPW.RefreshAppInfo().Result;
+ bool refreshAct = licenzeGPW.RefreshActInfo().Result;
+ bool refreshPayload = licenzeGPW.RefreshPayload().Result;
+ //bool refreshLic = licenzeGPW.RefreshLicInfo().Result;
}
- ///
- /// Verifica licenza (se sia validata/associata a quelle in memoria)
- ///
- ///
- ///
- public bool checkLic(object idxDip)
+ private void fixVisibility()
{
- bool answ = false;
- int IdxDip = 0;
- int.TryParse($"{idxDip}", out IdxDip);
- if (IdxDip > 0)
- {
- var localUserList = DataProxy.DP.taDipendenti.getAttivi(false);
- // cerco!
- var currUser = localUserList.Where(x => x.idxDipendente == IdxDip).FirstOrDefault();
-
- // verifico SE sia disponibile licenza...
- var activationsList = licenzeGPW.ListaAttivazioni;
- var currHash = DataProxy.DP.hashCodImpiego(currUser);
- var currAct = activationsList.Where(x => x.CodImpiego == currHash).FirstOrDefault();
- answ = (currAct != null && currAct.CodImpiego == currHash);
- }
- return answ;
+ lbtFixMissing.Visible = (numLicenzeOnline == numLicenze && attivazioniOnline != utentiAttivi);
+ grView.PageSize = utils.pageSize;
}
- ///
- /// determina se sia eliminabile il record (=non usato)
- ///
- ///
- ///
- public bool delEnabled(object idxObj)
- {
- bool answ = true;
- // solo se ha diritti scrittura controllo
- if (idxObj != null)
- {
- int trovati = 0;
- int idxDip = 0;
- _ = int.TryParse(idxObj.ToString(), out idxDip);
- trovati = DataProxy.DP.taTimb.getLastByDip(idxDip).Count;
- // controllo se ci sono record correlati...
- if (trovati > 0)
- {
- answ = false;
- }
- }
- return answ;
- }
-
- public void doUpdate()
- {
- fullRefresh();
- fixVisibility();
- grView.DataBind();
- }
-
- ///
- /// resetta la selezione dei valori in caso di modifiche su altri controlli
- ///
- public void resetSelezione()
- {
- grView.SelectedIndex = -1;
- grView.DataBind();
- raiseReset();
- }
-
- #endregion Public Methods
+ #endregion Private Methods
}
}
\ No newline at end of file
diff --git a/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.designer.cs b/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.designer.cs
index 991d9d7..bd2806c 100644
--- a/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.designer.cs
+++ b/GPW_Admin/WebUserControls/mod_adminDipendenti.ascx.designer.cs
@@ -1,10 +1,10 @@
//------------------------------------------------------------------------------
-//
-// This code was generated by a tool.
+//
+// Codice generato da uno strumento.
//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-//
+// Le modifiche a questo file possono causare un comportamento non corretto e verranno perse se
+// il codice viene rigenerato.
+//
//------------------------------------------------------------------------------
namespace GPW_Admin.WebUserControls
@@ -15,101 +15,110 @@ namespace GPW_Admin.WebUserControls
{
///
- /// divDB control.
+ /// Controllo divDB.
///
///
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
+ /// Campo generato automaticamente.
+ /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
///
protected global::System.Web.UI.HtmlControls.HtmlGenericControl divDB;
///
- /// divOnline control.
+ /// Controllo divOnline.
///
///
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
+ /// Campo generato automaticamente.
+ /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
///
protected global::System.Web.UI.HtmlControls.HtmlGenericControl divOnline;
///
- /// lbtRefresh control.
+ /// Controllo lbtRefresh.
///
///
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
+ /// Campo generato automaticamente.
+ /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
///
protected global::System.Web.UI.WebControls.LinkButton lbtRefresh;
///
- /// lbtFixMissing control.
+ /// Controllo lbtFixMissing.
///
///
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
+ /// Campo generato automaticamente.
+ /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
///
protected global::System.Web.UI.WebControls.LinkButton lbtFixMissing;
///
- /// chkshowAll control.
+ /// Controllo lbtShowTickets.
///
///
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
+ /// Campo generato automaticamente.
+ /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
+ ///
+ protected global::System.Web.UI.WebControls.LinkButton lbtShowTickets;
+
+ ///
+ /// Controllo chkshowAll.
+ ///
+ ///
+ /// Campo generato automaticamente.
+ /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
///
protected global::System.Web.UI.WebControls.CheckBox chkshowAll;
///
- /// grView control.
+ /// Controllo grView.
///
///
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
+ /// Campo generato automaticamente.
+ /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
///
protected global::System.Web.UI.WebControls.GridView grView;
///
- /// ods control.
+ /// Controllo ods.
///
///
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
+ /// Campo generato automaticamente.
+ /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
///
protected global::System.Web.UI.WebControls.ObjectDataSource ods;
///
- /// lblNumRec control.
+ /// Controllo lblNumRec.
///
///
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
+ /// Campo generato automaticamente.
+ /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
///
protected global::System.Web.UI.WebControls.Label lblNumRec;
///
- /// odsOrario control.
+ /// Controllo odsOrario.
///
///
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
+ /// Campo generato automaticamente.
+ /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
///
protected global::System.Web.UI.WebControls.ObjectDataSource odsOrario;
///
- /// odsGruppi control.
+ /// Controllo odsGruppi.
///
///
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
+ /// Campo generato automaticamente.
+ /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
///
protected global::System.Web.UI.WebControls.ObjectDataSource odsGruppi;
///
- /// hfReqTicket control.
+ /// Controllo hfReqTicket.
///
///
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
+ /// Campo generato automaticamente.
+ /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
///
protected global::System.Web.UI.WebControls.HiddenField hfReqTicket;
}
diff --git a/GPW_Data/licenzeGPW.cs b/GPW_Data/licenzeGPW.cs
index cacfaed..159a475 100644
--- a/GPW_Data/licenzeGPW.cs
+++ b/GPW_Data/licenzeGPW.cs
@@ -32,74 +32,12 @@ namespace GPW_data
private static string rkeyLicInfo = memLayer.ML.redHash($"LiMan:LicInfo");
private static string rkeyPayload = memLayer.ML.redHash($"LiMan:Payload");
+ private static string rkeyTickets = memLayer.ML.redHash($"LiMan:Tickets");
private static string rkeyVetoRefPayL = memLayer.ML.redHash($"LiMan:VetoRefPayL");
#endregion Private Fields
- #region Private Properties
-
- ///
- /// Info applicativo corrente (da cache con eventuale recupero online...)
- ///
- private 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
infoList = JsonConvert.DeserializeObject>(rawData);
- if (infoList != null)
- {
- answ = infoList.OrderByDescending(x => x.Scadenza).FirstOrDefault();
- }
- }
- else
- {
- answ = JsonConvert.DeserializeObject(rawData);
- }
- }
- catch
- { }
- }
- return answ;
- }
- }
-
- ///
- /// Durata cache statica locale dati licenza, random circa 1 h
- ///
- private static int LicCacheTTL
- {
- get
- {
- Random rndGen = new Random();
- return rndGen.Next(50, 70) * 60;
- }
- }
-
- private static LiManObj.ApplicativoDTO myInfoApplicativo { get; set; }
-
- #endregion Private Properties
-
#region Public Properties
///
@@ -162,11 +100,21 @@ namespace GPW_data
///
public static string modApp => _modApp();
+ ///
+ /// numero di Ticket APERTI
+ ///
+ public static int numTickets => getNumTickets().Result;
+
///
/// scadenza licenze x applicativo
///
public static DateTime scadenzaLicenza => _scadenzaLicenza();
+ ///
+ /// Elenco dei Ticket da info online
+ ///
+ public static List TicketsList => getTickets().Result;
+
///
/// numero di utenti attivi
///
@@ -174,329 +122,68 @@ namespace GPW_data
#endregion Public Properties
- #region Private Methods
+ #region Private Properties
///
- /// numero di licenze attive da info online
+ /// Info applicativo corrente (da cache con eventuale recupero online...)
///
- private static int _attivazioniOnline()
+ private static LiManObj.ApplicativoDTO InfoApplicativo
{
- return InfoApplicativo.NumLicenzeAttive;
- }
-
- ///
- /// chaive licenza
- ///
- private static string _authKey()
- {
- string answ = "";
- // controllo su db...
- try
+ get
{
- answ = DataProxy.DP.taAKV.getByKey(installazione)[0].valString;
- }
- catch
- { }
- return answ;
- }
-
- ///
- /// verifica se numero licenze copre utenti attivi...
- ///
- 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;
- }
-
- ///
- /// verifica se il payload delle licenze attivate sia valido (con server online)
- ///
- private static bool _checkPayload()
- {
- 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;
- }
-
- ///
- /// nome installazione sw
- ///
- 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;
- }
-
- ///
- /// numero di licenze attive sul sw (SE CONFORMI A CHIAVE)
- ///
- 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;
- }
-
- ///
- /// numero di licenze attive su DB (NON verificate!)
- ///
- private static int _licenzeDb()
- {
- int answ = 0;
- // controllo su db...
- try
- {
- answ = DataProxy.DP.taAKV.getByKey(installazione)[0].valInt;
- }
- catch
- { }
- return answ;
- }
-
- ///
- /// numero di licenze disponibili da info online
- ///
- private static int _licenzeOnline()
- {
- return InfoApplicativo.NumLicenze;
- }
-
- ///
- /// Elenco attivazioni attuali
- ///
- private static List _ListaAttivazioni()
- {
- List answ = new List();
- // 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>(rawData);
- }
- return answ;
- }
-
- ///
- /// Chiave Licenza Master
- ///
- 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;
- }
-
- ///
- /// modalità applicazione (pagina test.aspx)
- ///
- 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;
- }
-
- ///
- /// scadenza licenze x applicativo
- ///
- 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;
- }
-
- ///
- /// numero di utenti attivi
- ///
- private static int _utentiAttivi()
- {
- int answ = DataProxy.DP.taDipendenti.getAttivi(false).Count;
- return answ;
- }
-
- ///
- /// Calcolo Hash data stringa input
- ///
- ///
- ///
- 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...
- StringBuilder sb = new StringBuilder();
-
- // ciclo tutti gli utenti attivi
- var localUserList = DataProxy.DP.taDipendenti.getAttivi(false);
- List codiciImpiego = new List();
- // ciclo x ogni dip attivo...
- foreach (var item in localUserList)
- {
- codiciImpiego.Add(DataProxy.DP.hashCodImpiego(item));
- }
- // riordino
- var ordList = codiciImpiego.OrderBy(x => x);
- foreach (var item in ordList)
- {
- sb.AppendLine(item);
- }
- string rawData = sb.ToString();
-
- // hashing!
- using (var md5 = MD5.Create())
- {
- byte[] InputBytes = Encoding.UTF8.GetBytes(rawData);
- var byteHash = md5.ComputeHash(InputBytes);
- answ = BitConverter.ToString(byteHash).Replace("-", "").ToLowerInvariant();
- }
- return answ;
- }
-
- private static void tryCheckPayloadOnline(ref bool answ, ref string currPayload)
- {
- try
- {
- // cerco payload licenze locale...
- currPayload = memLayer.ML.getRSV(rkeyPayload);
+ LiManObj.ApplicativoDTO answ = new LiManObj.ApplicativoDTO();
+ // cerco da cache
+ string rawData = memLayer.ML.getRSV(rkeyLicInfo);
// se no ci fosse --> refresh online!
- if (string.IsNullOrEmpty(currPayload))
+ if (string.IsNullOrEmpty(rawData))
{
- currPayload = calcPayload();
- memLayer.ML.setRSV(rkeyPayload, currPayload, LicCacheTTL);
+ var fatto = RefreshAppInfo().Result;
+ if (fatto)
+ {
+ rawData = memLayer.ML.getRSV(rkeyLicInfo);
+ }
}
- // confronto payload calc con quello della licenza
- var currInfo = InfoApplicativo;
- answ = (InfoApplicativo.Payload == currPayload);
- // se fallisce --> resetto payload calcolato
- if (!answ)
+ if (!string.IsNullOrEmpty(rawData))
{
- memLayer.ML.setRSV(rkeyAppInfo, "", 1);
- memLayer.ML.setRSV(rkeyPayload, "", 1);
+ try
+ {
+ // verifico se ho 1 risultato o molti...se inizia per "[" è molti
+ if (rawData.StartsWith("["))
+ {
+ // POTREBBE darmi + di 1 risultato, prendo + recente...
+ List infoList = JsonConvert.DeserializeObject>(rawData);
+ if (infoList != null)
+ {
+ answ = infoList.OrderByDescending(x => x.Scadenza).FirstOrDefault();
+ }
+ }
+ else
+ {
+ answ = JsonConvert.DeserializeObject(rawData);
+ }
+ }
+ catch
+ { }
}
+ return answ;
}
- catch
- { }
}
- #endregion Private Methods
+ ///
+ /// Durata cache statica locale dati licenza, random circa 1 h
+ ///
+ private static int LicCacheTTL
+ {
+ get
+ {
+ Random rndGen = new Random();
+ return rndGen.Next(50, 70) * 60;
+ }
+ }
+
+ private static LiManObj.ApplicativoDTO myInfoApplicativo { get; set; }
+
+ #endregion Private Properties
#region Public Methods
@@ -911,5 +598,377 @@ namespace GPW_data
public static bool userPayloadOk(int idxDip) => _userPayloadOk(idxDip);
#endregion Public Methods
+
+ #region Private Methods
+
+ ///
+ /// numero di licenze attive da info online
+ ///
+ private static int _attivazioniOnline()
+ {
+ return InfoApplicativo.NumLicenzeAttive;
+ }
+
+ ///
+ /// chaive licenza
+ ///
+ private static string _authKey()
+ {
+ string answ = "";
+ // controllo su db...
+ try
+ {
+ answ = DataProxy.DP.taAKV.getByKey(installazione)[0].valString;
+ }
+ catch
+ { }
+ return answ;
+ }
+
+ ///
+ /// verifica se numero licenze copre utenti attivi...
+ ///
+ 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;
+ }
+
+ ///
+ /// verifica se il payload delle licenze attivate sia valido (con server online)
+ ///
+ private static bool _checkPayload()
+ {
+ 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;
+ }
+
+ ///
+ /// nome installazione sw
+ ///
+ 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;
+ }
+
+ ///
+ /// numero di licenze attive sul sw (SE CONFORMI A CHIAVE)
+ ///
+ 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;
+ }
+
+ ///
+ /// numero di licenze attive su DB (NON verificate!)
+ ///
+ private static int _licenzeDb()
+ {
+ int answ = 0;
+ // controllo su db...
+ try
+ {
+ answ = DataProxy.DP.taAKV.getByKey(installazione)[0].valInt;
+ }
+ catch
+ { }
+ return answ;
+ }
+
+ ///
+ /// numero di licenze disponibili da info online
+ ///
+ private static int _licenzeOnline()
+ {
+ return InfoApplicativo.NumLicenze;
+ }
+
+ ///
+ /// Elenco attivazioni attuali
+ ///
+ private static List _ListaAttivazioni()
+ {
+ List answ = new List();
+ // 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>(rawData);
+ }
+ return answ;
+ }
+
+ ///
+ /// Chiave Licenza Master
+ ///
+ 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;
+ }
+
+ ///
+ /// modalità applicazione (pagina test.aspx)
+ ///
+ 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;
+ }
+
+ ///
+ /// scadenza licenze x applicativo
+ ///
+ 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;
+ }
+
+ ///
+ /// numero di utenti attivi
+ ///
+ private static int _utentiAttivi()
+ {
+ int answ = DataProxy.DP.taDipendenti.getAttivi(false).Count;
+ return answ;
+ }
+
+ ///
+ /// Calcolo Hash data stringa input
+ ///
+ ///
+ ///
+ 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...
+ StringBuilder sb = new StringBuilder();
+
+ // ciclo tutti gli utenti attivi
+ var localUserList = DataProxy.DP.taDipendenti.getAttivi(false);
+ List codiciImpiego = new List();
+ // ciclo x ogni dip attivo...
+ foreach (var item in localUserList)
+ {
+ codiciImpiego.Add(DataProxy.DP.hashCodImpiego(item));
+ }
+ // riordino
+ var ordList = codiciImpiego.OrderBy(x => x);
+ foreach (var item in ordList)
+ {
+ sb.AppendLine(item);
+ }
+ string rawData = sb.ToString();
+
+ // hashing!
+ using (var md5 = MD5.Create())
+ {
+ byte[] InputBytes = Encoding.UTF8.GetBytes(rawData);
+ var byteHash = md5.ComputeHash(InputBytes);
+ answ = BitConverter.ToString(byteHash).Replace("-", "").ToLowerInvariant();
+ }
+ return answ;
+ }
+
+ ///
+ /// Recupera num ticket da sistema LiMan online
+ ///
+ ///
+ private static async Task getNumTickets()
+ {
+ var elenco = await getTickets();
+ var openTickets = elenco
+ .Where(x => x.Status <= StatoRichiesta.Valutazione)
+ .ToList();
+ return await Task.FromResult(openTickets.Count);
+ }
+
+ ///
+ /// Recupera num ticket da sistema LiMan online
+ ///
+ ///
+ private static async Task> getTickets()
+ {
+ List answ = new List();
+ // cerco in cache locale...
+ string rawData = memLayer.ML.getRSV(rkeyTickets);
+ if (!string.IsNullOrEmpty(rawData))
+ {
+ answ = JsonConvert.DeserializeObject>(rawData);
+ }
+ else
+ {
+ // cerco online
+ RestClient client = new RestClient(apiUrl);
+ //client.Authenticator = new HttpBasicAuthenticator("username", "password");
+ string MKeyEnc = HttpUtility.UrlEncode(MasterKey);
+ var request = new RestRequest($"/api/ticket/{installazione}?CodApp={applicazione}?Chiave={MKeyEnc}", DataFormat.Json);
+ var response = client.Get(request);
+ // controllo risposta
+ if (response.StatusCode == System.Net.HttpStatusCode.OK)
+ {
+ // salvo in redis contenuto serializzato
+ rawData = response.Content;
+ // deserializzo
+ answ = JsonConvert.DeserializeObject>(rawData);
+ // salvo in redis per TTL std
+ memLayer.ML.setRSV(rkeyTickets, rawData, 60);
+ }
+ }
+ return await Task.FromResult(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
+ var currInfo = InfoApplicativo;
+ answ = (InfoApplicativo.Payload == currPayload);
+ // se fallisce --> resetto payload calcolato
+ if (!answ)
+ {
+ memLayer.ML.setRSV(rkeyAppInfo, "", 1);
+ memLayer.ML.setRSV(rkeyPayload, "", 1);
+ }
+ }
+ catch
+ { }
+ }
+
+ #endregion Private Methods
}
}
\ No newline at end of file