Completamento migrazione repository MpSpecController: aggiunti MpMon, MpVoc, MpLand; migrati TranslateSrv, StatusData, LandDataService, TranslateSrv, MonDataFeeder, TabDataFeeder; 0 errori build

This commit is contained in:
Samuele E. Locatelli (W11-AI)
2026-06-02 23:59:01 +02:00
parent 843435ad3b
commit 328f7adc06
14 changed files with 496 additions and 92 deletions
@@ -0,0 +1,23 @@
using Microsoft.Extensions.Configuration;
using MP.Data.DbModels;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MP.Data.Repository.MpLand
{
public interface IMpLandRepository
{
Task<List<DbSizeModel>> AllDbInfoAsync();
Task<List<ConfigModel>> ConfigGetAllAsync();
Task<List<RemoteRebootLogModel>> RemRebootLogGetAllAsync();
Task<List<RemoteRebootLogModel>> RemRebootLogGetLastAsync();
Task<List<RemoteRebootLogModel>> RemRebootLogGetLastNoMaccAsync();
Task<List<MacchineModel>> MacchineGetAllAsync();
}
}
@@ -0,0 +1,162 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using MP.Data.DbModels;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MP.Data.Repository.MpLand
{
public class MpLandRepository : IMpLandRepository
{
#region Private Fields
private readonly IConfiguration _configuration;
private readonly IDbContextFactory<MoonProContext> _ctxFactory;
#endregion
#region Public Constructors
public MpLandRepository(IConfiguration configuration, IDbContextFactory<MoonProContext> ctxFactory)
{
_configuration = configuration;
_ctxFactory = ctxFactory;
}
#endregion
#region Public Methods
/// <inheritdoc />
public async Task<List<DbSizeModel>> AllDbInfoAsync()
{
List<DbSizeModel> dbResult = new List<DbSizeModel>();
string stp_DbInfo = @"
;WITH TableRowCounts AS (
SELECT
t.name AS TableName,
SUM(p.rows) AS RowNum
FROM sys.tables t
JOIN sys.partitions p ON t.object_id = p.object_id
WHERE p.index_id IN (0, 1)
GROUP BY t.name
),
LargestTable AS (
SELECT TOP 1 RowNum, TableName
FROM TableRowCounts
ORDER BY RowNum DESC
)
SELECT
DB_name() as DbName,
CAST(SUM(size) * 8.0 / 1024 AS DECIMAL(18,2)) AS DbSizeMb,
(SELECT COUNT(*) FROM sys.tables) AS NumTables,
(SELECT TableName FROM LargestTable) AS BigTable,
(SELECT RowNum FROM LargestTable) AS BigTableRows
FROM sys.master_files
WHERE database_id = DB_ID();
";
try
{
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.All")))
{
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
var singleRes = await dbCtx
.DbSetDbSize
.FromSqlRaw(stp_DbInfo)
.AsNoTracking()
.FirstOrDefaultAsync();
if (singleRes != null)
{
dbResult.Add(singleRes);
}
}
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.Flux")))
{
await using var dbCtx = new MoonPro_FluxContext(_configuration);
var singleRes = await dbCtx
.DbSetDbSize
.FromSqlRaw(stp_DbInfo)
.AsNoTracking()
.FirstOrDefaultAsync();
if (singleRes != null)
{
dbResult.Add(singleRes);
}
}
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.Stats")))
{
await using var dbCtx = new MoonPro_STATSContext(_configuration);
var singleRes = await dbCtx
.DbSetDbSize
.FromSqlRaw(stp_DbInfo)
.AsNoTracking()
.FirstOrDefaultAsync();
if (singleRes != null)
{
dbResult.Add(singleRes);
}
}
}
catch
{
}
return dbResult;
}
/// <inheritdoc />
public async Task<List<ConfigModel>> ConfigGetAllAsync()
{
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
return await dbCtx
.DbSetConfig
.AsNoTracking()
.OrderBy(x => x.Chiave)
.ToListAsync() ?? new();
}
/// <inheritdoc />
public async Task<List<MacchineModel>> MacchineGetAllAsync()
{
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
return await dbCtx
.DbSetMacchine
.ToListAsync() ?? new();
}
/// <inheritdoc />
public async Task<List<RemoteRebootLogModel>> RemRebootLogGetAllAsync()
{
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
return await dbCtx
.DbSetRemRebLog
.AsNoTracking()
.OrderByDescending(x => x.IdxReboot)
.ToListAsync() ?? new();
}
/// <inheritdoc />
public async Task<List<RemoteRebootLogModel>> RemRebootLogGetLastAsync()
{
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
return await dbCtx
.DbSetRemRebLog
.FromSqlRaw("EXEC stp_RRL_getLast")
.AsNoTracking()
.ToListAsync() ?? new();
}
/// <inheritdoc />
public async Task<List<RemoteRebootLogModel>> RemRebootLogGetLastNoMaccAsync()
{
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
return await dbCtx
.DbSetRemRebLog
.FromSqlRaw("EXEC stp_RRL_GetLastNoMachine")
.AsNoTracking()
.ToListAsync() ?? new();
}
#endregion
}
}
@@ -0,0 +1,20 @@
using Microsoft.Data.SqlClient;
using MP.Data.DbModels;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
namespace MP.Data.Repository.MpMon
{
public interface IMpMonRepository
{
Task<List<ConfigModel>> ConfigGetAllAsync();
Task<List<MacchineModel>> MacchineGetAllAsync();
Task<List<MacchineModel>> MacchineGetFiltAsync(string codGruppo);
Task<List<MappaStatoExplModel>> MseGetAllAsync(int maxAge = 2000);
}
}
+100
View File
@@ -0,0 +1,100 @@
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using MP.Data.DbModels;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
namespace MP.Data.Repository.MpMon
{
public class MpMonRepository : IMpMonRepository
{
#region Private Fields
private readonly IDbContextFactory<MoonProContext> _ctxFactory;
#endregion
#region Public Constructors
public MpMonRepository(IDbContextFactory<MoonProContext> ctxFactory)
{
_ctxFactory = ctxFactory;
}
#endregion
#region Public Methods
/// <inheritdoc />
public async Task<List<ConfigModel>> ConfigGetAllAsync()
{
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
return await dbCtx
.DbSetConfig
.AsNoTracking()
.OrderBy(x => x.Chiave)
.ToListAsync() ?? new();
}
/// <inheritdoc />
public async Task<List<MacchineModel>> MacchineGetAllAsync()
{
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
return await dbCtx
.DbSetMacchine
.AsNoTracking()
.OrderBy(x => x.IdxMacchina)
.ToListAsync() ?? new();
}
/// <inheritdoc />
public async Task<List<MacchineModel>> MacchineGetFiltAsync(string codGruppo)
{
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
List<MacchineModel> dbResult;
if (codGruppo == "*")
{
dbResult = await dbCtx
.DbSetMacchine
.AsNoTracking()
.OrderBy(x => x.IdxMacchina)
.ToListAsync();
}
else
{
dbResult = await dbCtx
.DbSetGrp2Macc
.Where(g => g.CodGruppo == codGruppo)
.Join(dbCtx.DbSetMacchine,
g => g.IdxMacchina,
m => m.IdxMacchina,
(g, m) => m
)
.AsNoTracking()
.OrderBy(x => x.IdxMacchina)
.ToListAsync();
}
dbResult = dbResult
.Where(x => !string.IsNullOrEmpty(x.locazione))
.OrderBy(x => x.locazione).ToList();
return dbResult;
}
/// <inheritdoc />
public async Task<List<MappaStatoExplModel>> MseGetAllAsync(int maxAge = 2000)
{
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
var maxAgeSec = new SqlParameter("@maxAgeSec", maxAge);
var dbResult = await dbCtx
.DbSetMSE
.FromSqlRaw("EXEC stp_MSE_getData @maxAgeSec", maxAgeSec)
.AsNoTracking()
.ToListAsync();
return dbResult;
}
#endregion
}
}
@@ -0,0 +1,15 @@
using MP.Data.DbModels;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MP.Data.Repository.MpVoc
{
public interface IMpVocRepository
{
Task<List<ConfigModel>> ConfigGetAllAsync();
Task<List<LingueModel>> LingueGetAllAsync();
Task<List<VocabolarioModel>> VocabolarioGetAllAsync();
}
}
@@ -0,0 +1,63 @@
using Microsoft.EntityFrameworkCore;
using MP.Data.DbModels;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
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)
{
_ctxFactory = ctxFactory;
}
#endregion
#region Public Methods
/// <inheritdoc />
public async Task<List<ConfigModel>> ConfigGetAllAsync()
{
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
return await dbCtx
.DbSetConfig
.AsNoTracking()
.OrderBy(x => x.Chiave)
.ToListAsync() ?? new();
}
/// <inheritdoc />
public async Task<List<LingueModel>> LingueGetAllAsync()
{
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
return await dbCtx
.DbSetLilngue
.AsNoTracking()
.OrderBy(x => x.Lingua)
.ToListAsync() ?? new();
}
/// <inheritdoc />
public async Task<List<VocabolarioModel>> VocabolarioGetAllAsync()
{
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
return await dbCtx
.DbSetVocabolario
.AsNoTracking()
.OrderBy(x => x.Lemma)
.ToListAsync() ?? new();
}
#endregion
}
}