SPEC:
- aggiunta pagina operatori - completato fix
This commit is contained in:
@@ -18,11 +18,12 @@ namespace MP.AppAuth
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
[Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. Connection string can be adapted as pleased.")]
|
||||
[Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. DbContextOptions must be supplied.")]
|
||||
public MoonProContext()
|
||||
{
|
||||
}
|
||||
|
||||
[Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. DbContextOptions must be supplied.")]
|
||||
public MoonProContext(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace MP.Core
|
||||
|
||||
public const string redisAnagGruppi = redisBaseAddr + "Cache:AnagGruppi";
|
||||
public const string redisAnagStati = redisBaseAddr + "Cache:AnagStati";
|
||||
public const string redisAnagGruppiOpr = redisBaseAddr + "Cache:GrpByOpr";
|
||||
|
||||
public const string redisArtByDossier = redisBaseAddr + "Cache:ArtByDossier";
|
||||
public const string redisArtList = redisBaseAddr + "Cache:ArtList";
|
||||
|
||||
@@ -15,15 +15,30 @@ namespace MP.Data.Controllers
|
||||
{
|
||||
public class MpIocController
|
||||
{
|
||||
protected readonly IDbContextFactory<MoonProContext> _ctxFactory;
|
||||
protected readonly IDbContextFactory<MoonPro_FluxContext> _ctxFactoryFL;
|
||||
#region Public Constructors
|
||||
|
||||
public MpIocController(IConfiguration configuration)
|
||||
public MpIocController(
|
||||
IConfiguration configuration,
|
||||
IDbContextFactory<MoonProContext> ctxFactory,
|
||||
IDbContextFactory<MoonPro_FluxContext> ctxFactoryFL)
|
||||
{
|
||||
_configuration = configuration;
|
||||
string connStr = _configuration.GetConnectionString("MP.Data");
|
||||
#if false
|
||||
_configuration = configuration;
|
||||
#endif
|
||||
_ctxFactory = ctxFactory;
|
||||
_ctxFactoryFL = ctxFactoryFL;
|
||||
#if false
|
||||
string connStr = configuration.GetConnectionString("MP.Data");
|
||||
options = new DbContextOptionsBuilder<MoonProContext>()
|
||||
.UseSqlServer(connStr)
|
||||
.Options;
|
||||
string connStrFlux = configuration.GetConnectionString("MP.Flux");
|
||||
optionsFlux = new DbContextOptionsBuilder<MoonPro_FluxContext>()
|
||||
.UseSqlServer(connStrFlux)
|
||||
.Options;
|
||||
#endif
|
||||
Log.Info("Avviata classe MpIocController");
|
||||
}
|
||||
|
||||
@@ -43,7 +58,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AlarmLogInsertAsync(DateTime dtRif, string machineId, string memAddress, int memIndex, int statusVal, string valDecoded)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var DtRif = new SqlParameter("@DtRif", dtRif);
|
||||
var MachineId = new SqlParameter("@MachineId", machineId);
|
||||
@@ -63,7 +78,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<AnagStatiModel>> AnagStatiGetAllAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var dbResult = await dbCtx
|
||||
.DbSetAnagStati
|
||||
@@ -81,7 +96,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<AnagArticoliModel>> ArticoliGetLastByMaccAsync(string idxMacc)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc);
|
||||
var dbResult = await dbCtx
|
||||
@@ -107,7 +122,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AutoStartOdlAsync(int idxOdl, int MatrOpr, string idxMacchina, decimal tCRich, int pzPallet, string note, bool startNewOdl, int qtyRich, string keyRich)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxOdl = new SqlParameter("@idxOdl ", idxOdl);
|
||||
var MatrApp = new SqlParameter("@MatrApp ", MatrOpr);
|
||||
@@ -138,7 +153,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> CheckCambiaStatoBatchAsync(tipoInputEvento tipoInput, string IdxMacchina, DateTime InizioStato, int IdxTipo, string CodArt, string Value, int MatrOpr, string pallet)
|
||||
{
|
||||
await using var dbCtx = new MoonProContext(options);
|
||||
await using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
//await using var tx = await dbCtx.Database.BeginTransactionAsync();
|
||||
|
||||
try
|
||||
@@ -224,7 +239,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ConfermaProdMacchinaAsync(string idxMacchina, int modoConfProd, int numPzConfermati, int numPzScarto, DateTime DataOraApp, int MatrOpr)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var DataOra = new SqlParameter("@DataOra ", DateTime.Now);
|
||||
@@ -267,7 +282,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ConfermaProdMacchinaFullAsync(string idxMacchina, int modoConfProd, int numPzConfermati, int numPzLasciati, int numPzScarto, DateTime DataOraApp, int MatrOpr)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var DataOra = new SqlParameter("@DataOra ", DateTime.Now);
|
||||
@@ -306,7 +321,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<ConfFluxModel>> ConfFluxFiltAsync(string idxMacc)
|
||||
{
|
||||
using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
using var dbCtx = _ctxFactoryFL.CreateDbContext();
|
||||
|
||||
var query = dbCtx.DbSetConfFlux
|
||||
.AsNoTracking()
|
||||
@@ -326,7 +341,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<ConfigModel>> ConfigGetAllAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var dbResult = await dbCtx
|
||||
.DbSetConfig
|
||||
@@ -343,7 +358,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ConfigUpdateAsync(ConfigModel updRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
bool fatto = false;
|
||||
var dbResult = await dbCtx
|
||||
@@ -365,7 +380,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<DatiMacchineModel>> DatiMacchineGetAllAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var dbResult = await dbCtx
|
||||
.DbSetDatiMacchine
|
||||
@@ -388,7 +403,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DDB_InsStatoBatchAsync(string idxMacchina, DateTime inizioStato, int idxStato, string codArt, string value, int matrOpr, string pallet)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var InizioStato = new SqlParameter("@InizioStato", inizioStato);
|
||||
@@ -411,7 +426,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<DecNumArticoliModel>> DecNumArtGetFiltAsync(string codArt = "")
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var query = dbCtx.DbSetDecNumArt
|
||||
.AsNoTracking()
|
||||
@@ -432,17 +447,13 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<DossierModel>> DossGetLastByMaccAsync(string idxMacc)
|
||||
{
|
||||
List<DossierModel> dbResult = new();
|
||||
using (var dbCtx = new MoonPro_FluxContext(_configuration))
|
||||
{
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc);
|
||||
dbResult = await dbCtx
|
||||
.DbSetDossiers
|
||||
.FromSqlRaw("exec dbo.stp_DOSS_getLastByMacch @idxMacchina", IdxMacchina)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc);
|
||||
return await dbCtx
|
||||
.DbSetDossiers
|
||||
.FromSqlRaw("exec dbo.stp_DOSS_getLastByMacch @idxMacchina", IdxMacchina)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -452,7 +463,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> EvListInsertAsync(EventListModel newRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
dbCtx.DbSetEvList.Add(newRec);
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
@@ -467,7 +478,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<bool> EvListMicroStatoInsertAsync(MicroStatoMacchinaModel newRecMsm, EventListModel newRecEv)
|
||||
{
|
||||
// eseguo in transazione...
|
||||
await using var dbCtx = new MoonProContext(options);
|
||||
await using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
await using var tx = await dbCtx.Database.BeginTransactionAsync();
|
||||
|
||||
try
|
||||
@@ -518,18 +529,15 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<FluxLogModel>> FluxLogFirstByMaccAsync(string idxMacc, int numMax)
|
||||
{
|
||||
List<FluxLogModel> dbResult = new();
|
||||
|
||||
using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc);
|
||||
var NumMax = new SqlParameter("@numMax", numMax);
|
||||
|
||||
dbResult = await dbCtx
|
||||
.DbSetFluxLog
|
||||
.FromSqlRaw("exec dbo.stp_FL_getFirstByMacc @IdxMacchina, @numMax", IdxMacchina, NumMax)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
return dbResult;
|
||||
return await dbCtx
|
||||
.DbSetFluxLog
|
||||
.FromSqlRaw("exec dbo.stp_FL_getFirstByMacc @IdxMacchina, @numMax", IdxMacchina, NumMax)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -543,17 +551,15 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<FluxLogModel>> FluxLogGetLastFiltAsync(DateTime DtMax, DateTime DtMin, string IdxMacchina, string CodFlux, int MaxRec)
|
||||
{
|
||||
List<FluxLogModel> dbResult = new List<FluxLogModel>();
|
||||
using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
|
||||
dbResult = await dbCtx
|
||||
.DbSetFluxLog
|
||||
.AsNoTracking()
|
||||
.Where(x => (x.dtEvento >= DtMin && x.dtEvento <= DtMax) && (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina) && (CodFlux == "*" || x.CodFlux == CodFlux))
|
||||
.OrderByDescending(x => x.dtEvento)
|
||||
.Take(MaxRec)
|
||||
.ToListAsync();
|
||||
return dbResult;
|
||||
return await dbCtx
|
||||
.DbSetFluxLog
|
||||
.AsNoTracking()
|
||||
.Where(x => (x.dtEvento >= DtMin && x.dtEvento <= DtMax) && (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina) && (CodFlux == "*" || x.CodFlux == CodFlux))
|
||||
.OrderByDescending(x => x.dtEvento)
|
||||
.Take(MaxRec)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -563,15 +569,13 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> FluxLogInsertAsync(FluxLogModel newRec)
|
||||
{
|
||||
bool fatto = false;
|
||||
using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
|
||||
var currRec = dbCtx
|
||||
.DbSetFluxLog
|
||||
.Add(newRec);
|
||||
await dbCtx.SaveChangesAsync();
|
||||
.DbSetFluxLog
|
||||
.Add(newRec);
|
||||
return await dbCtx.SaveChangesAsync()>0;
|
||||
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -581,8 +585,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> FluxLogTakeSnapshotLastAsync(string idxMacc, DateTime dataInizio, DateTime dataFine)
|
||||
{
|
||||
bool fatto = false;
|
||||
using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc);
|
||||
var DataInizio = new SqlParameter("@DtMin", dataInizio);
|
||||
@@ -591,8 +594,7 @@ namespace MP.Data.Controllers
|
||||
var result = await dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRawAsync("EXEC stp_FL_TakeSnapshotLast @IdxMacchina, @DtMin, @DtMax", IdxMacchina, DataInizio, DataFine);
|
||||
fatto = result > 0;
|
||||
return fatto;
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -605,7 +607,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<bool> KeepAliveUpsertAsync(string IdxMacc, DateTime OraServer, DateTime OraMacc)
|
||||
{
|
||||
bool fatto = false;
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var currRec = await dbCtx
|
||||
.DbSetKeepAlive
|
||||
@@ -638,7 +640,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<LinkMenuModel>> ListLinkFiltAsync(string tipoLink)
|
||||
{
|
||||
List<LinkMenuModel> dbResult = new List<LinkMenuModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
dbResult = await dbCtx
|
||||
.DbSetLinkMenu
|
||||
@@ -658,7 +660,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<ListValuesModel>> ListValuesFiltAsync(string tabName, string fieldName)
|
||||
{
|
||||
List<ListValuesModel> dbResult = new List<ListValuesModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var query = dbCtx
|
||||
.DbSetListValues
|
||||
@@ -682,7 +684,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<Macchine2SlaveModel>> Macchine2SlaveAsync()
|
||||
{
|
||||
List<Macchine2SlaveModel> dbResult = new List<Macchine2SlaveModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
dbResult = await dbCtx
|
||||
.DbSetM2S
|
||||
@@ -700,7 +702,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<MacchineModel>> MacchineGetAllAsync()
|
||||
{
|
||||
List<MacchineModel> dbResult = new List<MacchineModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
dbResult = await dbCtx
|
||||
.DbSetMacchine
|
||||
@@ -712,7 +714,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<MacchineModel?> MacchineGetByIdxAsync(string IdxMacchina)
|
||||
{
|
||||
MacchineModel dbResult = null;
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
dbResult = await dbCtx
|
||||
.DbSetMacchine
|
||||
@@ -729,7 +731,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<MacchineModel>> MacchineGetFiltAsync(string codGruppo)
|
||||
{
|
||||
List<MacchineModel> dbResult = new List<MacchineModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
if (codGruppo == "*")
|
||||
{
|
||||
@@ -763,7 +765,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> MacchineUpsertAsync(MacchineModel entity)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
// Recuperiamo l'entità tracciata dal context
|
||||
var trackedEntity = await dbCtx
|
||||
@@ -791,7 +793,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<MicroStatoMacchinaModel>> MicroStatoMacchinaGetByIdxMaccAsync(string IdxMacc)
|
||||
{
|
||||
List<MicroStatoMacchinaModel> dbResult = new List<MicroStatoMacchinaModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
dbResult = await dbCtx
|
||||
.DbSetMicroStatoMacc
|
||||
@@ -809,7 +811,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<bool> MicroStatoMacchinaUpsertAsync(MicroStatoMacchinaModel newRec)
|
||||
{
|
||||
bool fatto = false;
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var actRec = await dbCtx
|
||||
.DbSetMicroStatoMacc
|
||||
@@ -842,7 +844,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<MappaStatoExplModel>> MseGetAllAsync(int maxAge = 2000)
|
||||
{
|
||||
List<MappaStatoExplModel> dbResult = new List<MappaStatoExplModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var maxAgeSec = new SqlParameter("@maxAgeSec", maxAge);
|
||||
|
||||
@@ -862,7 +864,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> OdlAutoDayGenAsync(string idxMacchina, DateTime dataInizio, DateTime dataFine, string codArticolo)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var DataInizio = new SqlParameter("@DataInizio", dataInizio);
|
||||
@@ -884,7 +886,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> OdlAutoDayGenFullAsync(string idxMacchina, DateTime dataInizio, DateTime dataFine, string codArticolo, int? pzPODL, int? pzPallet, string? keyRichiesta, int? tcAssegnato, string? codGruppo, bool flgCreaPODL, bool flgCheckTC)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var DataInizio = new SqlParameter("@DataInizio", dataInizio);
|
||||
@@ -913,7 +915,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<ODLExpModel> OdlCurrByMaccAsync(string idxMacchina)
|
||||
{
|
||||
ODLExpModel answ = new();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
// attenzione: se la stored resituisce una tabella, il primo elemento va recuperato in RAM!!!
|
||||
@@ -936,7 +938,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> OdlFixMachineSlave(string idxMacchina, int numDayPrev, int doInsert)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var idxMaccParam = new SqlParameter("@IdxMacchina", idxMacchina ?? "");
|
||||
var numDayPrevParam = new SqlParameter("@NumDayPrev", numDayPrev);
|
||||
@@ -958,7 +960,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> OdlFixMachineSlaveAsync(string idxMacchina, int numDayPrev, int doInsert)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacc = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var NumDayPrev = new SqlParameter("@NumDayPrev", numDayPrev);
|
||||
@@ -977,7 +979,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<ODLExpModel> OdlLastByMaccAsync(string idxMacchina)
|
||||
{
|
||||
ODLExpModel answ = new();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
// attenzione: se la stored resituisce una tabella, il primo elemento va recuperato in RAM!!!
|
||||
@@ -1001,7 +1003,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<ODLExpModel>> OdlListByMaccPeriodoAsync(string idxMacchina, DateTime dtStart, DateTime dtEnd)
|
||||
{
|
||||
List<ODLExpModel> dbResult = new List<ODLExpModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var DataFrom = new SqlParameter("@dataFrom", dtStart);
|
||||
@@ -1023,7 +1025,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<PzProdModel> PezziProdMacchinaAsync(string idxMacchina)
|
||||
{
|
||||
PzProdModel dbResult = new PzProdModel();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
dbResult = (await dbCtx
|
||||
@@ -1046,7 +1048,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<PODLExpModel>> POdlGetByMaccArtAsync(string idxMacchina, string codArticolo, string codGruppo, bool onlyFree)
|
||||
{
|
||||
List<PODLExpModel> dbResult = new List<PODLExpModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var pCodArticolo = new SqlParameter("@CodArticolo", codArticolo);
|
||||
@@ -1069,7 +1071,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RecalcMseAsync(string idxMacchina, int maxAgeSec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var rigaProd = await StatoProdMacchinaAsync(idxMacchina, DateTime.Now);
|
||||
var MaxAgeSec = new SqlParameter("@maxAgeSec ", maxAgeSec);
|
||||
@@ -1093,7 +1095,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RegControlliInsertAsync(string idxMacchina, int matrOpr, bool esitoOk, string note, DateTime dataOra)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacc = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var MatrOpr = new SqlParameter("@MatrOpr", matrOpr);
|
||||
@@ -1114,7 +1116,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RegDichiarInsertAsync(RegistroDichiarazioniModel newRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var TagCode = new SqlParameter("@TagCode", newRec.TagCode);
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", newRec.IdxMacchina);
|
||||
@@ -1136,7 +1138,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RegDichiarUpdateAsync(RegistroDichiarazioniModel newRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var Original_IdxDich = new SqlParameter("@Original_IdxDich", newRec.IdxDich);
|
||||
var DtRec = new SqlParameter("@DtRec", newRec.DtRec);
|
||||
@@ -1157,7 +1159,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RegScartiInsertAsync(RegistroScartiModel newRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@idxMacchina", newRec.IdxMacchina);
|
||||
var DataOra = new SqlParameter("@DataOra", newRec.DataOra);
|
||||
@@ -1184,7 +1186,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<bool> RemRebootLogAddAndCleanAsync(RemoteRebootLogModel newRec, bool doClean, int num2keep)
|
||||
{
|
||||
bool fatto = false;
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
// 1. Transazione minima: SOLO INSERT + COMMIT
|
||||
await using var tx = await dbCtx.Database.BeginTransactionAsync();
|
||||
@@ -1227,7 +1229,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RemRebootLogAddAsync(RemoteRebootLogModel newRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var dbResult = dbCtx
|
||||
.DbSetRemRebLog
|
||||
@@ -1242,7 +1244,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<RemoteRebootLogModel>> RemRebootLogGetAllAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var dbResult = await dbCtx
|
||||
.DbSetRemRebLog
|
||||
@@ -1258,7 +1260,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<RemoteRebootLogModel>> RemRebootLogGetLastAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
var dbResult = await dbCtx
|
||||
.DbSetRemRebLog
|
||||
.FromSqlRaw("EXEC stp_RRL_getLast")
|
||||
@@ -1273,7 +1275,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RemRebootLogKeepLastAsync(int num2keep)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var pNum2Keep = new SqlParameter("@num2keep", num2keep);
|
||||
// La SP gestisce già la logica di soglia (1.5x), ma la specifico x sicurezza
|
||||
@@ -1291,7 +1293,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> SignalLogInsertAsync(SignalLogModel newRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var currRec = dbCtx
|
||||
.DbSetSignalLog
|
||||
@@ -1307,7 +1309,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<TransizioneStatiModel>> SMES_getHwTransitionsAsync(string idxMacchina, int idxTipo)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var IdxTipo = new SqlParameter("@IdxTipo", idxTipo);
|
||||
@@ -1327,7 +1329,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<TransizioneStatiModel>> SMES_getUserForcedAsync(string idxMacchina, int idxTipo)
|
||||
{
|
||||
await using var dbCtx = new MoonProContext(options);
|
||||
await using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var IdxTipo = new SqlParameter("@IdxTipo", idxTipo);
|
||||
@@ -1346,18 +1348,14 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public List<TransizioneIngressiModel> StateMachineIngressi(int idxFam)
|
||||
{
|
||||
List<TransizioneIngressiModel> dbResult = new List<TransizioneIngressiModel>();
|
||||
using (var dbCtx = new MoonProContext(options))
|
||||
{
|
||||
var IdxFamIn = new SqlParameter("@IdxFamigliaIngresso", idxFam);
|
||||
dbResult = dbCtx
|
||||
.DbSetSMI
|
||||
.FromSqlRaw("exec dbo.stp_TRI_getByIdxFamIng @IdxFamigliaIngresso", IdxFamIn)
|
||||
.AsNoTracking()
|
||||
.AsEnumerable()
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
var IdxFamIn = new SqlParameter("@IdxFamigliaIngresso", idxFam);
|
||||
return dbCtx
|
||||
.DbSetSMI
|
||||
.FromSqlRaw("exec dbo.stp_TRI_getByIdxFamIng @IdxFamigliaIngresso", IdxFamIn)
|
||||
.AsNoTracking()
|
||||
.AsEnumerable()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1366,7 +1364,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<TransizioneIngressiModel>> StateMachineIngressiAsync(int idxFam)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxFamIn = new SqlParameter("@IdxFamigliaIngresso", idxFam);
|
||||
var dbResult = await dbCtx
|
||||
@@ -1386,7 +1384,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<StatoProdModel> StatoProdMacchinaAsync(string idxMacchina, DateTime dtReq)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var DataOra = new SqlParameter("@DataOra ", dtReq);
|
||||
@@ -1406,7 +1404,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<VMSFDModel>> VMSFDGetAllAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var dbResult = await dbCtx
|
||||
.DbSetMSFD
|
||||
@@ -1424,7 +1422,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<VMSFDModel?> VMSFDGetByMaccAsync(string idxMacc)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc);
|
||||
var dbResult = (await dbCtx
|
||||
@@ -1444,7 +1442,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<VMSFDModel>> VMSFDGetMultiByMaccAsync(string idxMacc)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
|
||||
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc);
|
||||
|
||||
@@ -1461,9 +1459,14 @@ namespace MP.Data.Controllers
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static IConfiguration _configuration;
|
||||
#if false
|
||||
private static IConfiguration _configuration;
|
||||
#endif
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private DbContextOptions<MoonProContext> options;
|
||||
#if false
|
||||
private DbContextOptions<MoonProContext> options;
|
||||
#endif
|
||||
private DbContextOptions<MoonPro_FluxContext> optionsFlux;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
|
||||
@@ -15,10 +15,21 @@ namespace MP.Data.Controllers
|
||||
public class MpLandController : IDisposable
|
||||
{
|
||||
#region Public Constructors
|
||||
protected readonly IDbContextFactory<MoonProContext> _ctxFactory;
|
||||
protected readonly IDbContextFactory<MoonPro_FluxContext> _ctxFactoryFL;
|
||||
protected readonly IDbContextFactory<MoonPro_STATSContext> _ctxFactorySta;
|
||||
|
||||
public MpLandController(IConfiguration configuration)
|
||||
public MpLandController(
|
||||
IConfiguration configuration,
|
||||
IDbContextFactory<MoonProContext> ctxFactory,
|
||||
IDbContextFactory<MoonPro_FluxContext> ctxFactoryFL,
|
||||
IDbContextFactory<MoonPro_STATSContext> ctxFactorySta)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_ctxFactory = ctxFactory;
|
||||
_ctxFactoryFL = ctxFactoryFL;
|
||||
_ctxFactorySta = ctxFactorySta;
|
||||
#if false
|
||||
string connStr = _configuration.GetConnectionString("MP.Land");
|
||||
if (string.IsNullOrEmpty(connStr))
|
||||
{
|
||||
@@ -26,7 +37,8 @@ namespace MP.Data.Controllers
|
||||
}
|
||||
options = new DbContextOptionsBuilder<MoonProContext>()
|
||||
.UseSqlServer(connStr)
|
||||
.Options;
|
||||
.Options;
|
||||
#endif
|
||||
Log.Info("Avviato MpLandController");
|
||||
}
|
||||
|
||||
@@ -34,6 +46,7 @@ namespace MP.Data.Controllers
|
||||
|
||||
#region Public Methods
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Restituisce info dimensione, tabelle e num righe DB gestiti
|
||||
/// </summary>
|
||||
@@ -70,58 +83,53 @@ namespace MP.Data.Controllers
|
||||
// leggo per DB principale
|
||||
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.All")))
|
||||
{
|
||||
using (var dbCtx = new MoonProContext(options))
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
dbResult.Add(singleRes);
|
||||
}
|
||||
dbResult.Add(singleRes);
|
||||
}
|
||||
}
|
||||
// leggo per FluxLog
|
||||
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.Flux")))
|
||||
{
|
||||
using (var dbCtx = new MoonPro_FluxContext(_configuration))
|
||||
using var dbCtx = _ctxFactoryFL.CreateDbContext();
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
dbResult.Add(singleRes);
|
||||
}
|
||||
dbResult.Add(singleRes);
|
||||
}
|
||||
}
|
||||
// leggo per Stats
|
||||
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.Stats")))
|
||||
{
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using var dbCtx = _ctxFactorySta.CreateDbContext();
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
dbResult.Add(singleRes);
|
||||
}
|
||||
dbResult.Add(singleRes);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in AllDbInfo:{Environment.NewLine}{exc}");
|
||||
Log.Error($"Eccezione in AllDbInfoAsync:{Environment.NewLine}{exc}");
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Elenco da tabella Config
|
||||
@@ -130,15 +138,12 @@ namespace MP.Data.Controllers
|
||||
public List<ConfigModel> ConfigGetAll()
|
||||
{
|
||||
List<ConfigModel> dbResult = new List<ConfigModel>();
|
||||
using (var dbCtx = new MoonProContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetConfig
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Chiave)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
return dbCtx
|
||||
.DbSetConfig
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Chiave)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -154,16 +159,13 @@ namespace MP.Data.Controllers
|
||||
public List<AnagOperatoriModel> ElencoOperatori()
|
||||
{
|
||||
List<AnagOperatoriModel> dbResult = new List<AnagOperatoriModel>();
|
||||
using (var dbCtx = new MoonProContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbOperatori
|
||||
.Where(s => s.MatrOpr > 0)
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.MatrOpr)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
return dbCtx
|
||||
.DbOperatori
|
||||
.Where(s => s.MatrOpr > 0)
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.MatrOpr)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -173,13 +175,10 @@ namespace MP.Data.Controllers
|
||||
public List<MacchineModel> MacchineGetAll()
|
||||
{
|
||||
List<MacchineModel> dbResult = new List<MacchineModel>();
|
||||
using (MoonProContext localDbCtx = new MoonProContext(options))
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
.DbSetMacchine
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
return dbCtx
|
||||
.DbSetMacchine
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -189,15 +188,12 @@ namespace MP.Data.Controllers
|
||||
public List<RemoteRebootLogModel> RemRebootLogGetAll()
|
||||
{
|
||||
List<RemoteRebootLogModel> dbResult = new List<RemoteRebootLogModel>();
|
||||
using (var dbCtx = new MoonProContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetRemRebLog
|
||||
.AsNoTracking()
|
||||
.OrderByDescending(x => x.IdxReboot)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
return dbCtx
|
||||
.DbSetRemRebLog
|
||||
.AsNoTracking()
|
||||
.OrderByDescending(x => x.IdxReboot)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -207,15 +203,12 @@ namespace MP.Data.Controllers
|
||||
public List<RemoteRebootLogModel> RemRebootLogGetLast()
|
||||
{
|
||||
List<RemoteRebootLogModel> dbResult = new List<RemoteRebootLogModel>();
|
||||
using (var dbCtx = new MoonProContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetRemRebLog
|
||||
.FromSqlRaw("EXEC stp_RRL_getLast")
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
return dbCtx
|
||||
.DbSetRemRebLog
|
||||
.FromSqlRaw("EXEC stp_RRL_getLast")
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -225,15 +218,12 @@ namespace MP.Data.Controllers
|
||||
public List<RemoteRebootLogModel> RemRebootLogGetLastNoMacc()
|
||||
{
|
||||
List<RemoteRebootLogModel> dbResult = new List<RemoteRebootLogModel>();
|
||||
using (var dbCtx = new MoonProContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetRemRebLog
|
||||
.FromSqlRaw("EXEC stp_RRL_GetLastNoMachine")
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
return dbCtx
|
||||
.DbSetRemRebLog
|
||||
.FromSqlRaw("EXEC stp_RRL_GetLastNoMachine")
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -244,7 +234,7 @@ namespace MP.Data.Controllers
|
||||
public bool RollBackEntity(object item)
|
||||
{
|
||||
bool answ = false;
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -283,7 +273,9 @@ namespace MP.Data.Controllers
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly DbContextOptions<MoonProContext> options;
|
||||
#if false
|
||||
private readonly DbContextOptions<MoonProContext> options;
|
||||
#endif
|
||||
private bool _disposed = false;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
@@ -1,31 +1,36 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Core.DTO;
|
||||
using MP.Core.Objects;
|
||||
using MP.Data.DbModels;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using static EgwCoreLib.Utils.DtUtils;
|
||||
|
||||
namespace MP.Data.Controllers
|
||||
{
|
||||
public class MpSpecController
|
||||
{
|
||||
protected readonly IDbContextFactory<MoonProContext> _ctxFactory;
|
||||
protected readonly IDbContextFactory<MoonPro_FluxContext> _ctxFactoryFL;
|
||||
#region Public Constructors
|
||||
|
||||
public MpSpecController(IConfiguration configuration)
|
||||
public MpSpecController(
|
||||
IConfiguration configuration,
|
||||
IDbContextFactory<MoonProContext> ctxFactory,
|
||||
IDbContextFactory<MoonPro_FluxContext> ctxFactoryFL)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_ctxFactory = ctxFactory;
|
||||
_ctxFactoryFL = ctxFactoryFL;
|
||||
#if false
|
||||
string connStr = _configuration.GetConnectionString("MP.Data");
|
||||
options = new DbContextOptionsBuilder<MoonProContext>()
|
||||
.UseSqlServer(connStr)
|
||||
.Options;
|
||||
.Options;
|
||||
#endif
|
||||
Log.Info("Avviata classe MpSpecController");
|
||||
}
|
||||
|
||||
@@ -41,7 +46,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<AnagCountersModel> AnagCountersGetNextAsync(string cntType)
|
||||
{
|
||||
AnagCountersModel answ = new AnagCountersModel();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
bool outTable = true;
|
||||
if (outTable)
|
||||
{
|
||||
@@ -102,7 +107,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<vSelEventiBCodeModel>> AnagEventiGeneralAsync(string TableName = "EvList", string FieldName = "Common")
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var pTableName = new SqlParameter("@TableName", TableName);
|
||||
var pFieldName = new SqlParameter("@FieldName", FieldName);
|
||||
var dbResult = await dbCtx
|
||||
@@ -129,7 +134,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AnagGruppiDeleteAsync(AnagGruppiModel updRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var dbRec = await dbCtx
|
||||
.DbSetAnagGruppi
|
||||
.AsNoTracking()
|
||||
@@ -161,7 +166,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<AnagGruppiModel>> AnagGruppiGetTipoAsync(string tipoGruppo)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetAnagGruppi
|
||||
.Where(x => x.TipoGruppo == tipoGruppo)
|
||||
@@ -176,7 +181,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<RepartiDTO>> AnagGruppiRepartoDtoAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
// in primis recupero i reparti...
|
||||
var listReparti = await AnagGruppiGetTipoAsync("REPARTO");
|
||||
|
||||
@@ -211,7 +216,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AnagGruppiUpsertAsync(AnagGruppiModel updRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var dbRec = await dbCtx
|
||||
.DbSetAnagGruppi
|
||||
.AsNoTracking()
|
||||
@@ -279,7 +284,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<int> ArticoliCountAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var result = await dbCtx
|
||||
.DbSetArticoli
|
||||
.CountAsync();
|
||||
@@ -295,7 +300,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<int> ArticoliCountSearchAsync(string tipoArt = "*", string azienda = "*", string searchVal = "")
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
IQueryable<AnagArticoliModel> query = dbCtx.DbSetArticoli.AsNoTracking();
|
||||
|
||||
// filtro tipo articolo
|
||||
@@ -331,7 +336,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<int> ArticoliCountUsedAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var result = await dbCtx
|
||||
.DbSetCounter
|
||||
.FromSqlRaw("EXEC stp_ART_CountUsed")
|
||||
@@ -348,7 +353,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ArticoliDeleteRecordAsync(AnagArticoliModel currRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var currVal = dbCtx
|
||||
.DbSetArticoli
|
||||
.Where(x => x.CodArticolo == currRec.CodArticolo)
|
||||
@@ -368,7 +373,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<AnagArticoliModel>> ArticoliGetByTipoAsync(string tipo, string azienda = "*")
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetArticoli
|
||||
.AsNoTracking()
|
||||
@@ -387,7 +392,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<AnagArticoliModel>> ArticoliGetSearchAsync(int numRecord, string tipoArt = "*", string azienda = "*", string searchVal = "")
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
IQueryable<AnagArticoliModel> query = dbCtx.DbSetArticoli
|
||||
.AsNoTracking();
|
||||
|
||||
@@ -425,7 +430,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<AnagArticoliModel>> ArticoliGetUnusedAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetArticoli
|
||||
.FromSqlRaw("EXEC stp_ART_getNotUsed")
|
||||
@@ -439,7 +444,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<AnagArticoliModel>> ArticoliGetUsedAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetArticoli
|
||||
.FromSqlRaw("EXEC stp_ART_getUsed")
|
||||
@@ -454,7 +459,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<AnagArticoliModel>> ArticoliInKitAsync()
|
||||
{
|
||||
List<AnagArticoliModel> dbResult = new List<AnagArticoliModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
dbResult = await dbCtx
|
||||
.DbSetArticoli
|
||||
.FromSqlRaw("EXEC stp_TempKIT_getArtChild")
|
||||
@@ -470,7 +475,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ArticoliUpdateRecord(AnagArticoliModel editRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var currRec = dbCtx
|
||||
.DbSetArticoli
|
||||
.Where(x => x.CodArticolo == editRec.CodArticolo)
|
||||
@@ -500,7 +505,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<ConfigModel>> ConfigGetAllAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetConfig
|
||||
.AsNoTracking()
|
||||
@@ -516,7 +521,7 @@ namespace MP.Data.Controllers
|
||||
{
|
||||
bool fatto = false;
|
||||
ConfigModel dbResult = new ConfigModel();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
dbResult = await dbCtx
|
||||
.DbSetConfig
|
||||
.Where(x => x.Chiave == updRec.Chiave)
|
||||
@@ -647,7 +652,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> EvListInsertAsync(EventListModel newRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var currRec = await dbCtx
|
||||
.DbSetEvList
|
||||
.AddAsync(newRec);
|
||||
@@ -874,7 +879,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<bool> Grp2MaccDeleteAsync(Gruppi2MaccModel rec2del)
|
||||
{
|
||||
bool answ = false;
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var dbRec = await dbCtx
|
||||
.DbSetGrp2Macc
|
||||
.Where(x => x.CodGruppo == rec2del.CodGruppo && x.IdxMacchina == rec2del.IdxMacchina)
|
||||
@@ -896,7 +901,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<bool> Grp2MaccInsertAsync(Gruppi2MaccModel upsRec)
|
||||
{
|
||||
bool answ = false;
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var dbRec = await dbCtx
|
||||
.DbSetGrp2Macc
|
||||
.Where(x => x.CodGruppo == upsRec.CodGruppo && x.IdxMacchina == upsRec.IdxMacchina)
|
||||
@@ -919,7 +924,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<bool> Grp2OperDeleteAsync(Gruppi2OperModel rec2del)
|
||||
{
|
||||
bool answ = false;
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var dbRec = await dbCtx
|
||||
.DbSetGrp2Oper
|
||||
.Where(x => x.CodGruppo == rec2del.CodGruppo && x.MatrOpr == rec2del.MatrOpr)
|
||||
@@ -941,7 +946,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<bool> Grp2OperInsertAsync(Gruppi2OperModel upsRec)
|
||||
{
|
||||
bool answ = false;
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var dbRec = await dbCtx
|
||||
.DbSetGrp2Oper
|
||||
.Where(x => x.CodGruppo == upsRec.CodGruppo && x.MatrOpr == upsRec.MatrOpr)
|
||||
@@ -962,7 +967,7 @@ namespace MP.Data.Controllers
|
||||
/// <param name="rec2del"></param>
|
||||
public async Task<bool> IstKitDeleteAsync(IstanzeKitModel rec2del)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var actRec = await dbCtx
|
||||
.DbSetInstKit
|
||||
.Where(x => x.KeyKit == rec2del.KeyKit && x.KeyExtOrd == rec2del.KeyExtOrd)
|
||||
@@ -985,7 +990,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<IstanzeKitModel>> IstKitFiltAsync(string keyKit, string keyExtOrd)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetInstKit
|
||||
.Where(x => (string.IsNullOrEmpty(keyKit) && string.IsNullOrEmpty(keyExtOrd)) || (x.KeyKit.Contains(keyKit) && !string.IsNullOrEmpty(keyKit)) || (x.KeyExtOrd.Contains(keyExtOrd) && !string.IsNullOrEmpty(keyExtOrd)))
|
||||
@@ -1000,7 +1005,7 @@ namespace MP.Data.Controllers
|
||||
/// <param name="KeyFilt">Chiave x filtro conf su tab WKS</param>
|
||||
public async Task<bool> IstKitInsertByWKSAsync(string CodArtParent, string KeyFilt)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
|
||||
var pCodArtParent = new SqlParameter("@CodArtParent", CodArtParent);
|
||||
var pKeyFilt = new SqlParameter("@KeyFilt", KeyFilt);
|
||||
@@ -1017,7 +1022,7 @@ namespace MP.Data.Controllers
|
||||
/// <param name="editRec"></param>
|
||||
public async Task<bool> IstKitUpsertAsync(IstanzeKitModel editRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var actRec = await dbCtx
|
||||
.DbSetInstKit
|
||||
.Where(x => x.KeyKit == editRec.KeyKit && x.KeyExtOrd == editRec.KeyExtOrd)
|
||||
@@ -1065,7 +1070,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<LinkMenuModel>> ListLinkAllAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetLinkMenu
|
||||
.AsNoTracking()
|
||||
@@ -1081,7 +1086,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<LinkMenuModel>> ListLinkFiltAsync(string tipoLink)
|
||||
{
|
||||
List<LinkMenuModel> dbResult = new List<LinkMenuModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetLinkMenu
|
||||
.Where(x => x.TipoLink == tipoLink)
|
||||
@@ -1106,7 +1111,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<ODLExpModel>> ListODLFiltAsync(bool inCorso, string codArt, string keyRichPart, string Reparto, string IdxMacchina, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
List<ODLExpModel> dbResult = new List<ODLExpModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
|
||||
var InCorso = new SqlParameter("@InCorso", inCorso);
|
||||
var CodArt = new SqlParameter("@CodArt", codArt);
|
||||
@@ -1131,7 +1136,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<PODLExpModel>> ListPODL_ByCodArtAsync(string CodArticolo, bool OnlyAvail)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var pCodArticolo = new SqlParameter("@CodArticolo", CodArticolo);
|
||||
var pOnlyAvail = new SqlParameter("@onlyAvail", OnlyAvail);
|
||||
|
||||
@@ -1149,7 +1154,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<PODLExpModel>> ListPODL_ByKitParentAsync(int IdxPodlParent)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var pIdxPodlParent = new SqlParameter("@IdxPodlParent", IdxPodlParent);
|
||||
|
||||
return await dbCtx
|
||||
@@ -1169,7 +1174,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<PODLExpModel>> ListPODL_KitFiltAsync(bool lanciato, string keyRichPart, string idxMacchina, string codGruppo, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var Lanc = new SqlParameter("@Lanciato", lanciato);
|
||||
var KeyRich = new SqlParameter("@KeyRich", keyRichPart);
|
||||
var CodGrp = new SqlParameter("@CodGruppo", codGruppo);
|
||||
@@ -1194,7 +1199,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<PODLExpModel>> ListPODLFiltAsync(bool lanciato, string keyRichPart, string idxMacchina, string codGruppo, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var Lanc = new SqlParameter("@Lanciato", lanciato);
|
||||
var KeyRich = new SqlParameter("@KeyRich", keyRichPart);
|
||||
var CodGrp = new SqlParameter("@CodGruppo", codGruppo);
|
||||
@@ -1217,7 +1222,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<ListValuesModel>> ListValuesFiltAsync(string tabName, string fieldName)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetListValues
|
||||
.Where(x => x.TableName == tabName && x.FieldName == fieldName)
|
||||
@@ -1233,7 +1238,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<MacchineModel>> MacchineByMatrOperAsync(int MatrOpr)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
if (MatrOpr == 0)
|
||||
{
|
||||
return await dbCtx
|
||||
@@ -1272,7 +1277,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<MacchineModel>> MacchineGetFiltAsync(string codGruppo)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
if (codGruppo == "*")
|
||||
{
|
||||
return await dbCtx
|
||||
@@ -1305,7 +1310,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<string>> MacchineWithFluxAsync(DateTime dtStart, DateTime dtEnd)
|
||||
{
|
||||
using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetFluxLog
|
||||
.AsNoTracking()
|
||||
@@ -1322,7 +1327,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<MappaStatoExplModel>> MseGetAllAsync(int maxAge = 2000)
|
||||
{
|
||||
List<MappaStatoExplModel> dbResult = new List<MappaStatoExplModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
|
||||
var maxAgeSec = new SqlParameter("@maxAgeSec", maxAge);
|
||||
|
||||
@@ -1357,7 +1362,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<ODLExpModel> OdlByKeyAsync(int IdxOdl)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetODLExp
|
||||
.AsNoTracking()
|
||||
@@ -1379,7 +1384,7 @@ namespace MP.Data.Controllers
|
||||
bool fatto = false;
|
||||
if (idxOdl > 0)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
DateTime adesso = DateTime.Now;
|
||||
// preparo i parametri
|
||||
var IdxODL = new SqlParameter("@IdxODL", idxOdl);
|
||||
@@ -1441,7 +1446,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<ODLModel>> OdlGetCurrentAsync()
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetODL
|
||||
.Where(x => x.DataInizio != null && x.DataFine == null)
|
||||
@@ -1457,7 +1462,7 @@ namespace MP.Data.Controllers
|
||||
List<StatODLModel> dbResult = new List<StatODLModel>();
|
||||
if (IdxOdl > 0)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var IdxODL = new SqlParameter("@IdxODL", IdxOdl);
|
||||
|
||||
dbResult = await dbCtx
|
||||
@@ -1477,7 +1482,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<AnagOperatoriModel>> OperatoriGetFiltAsync(string codGruppo)
|
||||
{
|
||||
List<AnagOperatoriModel> dbResult = new List<AnagOperatoriModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
if (codGruppo == "*")
|
||||
{
|
||||
dbResult = await dbCtx
|
||||
@@ -1510,7 +1515,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<List<string>> ParametriGetFiltAsync(string IdxMacchina)
|
||||
{
|
||||
using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetFluxLog
|
||||
.AsNoTracking()
|
||||
@@ -1529,7 +1534,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<PODLModel> PODL_getByKeyAsync(int idxPODL)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetPODL
|
||||
.AsNoTracking()
|
||||
@@ -1545,7 +1550,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<PODLModel> PODL_getByOdlAsync(int idxODL)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetPODL
|
||||
.AsNoTracking()
|
||||
@@ -1563,7 +1568,7 @@ namespace MP.Data.Controllers
|
||||
if (missingIds == null || !missingIds.Any())
|
||||
return new Dictionary<int, int>();
|
||||
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetPODL
|
||||
.AsNoTracking()
|
||||
@@ -1602,7 +1607,7 @@ namespace MP.Data.Controllers
|
||||
InsertDate = editRec.InsertDate
|
||||
};
|
||||
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var currRec = await dbCtx
|
||||
.DbSetPODL
|
||||
.AsNoTracking()
|
||||
@@ -1637,7 +1642,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<bool> PODL_updateRecipe(int idxPODL, string recipeName)
|
||||
{
|
||||
bool answ = false;
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var currRec = await dbCtx
|
||||
.DbSetPODL
|
||||
.Where(x => x.IdxPromessa == idxPODL)
|
||||
@@ -1677,7 +1682,7 @@ namespace MP.Data.Controllers
|
||||
CodCli = currRec.CodCli,
|
||||
InsertDate = currRec.InsertDate
|
||||
};
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var currVal = await dbCtx
|
||||
.DbSetPODL
|
||||
.Where(x => x.IdxPromessa == recPODL.IdxPromessa)
|
||||
@@ -1694,7 +1699,7 @@ namespace MP.Data.Controllers
|
||||
/// <param name="IdxPODL">IdxPODL parent</param>
|
||||
public async Task<bool> PodlIstKitDeleteAsync(int IdxPODL)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var pIdxPODL = new SqlParameter("@IdxPODL", IdxPODL);
|
||||
|
||||
var dbResult = await dbCtx
|
||||
@@ -1710,7 +1715,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> PODLUpdateRecordAsync(PODLModel editRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var currRec = await dbCtx
|
||||
.DbSetPODL
|
||||
.Where(x => x.IdxPromessa == editRec.IdxPromessa)
|
||||
@@ -1744,7 +1749,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<StatoMacchineModel> StatoMacchinaAsync(string idxMacchina)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetStatoMacc
|
||||
.Where(x => x.IdxMacchina == idxMacchina)
|
||||
@@ -1758,7 +1763,7 @@ namespace MP.Data.Controllers
|
||||
/// <param name="rec2del"></param>
|
||||
public async Task<bool> TemplateKitDeleteAsync(TemplateKitModel rec2del)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var actRec = await dbCtx
|
||||
.DbSetTempKit
|
||||
.Where(x => x.CodArtParent == rec2del.CodArtParent && x.CodArtChild == rec2del.CodArtChild)
|
||||
@@ -1782,7 +1787,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<TemplateKitModel>> TemplateKitFiltAsync(string KitCode, string codChild)
|
||||
{
|
||||
List<TemplateKitModel> dbResult = new List<TemplateKitModel>();
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
dbResult = await dbCtx
|
||||
.DbSetTempKit
|
||||
.Where(x => (string.IsNullOrEmpty(KitCode) && string.IsNullOrEmpty(codChild)) || (x.CodArtParent.Contains(KitCode) && !string.IsNullOrEmpty(KitCode)) || (x.CodArtChild.Contains(codChild) && !string.IsNullOrEmpty(codChild)))
|
||||
@@ -1798,7 +1803,7 @@ namespace MP.Data.Controllers
|
||||
/// <param name="codAzienda"></param>
|
||||
public async Task<bool> TemplateKitUpsertAsync(TemplateKitModel editRec, string codAzienda)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
// verifico preliminarmente articolo...
|
||||
var recArt = dbCtx
|
||||
.DbSetArticoli
|
||||
@@ -1854,7 +1859,7 @@ namespace MP.Data.Controllers
|
||||
List<TksScoreModel> dbResult = new List<TksScoreModel>();
|
||||
if (!string.IsNullOrEmpty(KeyFilt))
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var pKeyFilt = new SqlParameter("@KeyFilt", KeyFilt);
|
||||
var pMaxRes = new SqlParameter("@maxResult", MaxResult);
|
||||
dbResult = await dbCtx
|
||||
@@ -1866,13 +1871,14 @@ namespace MP.Data.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Elenco Vocabolario di una lingua
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Dictionary<string, string> VocabolarioGetLang(string lingua)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = _ctxFactory.CreateDbContext();
|
||||
var rawList = dbCtx
|
||||
.DbSetVocabolario
|
||||
.AsNoTracking()
|
||||
@@ -1892,7 +1898,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> VocabolarioUpsertAsync(VocabolarioModel upsRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var actRec = await dbCtx
|
||||
.DbSetVocabolario
|
||||
.Where(x => x.Lingua == upsRec.Lingua && x.Lemma == upsRec.Lemma)
|
||||
@@ -1919,7 +1925,7 @@ namespace MP.Data.Controllers
|
||||
/// <param name="rec2del"></param>
|
||||
public async Task<bool> WipKitDeleteAsync(WipSetupKitModel rec2del)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var actRec = await dbCtx
|
||||
.DbSetWipKit
|
||||
.Where(x => x.KeyFilt == rec2del.KeyFilt && x.CodOrd == rec2del.CodOrd)
|
||||
@@ -1932,7 +1938,8 @@ namespace MP.Data.Controllers
|
||||
.Remove(actRec);
|
||||
}
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Elimina record + vecchi della data-ora indicata
|
||||
@@ -1941,7 +1948,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> WipKitDeleteOlderAsync(DateTime dateLimit)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var actRec = await dbCtx
|
||||
.DbSetWipKit
|
||||
.Where(x => x.DataIns < dateLimit)
|
||||
@@ -1967,7 +1974,7 @@ namespace MP.Data.Controllers
|
||||
// solo se filtro valido...
|
||||
if (!string.IsNullOrEmpty(KeyFilt))
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
dbResult = await dbCtx
|
||||
.DbSetWipKit
|
||||
.Where(x => x.KeyFilt.Contains(KeyFilt))
|
||||
@@ -1983,7 +1990,7 @@ namespace MP.Data.Controllers
|
||||
/// <param name="editRec"></param>
|
||||
public async Task<bool> WipKitUpsertAsync(WipSetupKitModel editRec)
|
||||
{
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var actRec = await dbCtx
|
||||
.DbSetWipKit
|
||||
.Where(x => x.KeyFilt == editRec.KeyFilt && x.CodOrd == editRec.CodOrd)
|
||||
@@ -2013,7 +2020,9 @@ namespace MP.Data.Controllers
|
||||
|
||||
private static IConfiguration _configuration;
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private DbContextOptions<MoonProContext> options;
|
||||
#if false
|
||||
private DbContextOptions<MoonProContext> options;
|
||||
#endif
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
|
||||
@@ -19,11 +19,15 @@ namespace MP.Data.Controllers
|
||||
public MpStatsController(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
string connStr = _configuration.GetConnectionString("MP.Stats");
|
||||
options = new DbContextOptionsBuilder<MoonPro_STATSContext>()
|
||||
.UseSqlServer(connStr)
|
||||
.Options;
|
||||
Log.Info("Avviata classe MpStatsController");
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
private DbContextOptions<MoonPro_STATSContext> options;
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
@@ -33,13 +37,10 @@ namespace MP.Data.Controllers
|
||||
public List<AzioniUL> ActionsGetAll()
|
||||
{
|
||||
List<AzioniUL> dbResult = new List<AzioniUL>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
using var dbCtx = new MoonPro_STATSContext(options);
|
||||
return dbCtx
|
||||
.DbSetAzioniUL
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,13 +50,10 @@ namespace MP.Data.Controllers
|
||||
public List<AnagFLTransModel> AnagFLTransGetAll()
|
||||
{
|
||||
List<AnagFLTransModel> dbResult = new List<AnagFLTransModel>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetAnagFLTrans
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
using var dbCtx = new MoonPro_STATSContext(options);
|
||||
return dbCtx
|
||||
.DbSetAnagFLTrans
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,7 +65,7 @@ namespace MP.Data.Controllers
|
||||
public List<StatsAnagArticoli> ArticoliGetSearch(int numRecord, string searchVal = "")
|
||||
{
|
||||
List<StatsAnagArticoli> dbResult = new List<StatsAnagArticoli>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetArticoli
|
||||
@@ -88,7 +86,7 @@ namespace MP.Data.Controllers
|
||||
public List<StatsODL> CommesseGetSearch(int numRecord, string searchVal = "")
|
||||
{
|
||||
List<StatsODL> dbResult = new List<StatsODL>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetODL
|
||||
@@ -107,7 +105,7 @@ namespace MP.Data.Controllers
|
||||
public List<ConfigModel> ConfigGetAll()
|
||||
{
|
||||
List<ConfigModel> dbResult = new List<ConfigModel>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetConfig
|
||||
@@ -133,7 +131,7 @@ namespace MP.Data.Controllers
|
||||
public List<FLModel> FluxLogRawData(string IdxMacchina, DateTime DtStart, DateTime DtEnd, string fluxType)
|
||||
{
|
||||
List<FLModel> dbResult = new List<FLModel>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetFL
|
||||
@@ -153,7 +151,7 @@ namespace MP.Data.Controllers
|
||||
public List<string> FluxTypeList()
|
||||
{
|
||||
List<string> dbResult = new List<string>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetFL
|
||||
@@ -172,7 +170,7 @@ namespace MP.Data.Controllers
|
||||
public List<MacchineStatModel> MacchineEnergy()
|
||||
{
|
||||
List<MacchineStatModel> dbResult = new List<MacchineStatModel>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetMaccStat
|
||||
@@ -188,7 +186,7 @@ namespace MP.Data.Controllers
|
||||
public List<MacchineModel> MacchineGetAll()
|
||||
{
|
||||
List<MacchineModel> dbResult = new List<MacchineModel>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetMacchine
|
||||
@@ -204,7 +202,7 @@ namespace MP.Data.Controllers
|
||||
public async Task<List<MaccEnergyCheckModel>> MacchineEnergyCheckGetAllAsync()
|
||||
{
|
||||
List<MaccEnergyCheckModel> dbResult = new List<MaccEnergyCheckModel>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = await dbCtx
|
||||
.DbSetMacchineCheck
|
||||
@@ -222,7 +220,7 @@ namespace MP.Data.Controllers
|
||||
public bool RollBackEntity(object item)
|
||||
{
|
||||
bool answ = false;
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -248,7 +246,7 @@ namespace MP.Data.Controllers
|
||||
public List<ResControlli> StatControlliGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
||||
{
|
||||
List<ResControlli> dbResult = new List<ResControlli>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
||||
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
||||
@@ -280,7 +278,7 @@ namespace MP.Data.Controllers
|
||||
public List<DdbTurni> StatDdbGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo, int FirstRecord, int NumRecord)
|
||||
{
|
||||
List<DdbTurni> dbResult = new List<DdbTurni>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
||||
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
||||
@@ -312,7 +310,7 @@ namespace MP.Data.Controllers
|
||||
public int StatDdbGetCount(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
||||
{
|
||||
int numResult = 0;
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
numResult = dbCtx
|
||||
.DbSetDdbTurni
|
||||
@@ -335,7 +333,7 @@ namespace MP.Data.Controllers
|
||||
public List<OdlEnergyModel> StatOdlEnergyGetFilt(string IdxMacchina, DateTime DtStart, DateTime DtEnd, int IdxODL, string KeyRichiesta, string CodArticolo)
|
||||
{
|
||||
List<OdlEnergyModel> dbResult = new List<OdlEnergyModel>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
var dataFrom = new SqlParameter("@dataFrom", DtStart);
|
||||
var dataTo = new SqlParameter("@dataTo", DtEnd);
|
||||
@@ -361,7 +359,7 @@ namespace MP.Data.Controllers
|
||||
public List<StatsODL> StatOdlGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
||||
{
|
||||
List<StatsODL> dbResult = new List<StatsODL>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
||||
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
||||
@@ -389,7 +387,7 @@ namespace MP.Data.Controllers
|
||||
public List<ResScarti> StatScartiGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
||||
{
|
||||
List<ResScarti> dbResult = new List<ResScarti>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
||||
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
||||
@@ -417,7 +415,7 @@ namespace MP.Data.Controllers
|
||||
public List<TurniOee> StatTurniOeeGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
||||
{
|
||||
List<TurniOee> dbResult = new List<TurniOee>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
||||
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
||||
@@ -443,7 +441,7 @@ namespace MP.Data.Controllers
|
||||
public List<UserActionLog> StatUserLogGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
||||
{
|
||||
List<UserActionLog> dbResult = new List<UserActionLog>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
||||
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
||||
@@ -467,7 +465,7 @@ namespace MP.Data.Controllers
|
||||
public List<VocabolarioModel> VocabolarioGetAll()
|
||||
{
|
||||
List<VocabolarioModel> dbResult = new List<VocabolarioModel>();
|
||||
using (var dbCtx = new MoonPro_STATSContext(_configuration))
|
||||
using (var dbCtx = new MoonPro_STATSContext(options))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetVocabolario
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace MP.Data
|
||||
{
|
||||
public static class DataServiceCollectionExtensions
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunta repository/servizi specifici per IOC
|
||||
/// </summary>
|
||||
@@ -49,6 +51,7 @@ namespace MP.Data
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunta repository/servizi specifici per LAND
|
||||
/// </summary>
|
||||
@@ -56,7 +59,12 @@ namespace MP.Data
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddLandDataLayer(this IServiceCollection services)
|
||||
{
|
||||
// Controllers MP.AppAuth (dipendenze di AppAuthService)
|
||||
services.TryAddScoped<AppAuthController>();
|
||||
services.TryAddScoped<MPController>();
|
||||
services.TryAddScoped<AppUserController>();
|
||||
|
||||
// Servizi LAND
|
||||
services.TryAddSingleton<IMpLandRepository, MpLandRepository>();
|
||||
services.TryAddSingleton<SyncService>();
|
||||
services.TryAddSingleton<TabDataService>();
|
||||
@@ -64,6 +72,7 @@ namespace MP.Data
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunta repository/servizi specifici per MON
|
||||
/// </summary>
|
||||
@@ -71,11 +80,11 @@ namespace MP.Data
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddMonDataLayer(this IServiceCollection services)
|
||||
{
|
||||
|
||||
services.TryAddSingleton<IMpMonRepository, MpMonRepository>();
|
||||
services.TryAddSingleton<MonDataFeeder>();
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunta repository/servizi specifici per SPEC
|
||||
/// </summary>
|
||||
@@ -95,13 +104,12 @@ namespace MP.Data
|
||||
services.TryAddScoped<IMpLandRepository, MpLandRepository>();
|
||||
// ---------- End Repository ----------
|
||||
|
||||
|
||||
// ---------- Start Servizi ----------
|
||||
//services.TryAddSingleton<MpDataService>();
|
||||
// ---------- End Servizi ----------
|
||||
|
||||
|
||||
// ---------- Start Altro ----------
|
||||
services.TryAddSingleton<MpIocController>();
|
||||
services.TryAddScoped<AppAuthController>();
|
||||
services.TryAddScoped<MPController>();
|
||||
services.TryAddScoped<AppUserController>();
|
||||
@@ -117,5 +125,30 @@ namespace MP.Data
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunta repository/servizi specifici per STATS
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddStatsDataLayer(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IMpVocRepository, MpVocRepository>();
|
||||
|
||||
services.AddSingleton<TranslateSrv>();
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunta repository/servizi specifici per TAB
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddTabDataLayer(this IServiceCollection services)
|
||||
{
|
||||
return services;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ namespace MP.Data.DbModels
|
||||
/// <summary>
|
||||
/// Score complessivo
|
||||
/// </summary>
|
||||
[Precision(18, 6)]
|
||||
public decimal TotalScore { get; set; } = 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@ namespace MP.Data
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private IConfiguration _configuration;
|
||||
#if false
|
||||
private IConfiguration _configuration;
|
||||
#endif
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
@@ -27,15 +29,17 @@ namespace MP.Data
|
||||
/// Indispensabile x prima generazione migrations EFCore
|
||||
/// </summary>
|
||||
|
||||
[Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. Connection string can be adapted as pleased.")]
|
||||
[Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. use DbContextoptions instead.")]
|
||||
public MoonPro_FluxContext()
|
||||
{
|
||||
}
|
||||
|
||||
#if false
|
||||
[Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. use DbContextoptions instead.")]
|
||||
public MoonPro_FluxContext(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public MoonPro_FluxContext(DbContextOptions<MoonPro_FluxContext> options) : base(options)
|
||||
{
|
||||
@@ -69,6 +73,7 @@ namespace MP.Data
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
#if false
|
||||
string connString = _configuration.GetConnectionString("MP.Flux");
|
||||
if (!string.IsNullOrEmpty(connString))
|
||||
{
|
||||
@@ -77,7 +82,9 @@ namespace MP.Data
|
||||
else
|
||||
{
|
||||
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_FluxData;Trusted_Connection=True;");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_FluxData;Trusted_Connection=True;");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,16 +16,20 @@ namespace MP.Data
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private IConfiguration _configuration;
|
||||
#if false
|
||||
private IConfiguration _configuration;
|
||||
#endif
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
#if false
|
||||
public MoonPro_STATSContext(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public MoonPro_STATSContext(DbContextOptions<MoonPro_STATSContext> options) : base(options)
|
||||
{
|
||||
@@ -68,10 +72,7 @@ namespace MP.Data
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
string connString = _configuration.GetConnectionString("MP.Stats");
|
||||
|
||||
optionsBuilder.UseSqlServer(connString);
|
||||
//optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_STATS;Trusted_Connection=True;");
|
||||
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_STATS;Trusted_Connection=True;");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,40 @@ namespace MP.Data.Repository.Anag
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<RepartiDTO>> GruppiRepartoDtoByOperAsync(int matrOpr)
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
var listReparti = await AnagGruppiGetTipoAsync("REPARTO");
|
||||
|
||||
var listMacc = await dbCtx
|
||||
.DbSetGrp2Macc
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
var listOpr = await dbCtx
|
||||
.DbSetGrp2Oper
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
var gruppiOpr = await dbCtx.DbSetGrp2Oper
|
||||
.Where(x => x.MatrOpr == matrOpr)
|
||||
.Select(x => x.CodGruppo)
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
return listReparti
|
||||
.Where(r => gruppiOpr.Contains(r.CodGruppo))
|
||||
.Select(x => new RepartiDTO()
|
||||
{
|
||||
CodGruppo = x.CodGruppo,
|
||||
TipoGruppo = x.TipoGruppo,
|
||||
DescrGruppo = x.DescrGruppo,
|
||||
SelEnabled = x.SelEnabled,
|
||||
CountMacc = listMacc.Where(y => y.CodGruppo == x.CodGruppo).Select(y => y.IdxMacchina).Distinct().Count(),
|
||||
CountOpr = listOpr.Where(y => y.CodGruppo == x.CodGruppo).Select(y => y.MatrOpr).Distinct().Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> AnagGruppiUpsertAsync(AnagGruppiModel updRec)
|
||||
{
|
||||
|
||||
@@ -75,14 +75,6 @@ namespace MP.Data.Repository.Anag
|
||||
/// <returns>Lista di valori ammessi</returns>
|
||||
Task<List<ListValuesModel>> AnagTipoArtLvAsync();
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Elenco codice articoli che abbiano dati Dossier
|
||||
/// </summary>
|
||||
/// <returns>Lista di codici articolo</returns>
|
||||
Task<List<string>> ArticleWithDossierAsync();
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Conteggio num articoli Async
|
||||
/// </summary>
|
||||
@@ -154,6 +146,20 @@ namespace MP.Data.Repository.Anag
|
||||
/// <returns>True se aggiornato</returns>
|
||||
Task<bool> ArticoliUpdateRecord(AnagArticoliModel editRec);
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Gruppi tipo REPARTOin formato DTO con conteggi del numero record trovati filtrati per operatore
|
||||
/// </summary>
|
||||
/// <returns>Lista di DTO reparti con conteggio macchine e operatori</returns>
|
||||
Task<List<RepartiDTO>> GruppiRepartoDtoByOperAsync(int matrOpr);
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Elenco codice articoli che abbiano dati Dossier
|
||||
/// </summary>
|
||||
/// <returns>Lista di codici articolo</returns>
|
||||
Task<List<string>> ArticleWithDossierAsync();
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Elenco valori ammessi x tabella/colonna Async
|
||||
/// </summary>
|
||||
|
||||
@@ -11,27 +11,36 @@ namespace MP.Data.Repository.Dossier
|
||||
{
|
||||
public class DossierRepository : IDossierRepository
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public DossierRepository(IConfiguration configuration)
|
||||
public DossierRepository(
|
||||
IConfiguration configuration,
|
||||
IDbContextFactory<MoonPro_FluxContext> ctxFactoryFL)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_ctxFactoryFL = ctxFactoryFL;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<string>> ArticleWithDossierAsync()
|
||||
{
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetDossiers
|
||||
.AsNoTracking()
|
||||
.Select(i => i.CodArticolo)
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> DossiersDeleteRecordAsync(DossierModel currRec)
|
||||
{
|
||||
await using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
var currVal = await dbCtx
|
||||
.DbSetDossiers
|
||||
.Where(x => x.IdxDossier == currRec.IdxDossier)
|
||||
@@ -46,7 +55,7 @@ namespace MP.Data.Repository.Dossier
|
||||
/// <inheritdoc />
|
||||
public async Task<List<DossierModel>> DossiersGetLastFiltAsync(string IdxMacchina, string CodArticolo, DateTime DtStart, DateTime DtEnd, int MaxRec)
|
||||
{
|
||||
await using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetDossiers
|
||||
.AsNoTracking()
|
||||
@@ -61,7 +70,7 @@ namespace MP.Data.Repository.Dossier
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> DossiersInsertAsync(DossierModel newRec)
|
||||
{
|
||||
await using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
await dbCtx
|
||||
.DbSetDossiers
|
||||
.AddAsync(newRec);
|
||||
@@ -71,7 +80,7 @@ namespace MP.Data.Repository.Dossier
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> DossiersTakeParamsSnapshotLastAsync(string idxMacchina, DateTime dtMin, DateTime dtMax)
|
||||
{
|
||||
await using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
||||
var pDtMin = new SqlParameter("@DtMin", dtMin);
|
||||
var pDtMax = new SqlParameter("@DtMax", dtMax);
|
||||
@@ -85,7 +94,7 @@ namespace MP.Data.Repository.Dossier
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> DossiersUpdateValoreAsync(DossierModel editRec)
|
||||
{
|
||||
await using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
var currRec = await dbCtx
|
||||
.DbSetDossiers
|
||||
.Where(x => x.IdxDossier == editRec.IdxDossier)
|
||||
@@ -104,18 +113,18 @@ namespace MP.Data.Repository.Dossier
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<string>> ArticleWithDossierAsync()
|
||||
{
|
||||
await using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
return await dbCtx
|
||||
.DbSetDossiers
|
||||
.AsNoTracking()
|
||||
.Select(i => i.CodArticolo)
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
}
|
||||
#endregion Public Methods
|
||||
|
||||
#endregion
|
||||
#region Protected Fields
|
||||
|
||||
protected readonly IDbContextFactory<MoonPro_FluxContext> _ctxFactoryFL;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,21 +15,15 @@ namespace MP.Data.Repository.FluxLog
|
||||
{
|
||||
public class FluxLogRepository : IFluxLogRepository
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private readonly IConfiguration _configuration;
|
||||
private static NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public FluxLogRepository(IConfiguration configuration)
|
||||
public FluxLogRepository(IConfiguration configuration, IDbContextFactory<MoonPro_FluxContext> ctxFactoryFL)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_ctxFactoryFL = ctxFactoryFL;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
@@ -60,7 +54,7 @@ namespace MP.Data.Repository.FluxLog
|
||||
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMaccSel);
|
||||
var pOnlyTest = new SqlParameter("@OnlyTest", false);
|
||||
|
||||
await using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
foreach (var item in fluxList)
|
||||
{
|
||||
Log.Info($"FluxLogDataReduxAsync | Flux: {item}");
|
||||
@@ -149,7 +143,7 @@ namespace MP.Data.Repository.FluxLog
|
||||
/// <inheritdoc />
|
||||
public async Task<List<FluxLogModel>> FluxLogGetLastFiltAsync(DateTime DtMax, DateTime DtMin, string IdxMacchina, string CodFlux, int MaxRec)
|
||||
{
|
||||
await using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetFluxLog
|
||||
.AsNoTracking()
|
||||
@@ -162,7 +156,7 @@ namespace MP.Data.Repository.FluxLog
|
||||
/// <inheritdoc />
|
||||
public async Task<List<ParetoFluxLogDTO>> FluxLogParetoAsync(string idxMacchina, DateTime dtFrom, DateTime dtTo)
|
||||
{
|
||||
await using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetFluxLog
|
||||
.Where(x => (string.IsNullOrEmpty(idxMacchina) || x.IdxMacchina == idxMacchina) && (dtFrom <= x.dtEvento && x.dtEvento <= dtTo))
|
||||
@@ -173,6 +167,19 @@ namespace MP.Data.Repository.FluxLog
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
protected readonly IDbContextFactory<MoonPro_FluxContext> _ctxFactoryFL;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger();
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,8 @@ namespace MP.Data.Repository.MpLand
|
||||
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly IDbContextFactory<MoonProContext> _ctxFactory;
|
||||
private readonly IDbContextFactory<MoonPro_FluxContext> _ctxFactoryFluxLog;
|
||||
private readonly IDbContextFactory<MoonPro_STATSContext> _ctxFactoryStats;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -61,11 +63,12 @@ namespace MP.Data.Repository.MpLand
|
||||
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.All")))
|
||||
{
|
||||
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
||||
var singleRes = await dbCtx
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync();
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
dbResult.Add(singleRes);
|
||||
@@ -73,12 +76,13 @@ namespace MP.Data.Repository.MpLand
|
||||
}
|
||||
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.Flux")))
|
||||
{
|
||||
await using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
var singleRes = await dbCtx
|
||||
await using var dbCtx = await _ctxFactoryFluxLog.CreateDbContextAsync();
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync();
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
dbResult.Add(singleRes);
|
||||
@@ -86,12 +90,13 @@ namespace MP.Data.Repository.MpLand
|
||||
}
|
||||
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.Stats")))
|
||||
{
|
||||
await using var dbCtx = new MoonPro_STATSContext(_configuration);
|
||||
var singleRes = await dbCtx
|
||||
await using var dbCtx = await _ctxFactoryStats.CreateDbContextAsync();
|
||||
var singleRes = dbCtx
|
||||
.DbSetDbSize
|
||||
.FromSqlRaw(stp_DbInfo)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync();
|
||||
.AsEnumerable()
|
||||
.FirstOrDefault();
|
||||
if (singleRes != null)
|
||||
{
|
||||
dbResult.Add(singleRes);
|
||||
|
||||
@@ -6,10 +6,35 @@ namespace MP.Data.Repository.MpVoc
|
||||
{
|
||||
public interface IMpVocRepository
|
||||
{
|
||||
Task<List<ConfigModel>> ConfigGetAllAsync();
|
||||
#region Public Methods
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Recupero elenco config
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<ConfigModel>> ConfigGetAllAsync();
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// recupero elenco lingue
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<LingueModel>> LingueGetAllAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Recupero tutte le voci dizionario, async
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<VocabolarioModel>> VocabolarioGetAllAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Recupero dizionario traduzioni x singola lingua
|
||||
/// </summary>
|
||||
/// <param name="lingua">Codice lingua</param>
|
||||
/// <returns>Dizionario di traduzioni</returns>
|
||||
Dictionary<string, string> VocabolarioGetLang(string lingua);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MP.Data.DbModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -8,12 +9,6 @@ namespace MP.Data.Repository.MpVoc
|
||||
{
|
||||
public class MpVocRepository : IMpVocRepository
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private readonly IDbContextFactory<MoonPro_VocContext> _ctxFactory;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public MpVocRepository(IDbContextFactory<MoonPro_VocContext> ctxFactory)
|
||||
@@ -21,10 +16,11 @@ namespace MP.Data.Repository.MpVoc
|
||||
_ctxFactory = ctxFactory;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
#if false
|
||||
/// <inheritdoc />
|
||||
public async Task<List<ConfigModel>> ConfigGetAllAsync()
|
||||
{
|
||||
@@ -34,7 +30,8 @@ namespace MP.Data.Repository.MpVoc
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Chiave)
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<LingueModel>> LingueGetAllAsync()
|
||||
@@ -58,6 +55,28 @@ namespace MP.Data.Repository.MpVoc
|
||||
.ToListAsync() ?? new();
|
||||
}
|
||||
|
||||
#endregion
|
||||
/// <inheritdoc />
|
||||
public Dictionary<string, string> VocabolarioGetLang(string lingua)
|
||||
{
|
||||
using var dbCtx = _ctxFactory.CreateDbContextAsync().GetAwaiter().GetResult();
|
||||
var rawList = dbCtx
|
||||
.DbSetVocabolario
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Lingua.ToLower() == lingua.ToLower())
|
||||
.OrderBy(x => x.Lemma)
|
||||
.ToList();
|
||||
// Proietto in dizionario
|
||||
return rawList
|
||||
.DistinctBy(t => t.Lemma, StringComparer.OrdinalIgnoreCase)
|
||||
.ToDictionary(t => t.Lemma, t => t.Traduzione, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IDbContextFactory<MoonPro_VocContext> _ctxFactory;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,6 +106,7 @@ namespace MP.Data.Repository.Production
|
||||
Task<List<AnagGiacenzeModel>> ListGiacenzeAsync(int IdxOdl);
|
||||
|
||||
Task<List<AnagOperatoriModel>> OperatoriGetFiltAsync(string codGruppo);
|
||||
Task<bool> OperatoriUpsertAsync(AnagOperatoriModel updRec);
|
||||
|
||||
Task<List<string>> ParametriGetFiltAsync(string IdxMacchina);
|
||||
|
||||
|
||||
@@ -19,10 +19,15 @@ namespace MP.Data.Repository.Production
|
||||
#endregion
|
||||
|
||||
#region Public Constructors
|
||||
protected readonly IDbContextFactory<MoonPro_FluxContext> _ctxFactoryFL;
|
||||
|
||||
public ProductionRepository(IDbContextFactory<MoonProContext> ctxFactory, IConfiguration configuration)
|
||||
public ProductionRepository(
|
||||
IConfiguration configuration,
|
||||
IDbContextFactory<MoonProContext> ctxFactory,
|
||||
IDbContextFactory<MoonPro_FluxContext> ctxFactoryFL)
|
||||
{
|
||||
_ctxFactory = ctxFactory;
|
||||
_ctxFactoryFL = ctxFactoryFL;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
@@ -686,7 +691,7 @@ namespace MP.Data.Repository.Production
|
||||
/// <inheritdoc />
|
||||
public async Task<List<string>> MacchineWithFluxAsync(DateTime dtStart, DateTime dtEnd)
|
||||
{
|
||||
await using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetFluxLog
|
||||
.AsNoTracking()
|
||||
@@ -841,10 +846,23 @@ namespace MP.Data.Repository.Production
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public async Task<bool> OperatoriUpsertAsync(AnagOperatoriModel updRec)
|
||||
{
|
||||
await using var dbCtx = await GetMoonProContextAsync();
|
||||
var dbRec = await dbCtx
|
||||
.DbOperatori
|
||||
.FindAsync(updRec.MatrOpr);
|
||||
if (dbRec != null)
|
||||
{
|
||||
dbCtx.Entry(dbRec).CurrentValues.SetValues(updRec);
|
||||
}
|
||||
return await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<string>> ParametriGetFiltAsync(string IdxMacchina)
|
||||
{
|
||||
await using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetFluxLog
|
||||
.AsNoTracking()
|
||||
|
||||
@@ -9,6 +9,8 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
using static Org.BouncyCastle.Asn1.Cmp.Challenge;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
@@ -19,10 +21,12 @@ namespace MP.Data.Services
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public BaseServ(IConfiguration configuration, IConnectionMultiplexer redConn)
|
||||
public BaseServ(IConfiguration configuration, IFusionCache cache, IConnectionMultiplexer redConn)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_cache = cache;
|
||||
|
||||
slowLogThresh = _configuration.GetValue<double>("ServerConf:slowLogThresh", 1);
|
||||
// Verifica conf trace...
|
||||
_traceEnabled = _configuration.GetValue<bool>("Otel:EnableTracing", false);
|
||||
|
||||
@@ -161,13 +165,23 @@ namespace MP.Data.Services
|
||||
/// </summary>
|
||||
protected static readonly ActivitySource ActivitySource = new ActivitySource("MP.IOC");
|
||||
|
||||
protected IConfiguration _configuration = null!;
|
||||
/// <summary>
|
||||
/// Oggetto gestione FusionCache
|
||||
/// </summary>
|
||||
protected readonly IFusionCache _cache;
|
||||
|
||||
/// <summary>
|
||||
/// Path base chiavi REDIS
|
||||
/// </summary>
|
||||
protected readonly string _redisBaseKey = "MP:IOC";
|
||||
|
||||
/// <summary>
|
||||
/// Abilitazione operazioni tracing generiche
|
||||
/// </summary>
|
||||
protected readonly bool _traceEnabled = false;
|
||||
|
||||
protected IConfiguration _configuration = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto per connessione a REDIS
|
||||
/// </summary>
|
||||
@@ -180,8 +194,19 @@ namespace MP.Data.Services
|
||||
protected IDatabase _redisDb = null!;
|
||||
|
||||
protected JsonSerializerSettings? JSSettings;
|
||||
|
||||
protected string MpIoNS = "";
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache Lunga standard (300 sec)
|
||||
/// </summary>
|
||||
protected int redisLongTimeCache = 300;
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache Breve standard (5 sec)
|
||||
/// </summary>
|
||||
protected int redisShortTimeCache = 5;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Properties
|
||||
@@ -281,6 +306,75 @@ namespace MP.Data.Services
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementa gestione FusionCache+ tracking attività
|
||||
/// - recupero cache da memoria o da obj esterno + cache memoria
|
||||
/// - recupero da fetchFunc se mancasse + store in cache L1/L2
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="cacheKey"></param>
|
||||
/// <param name="fetchFunc"></param>
|
||||
/// <param name="expiration"></param>
|
||||
/// <returns></returns>
|
||||
protected async Task<T> GetOrFetchAsync<T>(string operationName, string cacheKey, Func<Task<T>> fetchFunc, TimeSpan expiration, params string[] tagList)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity(operationName);
|
||||
string source;
|
||||
var tryGet = await _cache.TryGetAsync<T>(cacheKey);
|
||||
if (tryGet.HasValue)
|
||||
{
|
||||
source = "MEMORY";
|
||||
var result = tryGet.Value!;
|
||||
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
// se supero la soglia loggo...
|
||||
if (activity?.Duration.TotalMilliseconds > slowLogThresh)
|
||||
{
|
||||
LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
bool fromDb = false;
|
||||
// cache in redis
|
||||
var cacheOptions = new FusionCacheEntryOptions()
|
||||
.SetDuration(expiration)
|
||||
.SetFailSafe(true);
|
||||
// cache in RAM per 1/3 del tempo x risparmiare risorse
|
||||
cacheOptions.MemoryCacheDuration = expiration / 3;
|
||||
|
||||
var final = await _cache.GetOrSetAsync<T>(
|
||||
cacheKey,
|
||||
async _ =>
|
||||
{
|
||||
fromDb = true;
|
||||
return await fetchFunc();
|
||||
},
|
||||
options: cacheOptions,
|
||||
tags: tagList
|
||||
);
|
||||
|
||||
source = fromDb ? "DB" : "REDIS";
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
// switch log in base a source..
|
||||
switch (source)
|
||||
{
|
||||
case "DB":
|
||||
LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms", reqLevel: NLog.LogLevel.Info);
|
||||
break;
|
||||
|
||||
case "REDIS":
|
||||
LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms", reqLevel: NLog.LogLevel.Debug);
|
||||
break;
|
||||
|
||||
default:
|
||||
LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms");
|
||||
break;
|
||||
}
|
||||
return final!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper generale di lettura da cache o da funzione (DB) con caching successivo
|
||||
/// </summary>
|
||||
@@ -327,6 +421,18 @@ namespace MP.Data.Services
|
||||
return result!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce un timeout dal valore secondi richiesti + tempo random +/-3%
|
||||
/// </summary>
|
||||
/// <param name="durationSec"></param>
|
||||
/// <returns></returns>
|
||||
protected TimeSpan GetRandTOut(double durationSec)
|
||||
{
|
||||
double noise = (rand.NextDouble() * 0.06) - 0.03;
|
||||
double rValue = durationSec * (1 + noise);
|
||||
return TimeSpan.FromSeconds(rValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper trace messaggio log (SE abilitato)
|
||||
/// </summary>
|
||||
@@ -396,6 +502,7 @@ namespace MP.Data.Services
|
||||
#region Private Fields
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private bool _disposed = false;
|
||||
|
||||
/// <summary>
|
||||
@@ -408,12 +515,14 @@ namespace MP.Data.Services
|
||||
/// </summary>
|
||||
private int cacheTtlShort = 60 * 1;
|
||||
|
||||
private Random rand = new Random();
|
||||
|
||||
private Random rnd = new Random();
|
||||
|
||||
/// <summary>
|
||||
/// Path base chiavi REDIS
|
||||
/// Soglia minima (ms) per log timing in console
|
||||
/// </summary>
|
||||
protected readonly string _redisBaseKey = "MP:IOC";
|
||||
private double slowLogThresh = 0;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
|
||||
@@ -23,17 +23,19 @@ namespace MP.Data.Services.IOC
|
||||
public IocService(
|
||||
IConfiguration config,
|
||||
IConnectionMultiplexer redis,
|
||||
IFusionCache cache,
|
||||
IIocRepository repo,
|
||||
IServiceScopeFactory scopeFactory,
|
||||
//Microsoft.Extensions.Caching.Memory.IMemoryCache cache
|
||||
IFusionCache cache) : base(config, redis)
|
||||
IServiceScopeFactory scopeFactory
|
||||
) : base(config, cache, redis)
|
||||
{
|
||||
_className = "IocServ";
|
||||
int.TryParse(config.GetValue<string>("ServerConf:redisLongTimeCache"), out redisLongTimeCache);
|
||||
int.TryParse(config.GetValue<string>("ServerConf:redisShortTimeCache"), out redisShortTimeCache);
|
||||
_repo = repo;
|
||||
_scopeFactory = scopeFactory;
|
||||
_cache = cache;
|
||||
#if false
|
||||
_cache = cache;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
@@ -79,7 +81,7 @@ namespace MP.Data.Services.IOC
|
||||
result = await GetCurrOdlByProdAsync(idxMacchina);
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
_redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache));
|
||||
_redisDb.StringSet(currKey, rawData, GetRandTOut(redisLongTimeCache));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -261,16 +263,18 @@ namespace MP.Data.Services.IOC
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Restituisce un timeout dai minuti richiesti + tempo random 1..60 sec
|
||||
/// </summary>
|
||||
/// <param name="stdMinutes"></param>
|
||||
/// <returns></returns>
|
||||
protected TimeSpan getRandTOut(double stdMinutes)
|
||||
protected TimeSpan GetRandTOut(double stdMinutes)
|
||||
{
|
||||
double rndValue = stdMinutes + (double)rand.Next(1, 60) / 60;
|
||||
return TimeSpan.FromMinutes(rndValue);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
@@ -278,7 +282,9 @@ namespace MP.Data.Services.IOC
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private readonly IFusionCache _cache;
|
||||
#if false
|
||||
private readonly IFusionCache _cache;
|
||||
#endif
|
||||
|
||||
private readonly string _className;
|
||||
|
||||
@@ -295,9 +301,11 @@ namespace MP.Data.Services.IOC
|
||||
/// </summary>
|
||||
private string dtFormat = "yyyyMMddHHmmssfff";
|
||||
|
||||
#if false
|
||||
private int redisLongTimeCache = 5;
|
||||
|
||||
private int redisShortTimeCache = 2;
|
||||
private int redisShortTimeCache = 2;
|
||||
#endif
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
@@ -417,7 +425,7 @@ namespace MP.Data.Services.IOC
|
||||
{
|
||||
result = await _repo.ConfigGetAllAsync();
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await _redisDb.StringSetAsync(MP.Data.Utils.redisConfKey, rawData, getRandTOut(redisLongTimeCache));
|
||||
await _redisDb.StringSetAsync(MP.Data.Utils.redisConfKey, rawData, GetRandTOut(redisLongTimeCache));
|
||||
}
|
||||
Log.Debug($"ConfigGetAllAsync Read from {source}");
|
||||
if (result == null)
|
||||
@@ -544,7 +552,7 @@ namespace MP.Data.Services.IOC
|
||||
var fullList = await Macchine2SlaveGetAllAsync();
|
||||
result = fullList.Select(x => x.IdxMacchina).ToHashSet<string>();
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await _redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10));
|
||||
await _redisDb.StringSetAsync(currKey, rawData, GetRandTOut(redisLongTimeCache * 10));
|
||||
}
|
||||
return result;
|
||||
}, TimeSpan.FromMinutes(15));
|
||||
@@ -566,7 +574,7 @@ namespace MP.Data.Services.IOC
|
||||
var fullList = await Macchine2SlaveGetAllAsync();
|
||||
result = fullList.Select(x => x.IdxMacchinaSlave).Distinct().ToHashSet<string>();
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await _redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10));
|
||||
await _redisDb.StringSetAsync(currKey, rawData, GetRandTOut(redisLongTimeCache * 10));
|
||||
}
|
||||
return result;
|
||||
}, TimeSpan.FromMinutes(15));
|
||||
@@ -593,7 +601,7 @@ namespace MP.Data.Services.IOC
|
||||
result = await _repo.Macchine2SlaveAsync();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await _redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10));
|
||||
await _redisDb.StringSetAsync(currKey, rawData, GetRandTOut(redisLongTimeCache * 10));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
|
||||
@@ -14,6 +14,7 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
@@ -21,7 +22,12 @@ namespace MP.Data.Services
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public LandDataService(IConfiguration configuration, IConnectionMultiplexer redConn, Repository.MpLand.IMpLandRepository mpLandRepository) : base(configuration, redConn)
|
||||
public LandDataService(
|
||||
IConfiguration configuration,
|
||||
IConnectionMultiplexer redConn,
|
||||
IFusionCache cache,
|
||||
Repository.MpLand.IMpLandRepository mpLandRepository
|
||||
) : base(configuration, cache, redConn)
|
||||
{
|
||||
_mpLandRepository = mpLandRepository;
|
||||
// conf DB
|
||||
@@ -46,7 +52,7 @@ namespace MP.Data.Services
|
||||
/// Restituisce info dimensione, tabelle e num righe DB
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<DbSizeModel> AllDbInfo()
|
||||
public async Task<List<DbSizeModel>> AllDbInfoAsync()
|
||||
{
|
||||
// setup parametri costanti
|
||||
string source = "DB";
|
||||
@@ -55,7 +61,7 @@ namespace MP.Data.Services
|
||||
List<DbSizeModel> result = new List<DbSizeModel>();
|
||||
// cerco in _redisConn...
|
||||
string currKey = $"{redisBaseKey}:DbInfo:ALL";
|
||||
RedisValue rawData = _redisDb.StringGet(currKey);
|
||||
RedisValue rawData = await _redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<DbSizeModel>>($"{rawData}");
|
||||
@@ -63,17 +69,17 @@ namespace MP.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
result = _mpLandRepository.AllDbInfoAsync().GetAwaiter().GetResult();
|
||||
result = await _mpLandRepository.AllDbInfoAsync();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
_redisDb.StringSet(currKey, rawData, UltraFastCache);
|
||||
await _redisDb.StringSetAsync(currKey, rawData, UltraFastCache);
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<DbSizeModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"AllDbInfo | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"AllDbInfoAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
@@ -33,7 +34,14 @@ namespace MP.Data.Services
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public ListSelectDataSrv(IConfiguration configuration, IConnectionMultiplexer redConn, IAnagRepository anagRepository, IProductionRepository productionRepository, ISystemRepository systemRepository) : base(configuration, redConn)
|
||||
public ListSelectDataSrv(
|
||||
IConfiguration configuration,
|
||||
IConnectionMultiplexer redConn,
|
||||
IFusionCache cache,
|
||||
IAnagRepository anagRepository,
|
||||
IProductionRepository productionRepository,
|
||||
ISystemRepository systemRepository
|
||||
) : base(configuration, cache, redConn)
|
||||
{
|
||||
_anagRepository = anagRepository;
|
||||
_productionRepository = productionRepository;
|
||||
|
||||
@@ -5,6 +5,7 @@ using MP.Data.Repository.Mtc;
|
||||
using StackExchange.Redis;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services.Mtc
|
||||
{
|
||||
@@ -18,7 +19,8 @@ namespace MP.Data.Services.Mtc
|
||||
public MtcSetupService(
|
||||
IConfiguration config,
|
||||
IConnectionMultiplexer redis,
|
||||
IMtcSetupRepository repo) : base(config, redis)
|
||||
IFusionCache cache,
|
||||
IMtcSetupRepository repo) : base(config, cache, redis)
|
||||
{
|
||||
_className = "MtcSetup";
|
||||
_repo = repo;
|
||||
|
||||
@@ -11,6 +11,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
@@ -31,7 +32,13 @@ namespace MP.Data.Services
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public OrderDataSrv(IConfiguration configuration, IConnectionMultiplexer redConn, IProductionRepository productionRepository, ISystemRepository systemRepository) : base(configuration, redConn)
|
||||
public OrderDataSrv(
|
||||
IConfiguration configuration,
|
||||
IConnectionMultiplexer redConn,
|
||||
IFusionCache cache,
|
||||
IProductionRepository productionRepository,
|
||||
ISystemRepository systemRepository
|
||||
) : base(configuration, cache, redConn)
|
||||
{
|
||||
_productionRepository = productionRepository;
|
||||
_systemRepository = systemRepository;
|
||||
|
||||
@@ -4,6 +4,7 @@ using StackExchange.Redis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
@@ -13,7 +14,11 @@ namespace MP.Data.Services
|
||||
/// Init servizio TAB
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
public SchedulerDataService(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn)
|
||||
public SchedulerDataService(
|
||||
IConfiguration configuration,
|
||||
IConnectionMultiplexer redConn,
|
||||
IFusionCache cache
|
||||
) : base(configuration, cache, redConn)
|
||||
{
|
||||
_configuration = configuration;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using NLog;
|
||||
using StackExchange.Redis;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
@@ -15,7 +16,11 @@ namespace MP.Data.Services
|
||||
/// Init servizio TAB
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
public SharedMemService(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn)
|
||||
public SharedMemService(
|
||||
IConfiguration configuration,
|
||||
IConnectionMultiplexer redConn,
|
||||
IFusionCache cache
|
||||
) : base(configuration, cache, redConn)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Core.DTO;
|
||||
using MP.Core.Objects;
|
||||
using MP.Data.Controllers;
|
||||
using MP.Data.DbModels;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
@@ -15,6 +16,7 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
@@ -26,7 +28,12 @@ namespace MP.Data.Services
|
||||
/// Init servizio TAB
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
public TabDataService(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn)
|
||||
public TabDataService(
|
||||
IConfiguration configuration,
|
||||
IConnectionMultiplexer redConn,
|
||||
IFusionCache cache,
|
||||
MpIocController iocContr
|
||||
) : base(configuration, cache, redConn)
|
||||
{
|
||||
_configuration = configuration;
|
||||
|
||||
@@ -41,7 +48,7 @@ namespace MP.Data.Services
|
||||
StringBuilder sb = new StringBuilder();
|
||||
dbTabController = new Controllers.MpTabController(configuration);
|
||||
sb.AppendLine($"TabDataService | MpTabController OK");
|
||||
dbIocController = new Controllers.MpIocController(configuration);
|
||||
dbIocController = iocContr;// new Controllers.MpIocController(configuration);
|
||||
sb.AppendLine($"TabDataService | MpIocController OK");
|
||||
dbInveController = new Controllers.MpInveController(configuration);
|
||||
sb.AppendLine($"TabDataService | MpInveController OK");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Core.Conf;
|
||||
using MP.Data.DbModels;
|
||||
using MP.Data.Repository.FluxLog;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using StackExchange.Redis;
|
||||
@@ -13,6 +14,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services
|
||||
{
|
||||
@@ -23,30 +25,57 @@ namespace MP.Data.Services
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public TranslateSrv(IConfiguration configuration, IConnectionMultiplexer redConn, Repository.MpVoc.IMpVocRepository mpVocRepository) : base(configuration, redConn)
|
||||
public TranslateSrv(
|
||||
IConfiguration configuration,
|
||||
IConnectionMultiplexer redConn,
|
||||
IFusionCache cache,
|
||||
Repository.MpVoc.IMpVocRepository mpVocRepository
|
||||
) : base(configuration, cache, redConn)
|
||||
{
|
||||
_mpVocRepository = mpVocRepository;
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
// conf DB
|
||||
string connStr = _configuration.GetConnectionString("MP.Voc");
|
||||
if (string.IsNullOrEmpty(connStr))
|
||||
{
|
||||
Log.Error("MP.Voc: ConnString empty!");
|
||||
}
|
||||
else
|
||||
{
|
||||
var _ = _mpVocRepository.ConfigGetAllAsync().GetAwaiter().GetResult();
|
||||
InitDict();
|
||||
sw.Stop();
|
||||
Log.Info($"TranslateSrv | MpVocRepository OK | {sw.Elapsed.TotalMilliseconds} ms");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Esegue traduzione dato vocabolario da Lingua + Lemma
|
||||
/// </summary>
|
||||
/// <param name="lemma"></param>
|
||||
/// <param name="lingua"></param>
|
||||
/// <returns></returns>
|
||||
public string Traduci(string lemma, string lingua = "IT")
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(lemma)) return string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(lingua)) return lemma;
|
||||
|
||||
string linguaKey = lingua.ToLowerInvariant().Trim();
|
||||
string cacheKey = $"vocab:{linguaKey}";
|
||||
|
||||
// FusionCache gestisce il lock e recupera l'intero dizionario della lingua.
|
||||
// Se è in L1 (Memory), restituisce l'oggetto C# istantaneamente.
|
||||
// Se non c'è, passa a L2 (Redis) o invoca la factory per caricarlo.
|
||||
var dizionarioLingua = _cache.GetOrSet<Dictionary<string, string>>(
|
||||
cacheKey,
|
||||
_ => _mpVocRepository.VocabolarioGetLang(linguaKey),
|
||||
options => options
|
||||
.SetDuration(TimeSpan.FromHours(8)) // Durata logica della cache
|
||||
.SetFailSafe(true, TimeSpan.FromHours(1)) // Se Redis/DB è giù, usa i vecchi dati L1
|
||||
);
|
||||
|
||||
// Ricerca O(1) nel dizionario in memoria
|
||||
if (dizionarioLingua != null && dizionarioLingua.TryGetValue(lemma, out var traduzione))
|
||||
{
|
||||
return traduzione;
|
||||
}
|
||||
|
||||
// Fallback: se la parola non è censita, restituisce il lemma originale (lingua + lemma)
|
||||
return $"{lingua}_{lemma}";
|
||||
}
|
||||
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Recupero elenco config
|
||||
/// </summary>
|
||||
@@ -80,7 +109,8 @@ namespace MP.Data.Services
|
||||
sw.Stop();
|
||||
Log.Debug($"ConfigGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Pulizia cache Redis (tutta)
|
||||
@@ -88,12 +118,15 @@ namespace MP.Data.Services
|
||||
/// <returns></returns>
|
||||
public async Task<bool> FlushCache()
|
||||
{
|
||||
#if false
|
||||
RedisValue pattern = new RedisValue($"{redisBaseKey}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
// rileggo vocabolario!
|
||||
var rawData = await VocabolarioGetAll();
|
||||
DictVocab = rawData.ToDictionary(kvp => $"{kvp.Lingua}_{kvp.Lemma}".ToUpper(), kvp => kvp.Traduzione);
|
||||
return answ;
|
||||
return answ;
|
||||
#endif
|
||||
return await FlushFusionCacheAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -102,9 +135,51 @@ namespace MP.Data.Services
|
||||
/// <returns></returns>
|
||||
public async Task<bool> FlushCache(string KeyReq)
|
||||
{
|
||||
#if false
|
||||
RedisValue pattern = new RedisValue($"{redisBaseKey}:{KeyReq}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
return answ;
|
||||
return answ;
|
||||
#endif
|
||||
return await FlushFusionCacheAsync(KeyReq);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancellazione FusionCache (totale)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> FlushFusionCacheAsync()
|
||||
{
|
||||
await _cache.ClearAsync(allowFailSafe: false);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancellazione FusionCache dato singolo tag
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> FlushFusionCacheAsync(string tag)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(tag)) return false;
|
||||
|
||||
await _cache.RemoveByTagAsync(tag);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancellazione FusionCache dato elenco tags
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> FlushFusionCacheAsync(List<string> listTags)
|
||||
{
|
||||
if (listTags == null || listTags.Count == 0) return false;
|
||||
|
||||
// Generiamo i Task di rimozione ed eseguiamoli in parallelo su Redis/L1
|
||||
var tasks = listTags
|
||||
.Where(tag => !string.IsNullOrWhiteSpace(tag))
|
||||
.Select(tag => _cache.RemoveByTagAsync(tag).AsTask());
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -113,6 +188,17 @@ namespace MP.Data.Services
|
||||
/// <returns></returns>
|
||||
public async Task<List<LingueModel>> LingueGetAll()
|
||||
{
|
||||
string currKey = $"{redisBaseKey}:Lang";
|
||||
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "LingueGetAll",
|
||||
cacheKey: currKey,
|
||||
expiration: GetRandTOut(redisShortTimeCache),
|
||||
fetchFunc: async () => await _mpVocRepository.LingueGetAllAsync() ?? new(),
|
||||
tagList: [currKey]
|
||||
);
|
||||
|
||||
#if false
|
||||
string source = "DB";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
@@ -139,9 +225,11 @@ namespace MP.Data.Services
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"LingueGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Traduzione termine
|
||||
/// </summary>
|
||||
@@ -157,7 +245,8 @@ namespace MP.Data.Services
|
||||
answ = DictVocab[key];
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Recupero elenco config
|
||||
@@ -165,6 +254,18 @@ namespace MP.Data.Services
|
||||
/// <returns></returns>
|
||||
public async Task<List<VocabolarioModel>> VocabolarioGetAll()
|
||||
{
|
||||
string currKey = $"{redisBaseKey}:VocAll";
|
||||
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "VocabolarioGetAll",
|
||||
cacheKey: currKey,
|
||||
expiration: GetRandTOut(redisShortTimeCache),
|
||||
fetchFunc: async () => await _mpVocRepository.VocabolarioGetAllAsync() ?? new(),
|
||||
tagList: [currKey]
|
||||
);
|
||||
|
||||
|
||||
#if false
|
||||
string source = "DB";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
@@ -191,46 +292,31 @@ namespace MP.Data.Services
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"VocabolarioGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Vocabolario x recupero rapido traduzioni
|
||||
/// </summary>
|
||||
protected static Dictionary<string, string> DictVocab = new Dictionary<string, string>();
|
||||
protected static Dictionary<string, string> DictVocab = new Dictionary<string, string>();
|
||||
#endif
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// Free managed resources here
|
||||
DictVocab.Clear();
|
||||
}
|
||||
|
||||
// Free unmanaged resources here
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
// Call base class implementation.
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private bool _disposed = false;
|
||||
|
||||
private string redisBaseKey = "MP:Voc:Cache";
|
||||
|
||||
private readonly Repository.MpVoc.IMpVocRepository _mpVocRepository;
|
||||
@@ -239,16 +325,8 @@ namespace MP.Data.Services
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Inizializzazione dict vari
|
||||
/// </summary>
|
||||
private void InitDict()
|
||||
{
|
||||
// inizializzo dizionario vocabolario
|
||||
var rawData = _mpVocRepository.VocabolarioGetAllAsync().GetAwaiter().GetResult();
|
||||
DictVocab = rawData.ToDictionary(kvp => $"{kvp.Lingua}_{kvp.Lemma}".ToUpper(), kvp => kvp.Traduzione);
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Esegue flush memoria _redisConn dato pat2Flush
|
||||
/// </summary>
|
||||
@@ -287,26 +365,10 @@ namespace MP.Data.Services
|
||||
}
|
||||
}
|
||||
answ = true;
|
||||
#if false
|
||||
var listEndpoints = redisConn.GetEndPoints();
|
||||
foreach (var endPoint in listEndpoints)
|
||||
{
|
||||
//var server = redisConnAdmin.GetServer(listEndpoints[0]);
|
||||
var server = redisConn.GetServer(endPoint);
|
||||
if (server != null)
|
||||
{
|
||||
var keyList = server.Keys(redisDb.Database, pattern);
|
||||
foreach (var item in keyList)
|
||||
{
|
||||
await redisDb.KeyDeleteAsync(item);
|
||||
}
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services.Utils
|
||||
{
|
||||
@@ -19,7 +20,8 @@ namespace MP.Data.Services.Utils
|
||||
public StatsAggrService(
|
||||
IConfiguration config,
|
||||
IConnectionMultiplexer redis,
|
||||
IStatsAggrRepository repo) : base(config, redis)
|
||||
IFusionCache cache,
|
||||
IStatsAggrRepository repo) : base(config, cache, redis)
|
||||
{
|
||||
_className = "StatsAggr";
|
||||
_repo = repo;
|
||||
|
||||
@@ -9,6 +9,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services.Utils
|
||||
{
|
||||
@@ -19,7 +20,9 @@ namespace MP.Data.Services.Utils
|
||||
public StatsCodeService(
|
||||
IConfiguration config,
|
||||
IConnectionMultiplexer redis,
|
||||
IStatsCodeRepository repo) : base(config, redis)
|
||||
IFusionCache cache,
|
||||
IStatsCodeRepository repo
|
||||
) : base(config, cache, redis)
|
||||
{
|
||||
_className = "StatsStatusCode";
|
||||
_repo = repo;
|
||||
|
||||
@@ -9,6 +9,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services.Utils
|
||||
{
|
||||
@@ -19,7 +20,9 @@ namespace MP.Data.Services.Utils
|
||||
public StatsDetailService(
|
||||
IConfiguration config,
|
||||
IConnectionMultiplexer redis,
|
||||
IStatsDetailRepository repo) : base(config, redis)
|
||||
IFusionCache cache,
|
||||
IStatsDetailRepository repo
|
||||
) : base(config,cache, redis)
|
||||
{
|
||||
_className = "StatsDetail";
|
||||
_repo = repo;
|
||||
|
||||
@@ -9,6 +9,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace MP.Data.Services.Utils
|
||||
{
|
||||
@@ -19,7 +20,9 @@ namespace MP.Data.Services.Utils
|
||||
public StatsErrService(
|
||||
IConfiguration config,
|
||||
IConnectionMultiplexer redis,
|
||||
IStatsErrRepository repo) : base(config, redis)
|
||||
IFusionCache cache,
|
||||
IStatsErrRepository repo
|
||||
) : base(config,cache, redis)
|
||||
{
|
||||
_className = "StatsErr";
|
||||
_repo = repo;
|
||||
|
||||
@@ -55,8 +55,7 @@ namespace MP.SPEC.Components
|
||||
}
|
||||
// eseguo chiusura finale
|
||||
CurrAction.IsActive = false;
|
||||
MDService.ActionSetReqAsync(CurrAction);
|
||||
await Task.Delay(1);
|
||||
await MDService.ActionSetReqAsync(CurrAction);
|
||||
}
|
||||
|
||||
protected async Task doConfirm()
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
<h4>Operatori</h4>
|
||||
</div>
|
||||
<div class="px-0">
|
||||
<button @onclick="() => ToggleAddNew()" class="btn @addNewCss btn-sm"><i class="fa-solid @addNewIcon"></i> @addNewTxt</button>
|
||||
@if (AddEnabled)
|
||||
{
|
||||
<button @onclick="() => ToggleAddNew()" class="btn @addNewCss btn-sm"><i class="fa-solid @addNewIcon"></i> @addNewTxt</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -33,25 +36,51 @@
|
||||
<table class="table table-sm table-striped small">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><button class="btn btn-sm btn-info" title="Reset" @onclick="DoReset"><i class="fa-solid fa-rotate"></i></button></th>
|
||||
<th><i class="fa-solid fa-key"></i> Matr.</th>
|
||||
<th><i class="fa-solid fa-object-group"></i> Anagr.</th>
|
||||
<th class="text-end"></th>
|
||||
@if (DelEnabled)
|
||||
{
|
||||
<th class="text-end"></th>
|
||||
}
|
||||
@if (StaChgEnab)
|
||||
{
|
||||
<th class="text-end"></th>
|
||||
}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var record in ListRecords)
|
||||
@foreach (var item in ListRecords)
|
||||
{
|
||||
<tr>
|
||||
<tr class="@cssRow(item)">
|
||||
<td>
|
||||
<div>@record.MatrOpr</div>
|
||||
<button class="btn btn-sm btn-info" title="Mostra Assegnazioni" @onclick="() => DoSelect(item)"><i class="fa-solid fa-search"></i></button>
|
||||
</td>
|
||||
<td>
|
||||
<div>@record.Cognome @record.Nome</div>
|
||||
<td class="@cssCol(item)">
|
||||
<div>@item.MatrOpr</div>
|
||||
</td>
|
||||
|
||||
<td class="text-end">
|
||||
<button @onclick="() => DoDelete(record)" class="btn btn-danger btn-sm"><i class="bi bi-trash-fill"></i></button>
|
||||
<td class="@cssCol(item)">
|
||||
<div>@item.Cognome @item.Nome</div>
|
||||
</td>
|
||||
@if (DelEnabled)
|
||||
{
|
||||
<td class="text-end">
|
||||
<button @onclick="() => DoDelete(item)" class="btn btn-danger btn-sm"><i class="bi bi-trash-fill"></i></button>
|
||||
</td>
|
||||
}
|
||||
@if (StaChgEnab)
|
||||
{
|
||||
<td class="text-end">
|
||||
@if (item.isEnabled)
|
||||
{
|
||||
<button class="btn btn-sm btn-warning" title="Disabilita Operatore" @onclick="() => ToggleStatusOpr(item)"><i class="fa-solid fa-thumbs-down"></i></button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-sm btn-success" title="Abilita Operatore" @onclick="() => ToggleStatusOpr(item)"><i class="fa-solid fa-thumbs-up"></i></button>
|
||||
}
|
||||
</td>
|
||||
}
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
|
||||
@@ -9,6 +9,9 @@ namespace MP.SPEC.Components.Reparti
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
[Parameter]
|
||||
public bool AddEnabled { get; set; } = true;
|
||||
|
||||
[Parameter]
|
||||
public List<AnagOperatoriModel>? AllRecords { get; set; } = null;
|
||||
|
||||
@@ -18,9 +21,18 @@ namespace MP.SPEC.Components.Reparti
|
||||
[Parameter]
|
||||
public List<AnagOperatoriModel>? CurrRecords { get; set; } = null;
|
||||
|
||||
[Parameter]
|
||||
public bool DelEnabled { get; set; } = true;
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<bool> EC_RecChange { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<AnagOperatoriModel?> EC_RecSel { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool StaChgEnab { get; set; } = false;
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Protected Properties
|
||||
@@ -37,7 +49,7 @@ namespace MP.SPEC.Components.Reparti
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
numRecord = 10;
|
||||
//numRecord = 10;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
@@ -65,7 +77,9 @@ namespace MP.SPEC.Components.Reparti
|
||||
private bool isLoading = false;
|
||||
|
||||
private List<AnagOperatoriModel>? ListAvail;
|
||||
|
||||
private List<AnagOperatoriModel>? ListRecords;
|
||||
|
||||
private int numRecord = 5;
|
||||
|
||||
private int totalCount = 0;
|
||||
@@ -93,6 +107,18 @@ namespace MP.SPEC.Components.Reparti
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private string cssCol(AnagOperatoriModel currRec)
|
||||
{
|
||||
return !currRec.isEnabled ? "opacity-75" : "";
|
||||
}
|
||||
|
||||
private string cssRow(AnagOperatoriModel currRec)
|
||||
{
|
||||
string answ = selRec != null && currRec.MatrOpr == selRec.MatrOpr ? "table-info " : "";
|
||||
answ += !currRec.isEnabled ? "text-secondary disabled text-decoration-line-through" : "";
|
||||
return answ;
|
||||
}
|
||||
|
||||
private async Task DoAdd(AnagOperatoriModel currRec)
|
||||
{
|
||||
// eliminazione dal gruppo
|
||||
@@ -120,6 +146,19 @@ namespace MP.SPEC.Components.Reparti
|
||||
await EC_RecChange.InvokeAsync(false);
|
||||
}
|
||||
|
||||
private AnagOperatoriModel? selRec = null;
|
||||
|
||||
private async Task DoSelect(AnagOperatoriModel sRec)
|
||||
{
|
||||
selRec = sRec;
|
||||
await EC_RecSel.InvokeAsync(sRec);
|
||||
}
|
||||
private async Task DoReset()
|
||||
{
|
||||
selRec = null;
|
||||
await EC_RecSel.InvokeAsync(null);
|
||||
}
|
||||
|
||||
private async Task ReportUpdate(bool force)
|
||||
{
|
||||
AddNewEnabled = false;
|
||||
@@ -131,6 +170,17 @@ namespace MP.SPEC.Components.Reparti
|
||||
AddNewEnabled = !AddNewEnabled;
|
||||
}
|
||||
|
||||
private async Task ToggleStatusOpr(AnagOperatoriModel updRec)
|
||||
{
|
||||
string azione = updRec.isEnabled ? "disabilitarlo" : "abilitarlo";
|
||||
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler modificare l'operatore per {azione}?"))
|
||||
return;
|
||||
|
||||
updRec.isEnabled = !updRec.isEnabled;
|
||||
await MDService.OperatoriUpsertAsync(updRec);
|
||||
await EC_RecChange.InvokeAsync(true);
|
||||
}
|
||||
|
||||
private void UpdateTable()
|
||||
{
|
||||
ListRecords = new();
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<h4>Elenco Reparti</h4>
|
||||
</div>
|
||||
<div class="px-0">
|
||||
@if (SelRecord == null && IsSuperAdmin)
|
||||
@if (SelRecord == null && IsSuperAdmin && EditEnabled)
|
||||
{
|
||||
<button @onclick="() => ToggleAddNew()" class="btn @addNewCss btn-sm"><i class="fa-solid @addNewIcon"></i> @addNewTxt</button>
|
||||
}
|
||||
@@ -95,17 +95,20 @@
|
||||
{
|
||||
<tr class="@CheckSelect(record)">
|
||||
<td class="text-nowrap">
|
||||
@if (EditRec == null)
|
||||
@if (EditEnabled)
|
||||
{
|
||||
<button @onclick="() => DoSelect(record)" class="btn btn-primary btn-sm" title="Seleziona Record"><i class="bi bi-search"></i></button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-secondary disabled btn-sm" title="Seleziona Record"><i class="bi bi-search"></i></button>
|
||||
}
|
||||
@if (SelRecord == null)
|
||||
{
|
||||
<button @onclick="() => DoEdit(record)" class="btn btn-primary btn-sm ms-1" title="Seleziona Record"><i class="fa-solid fa-edit"></i></button>
|
||||
if (EditRec == null)
|
||||
{
|
||||
<button @onclick="() => DoSelect(record)" class="btn btn-primary btn-sm" title="Seleziona Record"><i class="bi bi-search"></i></button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-secondary disabled btn-sm" title="Seleziona Record"><i class="bi bi-search"></i></button>
|
||||
}
|
||||
if (SelRecord == null)
|
||||
{
|
||||
<button @onclick="() => DoEdit(record)" class="btn btn-primary btn-sm ms-1" title="Seleziona Record"><i class="fa-solid fa-edit"></i></button>
|
||||
}
|
||||
}
|
||||
</td>
|
||||
@if (SelRecord == null)
|
||||
@@ -122,13 +125,16 @@
|
||||
<td class="text-end">@record.CountMacc</td>
|
||||
<td class="text-end">@record.CountOpr</td>
|
||||
<td class="text-end">
|
||||
@if (DelEnabled(record))
|
||||
@if (EditEnabled)
|
||||
{
|
||||
<button @onclick="() => DoDelete(record)" class="btn btn-danger btn-sm"><i class="bi bi-trash-fill"></i></button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-secondary disabled btn-sm"><i class="bi bi-trash-fill"></i></button>
|
||||
if (DelEnabled(record))
|
||||
{
|
||||
<button @onclick="() => DoDelete(record)" class="btn btn-danger btn-sm"><i class="bi bi-trash-fill"></i></button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-secondary disabled btn-sm"><i class="bi bi-trash-fill"></i></button>
|
||||
}
|
||||
}
|
||||
</td>
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ namespace MP.SPEC.Components.Reparti
|
||||
[Parameter]
|
||||
public string CodGruppoSel { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public bool EditEnabled { get; set; } = true;
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<string> EC_RecordSel { get; set; }
|
||||
|
||||
|
||||
@@ -702,6 +702,20 @@ namespace MP.SPEC.Data
|
||||
tagList: [Utils.redisAnagGruppi]
|
||||
);
|
||||
}
|
||||
/// <summary>
|
||||
/// Restitusice elenco Reparti
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<RepartiDTO>> GruppiRepartoDtoByOperAsync(int matrOpr)
|
||||
{
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "ElencoRepartiDtoAsync",
|
||||
cacheKey: $"{Utils.redisAnagGruppiOpr}:{matrOpr}",
|
||||
expiration: GetRandTOut(redisLongTimeCache),
|
||||
fetchFunc: async () => await _anagRepository.GruppiRepartoDtoByOperAsync(matrOpr) ?? new(),
|
||||
tagList: [Utils.redisAnagGruppiOpr]
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Caricamento asincrono della cache degli articoli (Used/Unused)
|
||||
@@ -1408,6 +1422,25 @@ namespace MP.SPEC.Data
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiornamento operatori su DB + invalidata cache
|
||||
/// </summary>
|
||||
/// <param name="updRec"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> OperatoriUpsertAsync(AnagOperatoriModel updRec)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("OperatoriUpsertAsync");
|
||||
string source = "DB";
|
||||
bool fatto = false;
|
||||
// salvo
|
||||
fatto = await _productionRepository.OperatoriUpsertAsync(updRec);
|
||||
await FlushFusionCacheAsync(Utils.redisOprList);
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
LogTrace($"OperatoriUpsertAsync | {source} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco di tutti i parametri filtrati x idxMaccSel
|
||||
/// </summary>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>MP.SPEC</RootNamespace>
|
||||
<Version>8.16.2606.311</Version>
|
||||
<Version>8.16.2606.317</Version>
|
||||
<UserSecretsId>1800a78a-6ff1-40f9-b490-87fb8bfc1394</UserSecretsId>
|
||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
@page "/operatori"
|
||||
|
||||
<div class="card mb-5">
|
||||
<div class="card-header table-primary">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="px-0">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="px-2">
|
||||
<span class="fs-3 mb-0">Gestione Operatori</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="px-0 align-content-center d-flex justify-content-end">
|
||||
@* <small class="fs-5">Edit Massivo Fermi</small> *@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (isLoading)
|
||||
{
|
||||
<LoadingData></LoadingData>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row">
|
||||
<div class="@cssMain">
|
||||
<ListOperatori CurrRecords="@ListOperatori" AllRecords="@ListOperatori" AddEnabled="false" DelEnabled="false" StaChgEnab="true" EC_RecSel="ShowDetail"></ListOperatori>
|
||||
</div>
|
||||
@if (SelRec != null)
|
||||
{
|
||||
<div class="col-6">
|
||||
<ListReparti AllRecords="ListGruppi" EditEnabled="false"></ListReparti>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MP.Core.DTO;
|
||||
using MP.Data.DbModels;
|
||||
using MP.SPEC.Data;
|
||||
|
||||
namespace MP.SPEC.Pages
|
||||
{
|
||||
public partial class Operatori
|
||||
{
|
||||
#region Protected Properties
|
||||
|
||||
[Inject]
|
||||
protected MpDataService MDService { get; set; } = null!;
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await ReloadDataAsync();
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private bool isLoading = false;
|
||||
private List<AnagOperatoriModel> ListOperatori = new();
|
||||
private List<RepartiDTO> ListGruppi = new();
|
||||
private AnagOperatoriModel? SelRec = null;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private string cssMain => SelRec == null ? "col-12" : "col-6";
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private async Task ReloadDataAsync()
|
||||
{
|
||||
isLoading = true;
|
||||
ListOperatori = await MDService.OperatoriGetFiltAsync("*");
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
private async Task ShowDetail(AnagOperatoriModel? newRec)
|
||||
{
|
||||
SelRec = newRec;
|
||||
if (SelRec == null)
|
||||
{
|
||||
ListGruppi.Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
// recupero gruppi operatore
|
||||
ListGruppi = await MDService.GruppiRepartoDtoByOperAsync(SelRec.MatrOpr);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
+8
-1
@@ -170,7 +170,14 @@ builder.Services.AddDbContextFactory<MoonPro_VocContext>(options =>
|
||||
.EnableSensitiveDataLogging(false) // true solo in Sviluppo
|
||||
.ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning)));
|
||||
|
||||
// MP.Data Services Utils - Statistiche DB
|
||||
var connStrFL = builder.Configuration.GetConnectionString("MP.Flux")
|
||||
?? throw new InvalidOperationException("ConnString 'MP.Flux' mancante.");
|
||||
builder.Services.AddDbContextFactory<MoonPro_FluxContext>(options =>
|
||||
options.UseSqlServer(connStrFL)
|
||||
.EnableSensitiveDataLogging(false) // true solo in Sviluppo
|
||||
.ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning)));
|
||||
|
||||
// Init centralizzato Repository/Servizi da MP.Data Services
|
||||
builder.Services.AddSpecDataLayer();
|
||||
|
||||
// servizi del progetto SPEC
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MAPOSPEC </i>
|
||||
<h4>Versione: 8.16.2606.311</h4>
|
||||
<h4>Versione: 8.16.2606.317</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
8.16.2606.311
|
||||
8.16.2606.317
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>8.16.2606.311</version>
|
||||
<version>8.16.2606.317</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
Reference in New Issue
Block a user