Fix api report applicazioni con enigma/payload random + check licenze impiegate
This commit is contained in:
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Controller livello APPLICAZIONI
|
||||
/// </summary>
|
||||
[Route("api/applicazioni")]
|
||||
[ApiController]
|
||||
public class ApplicazioniController : ControllerBase
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
/// <summary>
|
||||
/// Classe per logging
|
||||
/// </summary>
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Init generico
|
||||
/// </summary>
|
||||
/// <param name="DataService"></param>
|
||||
public ApplicazioniController(ApiDataService DataService)
|
||||
{
|
||||
_DataService = DataService;
|
||||
Log.Info("Avviata classe ApplicazioniController");
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
/// <summary>
|
||||
/// Dataservice x accesso DB
|
||||
/// </summary>
|
||||
protected ApiDataService _DataService { get; set; }
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Recupera elenco dati licenza Applicativi (id licenza + num utenze) dati cliente + programma
|
||||
/// GET api/install/list/id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}")]
|
||||
public async Task<List<DB.DTO.ApplicativoDTO>> Get(string id, string CodApp)
|
||||
{
|
||||
var result = await _DataService.ApplicativiByCliente(id, CodApp, true);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera elenco dati licenza (id + num utenze) dati cliente + programma
|
||||
/// GET api/install/list/id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list/{id}")]
|
||||
public async Task<List<DB.DTO.ApplicativoDTO>> Get(string id, string CodApp)
|
||||
{
|
||||
var result = await _DataService.ApplicativiByCliente(id, CodApp);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -62,13 +62,13 @@ namespace LiMan.APi.Data
|
||||
/// </summary>
|
||||
/// <param name="CodInst"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<DB.DTO.ApplicativoDTO>> ApplicativiByCliente(string CodInst, string CodApp)
|
||||
public async Task<List<DB.DTO.ApplicativoDTO>> ApplicativiByCliente(string CodInst, string CodApp, bool hideData)
|
||||
{
|
||||
List<DB.DTO.ApplicativoDTO> dbResult = new List<DB.DTO.ApplicativoDTO>();
|
||||
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");
|
||||
|
||||
+30
-9
@@ -4,6 +4,35 @@
|
||||
<name>LiMan.APi</name>
|
||||
</assembly>
|
||||
<members>
|
||||
<member name="T:LiMan.APi.Controllers.ApplicazioniController">
|
||||
<summary>
|
||||
Controller livello APPLICAZIONI
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:LiMan.APi.Controllers.ApplicazioniController.Log">
|
||||
<summary>
|
||||
Classe per logging
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:LiMan.APi.Controllers.ApplicazioniController.#ctor(LiMan.APi.Data.ApiDataService)">
|
||||
<summary>
|
||||
Init generico
|
||||
</summary>
|
||||
<param name="DataService"></param>
|
||||
</member>
|
||||
<member name="P:LiMan.APi.Controllers.ApplicazioniController._DataService">
|
||||
<summary>
|
||||
Dataservice x accesso DB
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:LiMan.APi.Controllers.ApplicazioniController.Get(System.String,System.String)">
|
||||
<summary>
|
||||
Recupera elenco dati licenza Applicativi (id licenza + num utenze) dati cliente + programma
|
||||
GET api/install/list/id
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:LiMan.APi.Controllers.InstallazioniController">
|
||||
<summary>
|
||||
Controller livello INSTALLAZIONI
|
||||
@@ -33,14 +62,6 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:LiMan.APi.Controllers.InstallazioniController.Get(System.String,System.String)">
|
||||
<summary>
|
||||
Recupera elenco dati licenza (id + num utenze) dati cliente + programma
|
||||
GET api/install/list/id
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:LiMan.APi.Data.ApiDataService">
|
||||
<summary>
|
||||
Classe astrazione accesso dati
|
||||
@@ -53,7 +74,7 @@
|
||||
<param name="configuration"></param>
|
||||
<param name="logger"></param>
|
||||
</member>
|
||||
<member name="M:LiMan.APi.Data.ApiDataService.ApplicativiByCliente(System.String,System.String)">
|
||||
<member name="M:LiMan.APi.Data.ApiDataService.ApplicativiByCliente(System.String,System.String,System.Boolean)">
|
||||
<summary>
|
||||
Elenco licenze dato cliente
|
||||
</summary>
|
||||
|
||||
@@ -55,30 +55,79 @@ namespace LiMan.DB.Controllers
|
||||
//Log.Info("Dispose di GWMSController");
|
||||
}
|
||||
|
||||
public List<ApplicativoDTO> GetApplicativiFilt(bool OnlyActive, string CodApp, string CodInst)
|
||||
public List<ApplicativoDTO> GetApplicativiFilt(bool OnlyActive, string CodApp, string CodInst, bool hideData)
|
||||
{
|
||||
List<ApplicativoDTO> dbResult = new List<ApplicativoDTO>();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user