Completamento migrazione repository MpSpecController: aggiunti MpMon, MpVoc, MpLand; migrati TranslateSrv, StatusData, LandDataService, TranslateSrv, MonDataFeeder, TabDataFeeder; 0 errori build
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user