diff --git a/LiMan.Api/Controllers/ApplicazioniController.cs b/LiMan.Api/Controllers/ApplicazioniController.cs new file mode 100644 index 0000000..4148768 --- /dev/null +++ b/LiMan.Api/Controllers/ApplicazioniController.cs @@ -0,0 +1,68 @@ +using LiMan.APi.Data; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using NLog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LiMan.APi.Controllers +{ + /// + /// Controller livello APPLICAZIONI + /// + [Route("api/applicazioni")] + [ApiController] + public class ApplicazioniController : ControllerBase + { + #region Private Fields + + /// + /// Classe per logging + /// + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + #endregion Private Fields + + #region Public Constructors + + /// + /// Init generico + /// + /// + public ApplicazioniController(ApiDataService DataService) + { + _DataService = DataService; + Log.Info("Avviata classe ApplicazioniController"); + } + + #endregion Public Constructors + + #region Protected Properties + + /// + /// Dataservice x accesso DB + /// + protected ApiDataService _DataService { get; set; } + + #endregion Protected Properties + + #region Public Methods + + /// + /// Recupera elenco dati licenza Applicativi (id licenza + num utenze) dati cliente + programma + /// GET api/install/list/id + /// + /// + /// + [HttpGet("{id}")] + public async Task> Get(string id, string CodApp) + { + var result = await _DataService.ApplicativiByCliente(id, CodApp, true); + return result; + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/LiMan.Api/Controllers/InstallazioniController.cs b/LiMan.Api/Controllers/InstallazioniController.cs index ea74006..674c8b7 100644 --- a/LiMan.Api/Controllers/InstallazioniController.cs +++ b/LiMan.Api/Controllers/InstallazioniController.cs @@ -34,7 +34,7 @@ namespace LiMan.APi.Controllers public InstallazioniController(ApiDataService DataService) { _DataService = DataService; - Log.Info("Avviata classe ParentCheckController"); + Log.Info("Avviata classe InstallazioniController"); } #endregion Public Constructors @@ -65,19 +65,6 @@ namespace LiMan.APi.Controllers return listaApp; } - /// - /// Recupera elenco dati licenza (id + num utenze) dati cliente + programma - /// GET api/install/list/id - /// - /// - /// - [HttpGet("list/{id}")] - public async Task> Get(string id, string CodApp) - { - var result = await _DataService.ApplicativiByCliente(id, CodApp); - return result; - } - #endregion Public Methods } } \ No newline at end of file diff --git a/LiMan.Api/Data/ApiDataService.cs b/LiMan.Api/Data/ApiDataService.cs index c6dc411..0c9212f 100644 --- a/LiMan.Api/Data/ApiDataService.cs +++ b/LiMan.Api/Data/ApiDataService.cs @@ -62,13 +62,13 @@ namespace LiMan.APi.Data /// /// /// - public async Task> ApplicativiByCliente(string CodInst, string CodApp) + public async Task> ApplicativiByCliente(string CodInst, string CodApp, bool hideData) { List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = dbController.GetApplicativiFilt(true, CodApp, CodInst); + dbResult = dbController.GetApplicativiFilt(true, CodApp, CodInst, hideData); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per ApplicativiByCliente: {ts.TotalMilliseconds} ms"); diff --git a/LiMan.Api/LiMan.APi.xml b/LiMan.Api/LiMan.APi.xml index c34f944..3f29a46 100644 --- a/LiMan.Api/LiMan.APi.xml +++ b/LiMan.Api/LiMan.APi.xml @@ -4,6 +4,35 @@ LiMan.APi + + + Controller livello APPLICAZIONI + + + + + Classe per logging + + + + + Init generico + + + + + + Dataservice x accesso DB + + + + + Recupera elenco dati licenza Applicativi (id licenza + num utenze) dati cliente + programma + GET api/install/list/id + + + + Controller livello INSTALLAZIONI @@ -33,14 +62,6 @@ - - - Recupera elenco dati licenza (id + num utenze) dati cliente + programma - GET api/install/list/id - - - - Classe astrazione accesso dati @@ -53,7 +74,7 @@ - + Elenco licenze dato cliente diff --git a/LiMan.DB/Controllers/DbController.cs b/LiMan.DB/Controllers/DbController.cs index b9ef5bb..42cb2fb 100644 --- a/LiMan.DB/Controllers/DbController.cs +++ b/LiMan.DB/Controllers/DbController.cs @@ -55,30 +55,79 @@ namespace LiMan.DB.Controllers //Log.Info("Dispose di GWMSController"); } - public List GetApplicativiFilt(bool OnlyActive, string CodApp, string CodInst) + public List GetApplicativiFilt(bool OnlyActive, string CodApp, string CodInst, bool hideData) { List dbResult = new List(); using (LMDbContext localDbCtx = new LMDbContext(_configuration)) { DateTime oggi = DateTime.Today; - dbResult = localDbCtx - .DbSetLicenze - .Where(x => (x.CodApp == CodApp || string.IsNullOrEmpty(CodApp)) && (x.CodInst == CodInst || string.IsNullOrEmpty(CodInst)) && (!OnlyActive || x.Scadenza > oggi)) - .OrderByDescending(o => o.Scadenza) - .Select(x => new ApplicativoDTO() + + StringBuilder sbRandEnigma = new StringBuilder(); + StringBuilder sbRandPayload = new StringBuilder(); + string stdEnigma = ""; + string stdPayLoad = ""; + DateTime stdDataEnigma = DateTime.Today; + if (hideData) { - IdxLic = x.IdxLic, - CodApp = x.CodApp, - Descrizione = x.Descrizione, - Tipo = x.Tipo, - Scadenza = x.Scadenza, - NumLicenze = x.NumLicenze, - NumLicenzeAttive = 0, - DataEnigma = x.DataEnigma, - Enigma = x.Enigma, - Payload = x.Payload - }) - .ToList(); + int numChar = 80; + Random random = new Random(); + + //random data enigma + stdDataEnigma = DateTime.Today.AddDays(random.Next(0, 15)); + + // random enigma + for (int i = 0; i < numChar; i++) + { + // Generate floating point numbers + double myFloat = random.NextDouble(); + // Generate the char using below logic + var myChar = Convert.ToChar(Convert.ToInt32(Math.Floor(25 * myFloat) + 65)); + sbRandEnigma.Append(myChar); + } + stdEnigma = $"{sbRandEnigma}"; + + // random payload + for (int i = 0; i < numChar; i++) + { + // Generate floating point numbers + double myFloat = random.NextDouble(); + // Generate the char using below logic + var myChar = Convert.ToChar(Convert.ToInt32(Math.Floor(25 * myFloat) + 65)); + sbRandPayload.Append(myChar); + } + stdPayLoad = $"{sbRandPayload}"; + } + + // conteggio preliminare licenze impiegate + var countSubLic = localDbCtx + .DbSetSubLicenze + .GroupBy(x => x.IdxLic) + .Select(g => new + { + IdxLic = g.Key, + NumLic = g.Count() + }); + + // calcolo DTO applicativi + dbResult = localDbCtx + .DbSetLicenze + .Where(x => (x.CodApp == CodApp || string.IsNullOrEmpty(CodApp)) && (x.CodInst == CodInst || string.IsNullOrEmpty(CodInst)) && (!OnlyActive || x.Scadenza > oggi)) + .OrderByDescending(o => o.Scadenza) + .Select(x => new ApplicativoDTO() + { + IdxLic = x.IdxLic, + CodApp = x.CodApp, + CodInst = x.CodInst, + Descrizione = x.Descrizione, + Tipo = x.Tipo, + Scadenza = x.Scadenza, + NumLicenze = x.NumLicenze, + NumLicenzeAttive = countSubLic.Where(s => s.IdxLic == x.IdxLic).Select(c => c.NumLic).FirstOrDefault(), + DataEnigma = hideData ? stdDataEnigma : x.DataEnigma, + Enigma = hideData ? stdEnigma : x.Enigma, + Payload = hideData ? stdPayLoad : x.Payload + }) + .ToList(); } return dbResult; } diff --git a/LiMan.DB/DTO/ApplicativoDTO.cs b/LiMan.DB/DTO/ApplicativoDTO.cs index a8f8849..8234de8 100644 --- a/LiMan.DB/DTO/ApplicativoDTO.cs +++ b/LiMan.DB/DTO/ApplicativoDTO.cs @@ -16,6 +16,7 @@ namespace LiMan.DB.DTO public int IdxLic { get; set; } = 0; public string CodApp { get; set; } = ""; + public string CodInst { get; set; } = ""; public string Descrizione { get; set; } = ""; public TipoLicenza Tipo { get; set; } = TipoLicenza.ND;