diff --git a/MP.Data/Controllers/MpLandController.cs b/MP.Data/Controllers/MpLandController.cs index dab9748b..bed9195f 100644 --- a/MP.Data/Controllers/MpLandController.cs +++ b/MP.Data/Controllers/MpLandController.cs @@ -31,6 +31,89 @@ namespace MP.Data.Controllers #region Public Methods + /// + /// Restituisce info dimensione, tabelle e num righe DB gestiti + /// + /// + public List AllDbInfo() + { + List dbResult = new List(); + 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) -- heap or clustered index + 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(); + "; + + // leggo per DB principale + if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.All"))) + { + using (var dbCtx = new MoonProContext(_configuration)) + { + var singleRes = dbCtx + .DbSetDbSize + .FromSqlRaw(stp_DbInfo) + .AsEnumerable() + .FirstOrDefault(); + if (singleRes != null) + { + dbResult.Add(singleRes); + } + } + } + // leggo per FluxLog + if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.FluxLog"))) + { + using (var dbCtx = new MoonPro_FluxContext(_configuration)) + { + var singleRes = dbCtx + .DbSetDbSize + .FromSqlRaw(stp_DbInfo) + .AsEnumerable() + .FirstOrDefault(); + if (singleRes != null) + { + dbResult.Add(singleRes); + } + } + } + // leggo per Stats + if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.Stats"))) + { + using (var dbCtx = new MoonPro_STATSContext(_configuration)) + { + var singleRes = dbCtx + .DbSetDbSize + .FromSqlRaw(stp_DbInfo) + .AsEnumerable() + .FirstOrDefault(); + if (singleRes != null) + { + dbResult.Add(singleRes); + } + } + } + return dbResult; + } + /// /// Elenco da tabella Config /// diff --git a/MP.Data/Controllers/MpStatsController.cs b/MP.Data/Controllers/MpStatsController.cs index c0caef66..de6de2a3 100644 --- a/MP.Data/Controllers/MpStatsController.cs +++ b/MP.Data/Controllers/MpStatsController.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Data; using System.Drawing.Drawing2D; using System.Linq; +using ZXing; using static MP.Core.Objects.Enums; namespace MP.Data.Controllers diff --git a/MP.Data/DbModels/DbSizeModel.cs b/MP.Data/DbModels/DbSizeModel.cs new file mode 100644 index 00000000..1704ae77 --- /dev/null +++ b/MP.Data/DbModels/DbSizeModel.cs @@ -0,0 +1,14 @@ +using System.ComponentModel.DataAnnotations; + +namespace MP.Data.DbModels +{ + public class DbSizeModel + { + [Key] + public string DbName { get; set; } = ""; + public decimal DbSizeMb { get; set; } = 0; + public int NumTables { get; set; } = 0; + public string BigTable { get; set; } = ""; + public long BigTableRows { get; set; } = 0; + } +} diff --git a/MP.Data/MoonProContext.cs b/MP.Data/MoonProContext.cs index ac80eb39..71dd2d6f 100644 --- a/MP.Data/MoonProContext.cs +++ b/MP.Data/MoonProContext.cs @@ -38,6 +38,7 @@ namespace MP.Data #region Public Properties + public virtual DbSet DbSetDbSize { get; set; } public virtual DbSet DbSetAlarmLog { get; set; } public virtual DbSet DbSetAKV { get; set; } public virtual DbSet DbSetAnagEventi { get; set; } diff --git a/MP.Data/MoonPro_FluxContext.cs b/MP.Data/MoonPro_FluxContext.cs index 9c14f8bf..f68e84eb 100644 --- a/MP.Data/MoonPro_FluxContext.cs +++ b/MP.Data/MoonPro_FluxContext.cs @@ -48,6 +48,7 @@ namespace MP.Data #region Public Properties + public virtual DbSet DbSetDbSize { get; set; } public virtual DbSet DbSetArticoli { get; set; } public virtual DbSet DbSetMacchine { get; set; } public virtual DbSet DbSetFluxLog { get; set; } diff --git a/MP.Data/MoonPro_STATSContext.cs b/MP.Data/MoonPro_STATSContext.cs index 99a48f37..88fe6708 100644 --- a/MP.Data/MoonPro_STATSContext.cs +++ b/MP.Data/MoonPro_STATSContext.cs @@ -36,6 +36,7 @@ namespace MP.Data #region Public Properties + public virtual DbSet DbSetDbSize { get; set; } public virtual DbSet DbSetAnagFLTrans { get; set; } public virtual DbSet DbSetArticoli { get; set; } public virtual DbSet DbSetAzioniUL { get; set; } diff --git a/MP.Data/Services/LandDataService.cs b/MP.Data/Services/LandDataService.cs index 0fc7e0dc..bb86cc63 100644 --- a/MP.Data/Services/LandDataService.cs +++ b/MP.Data/Services/LandDataService.cs @@ -47,6 +47,41 @@ namespace MP.Data.Services #region Public Methods + /// + /// Restituisce info dimensione, tabelle e num righe DB + /// + /// + public List AllDbInfo() + { + // setup parametri costanti + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:DbInfo:ALL"; + RedisValue rawData = redisDb.StringGet(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbController.AllDbInfo(); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSet(currKey, rawData, UltraFastCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"AllDbInfo | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + /// /// Elenco INFO IOB da tab Macchine gestite + RemoteRebootLog /// diff --git a/MP.Land/Components/DbInfoMan.razor b/MP.Land/Components/DbInfoMan.razor new file mode 100644 index 00000000..2a859410 --- /dev/null +++ b/MP.Land/Components/DbInfoMan.razor @@ -0,0 +1,38 @@ +
+
+
Current DB Info
+
+
+ @if (ListRecord == null || ListRecord.Count == 0) + { +
Nessun record disponibile
+ } + else + { + + + + + + + + + + + + @foreach (var item in ListRecord) + { + + + + + + + + } + +
DB Size (Mb) Num Tab Biggest Tab Num Rows
@item.DbName@item.DbSizeMb.ToString("N2")@item.NumTables@item.BigTable@item.BigTableRows.ToString("N0")
+ } +
+
+ diff --git a/MP.Land/Components/DbInfoMan.razor.cs b/MP.Land/Components/DbInfoMan.razor.cs new file mode 100644 index 00000000..aae03d69 --- /dev/null +++ b/MP.Land/Components/DbInfoMan.razor.cs @@ -0,0 +1,127 @@ +using EgwCoreLib.Razor; +using Microsoft.AspNetCore.Components; +using MP.Data.DbModels; +using MP.Data.Services; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MP.Land.Components +{ + public partial class DbInfoMan + { + #region Protected Properties + + [Inject] + protected LandDataService LDService { get; set; } + + protected List ListRecord { get; set; } = new List(); + + #endregion Protected Properties + + #region Protected Methods + + protected override void OnParametersSet() + { + ReloadData(); + } + + protected void SortRequested(Sorter.SortCallBack e) + { + if (sortField == e.ParamName) + { + sortAsc = e.IsAscending; + } + sortField = e.ParamName; + RefreshDisplay(); + } + + #endregion Protected Methods + + #region Private Fields + + private bool sortAsc = true; + + private string sortField = ""; + + #endregion Private Fields + + #region Private Methods + + private void RefreshDisplay() + { + // se ho ordinamento riordino... + if (!string.IsNullOrEmpty(sortField)) + { + switch (sortField) + { + case "DbName": + if (sortAsc) + { + ListRecord = ListRecord.OrderBy(x => x.DbName).ToList(); + } + else + { + ListRecord = ListRecord.OrderByDescending(x => x.DbName).ToList(); + } + break; + + case "DbSizeMb": + if (sortAsc) + { + ListRecord = ListRecord.OrderBy(x => x.DbSizeMb).ToList(); + } + else + { + ListRecord = ListRecord.OrderByDescending(x => x.DbSizeMb).ToList(); + } + break; + + case "NumTable": + if (sortAsc) + { + ListRecord = ListRecord.OrderBy(x => x.NumTables).ToList(); + } + else + { + ListRecord = ListRecord.OrderByDescending(x => x.NumTables).ToList(); + } + break; + + case "BigTable": + if (sortAsc) + { + ListRecord = ListRecord.OrderBy(x => x.BigTable).ToList(); + } + else + { + ListRecord = ListRecord.OrderByDescending(x => x.BigTable).ToList(); + } + break; + + case "BigTableRows": + if (sortAsc) + { + ListRecord = ListRecord.OrderBy(x => x.BigTableRows).ToList(); + } + else + { + ListRecord = ListRecord.OrderByDescending(x => x.BigTableRows).ToList(); + } + break; + + default: + ListRecord = ListRecord.OrderBy(x => x.DbName).ToList(); + break; + } + } + } + + private void ReloadData() + { + ListRecord = LDService.AllDbInfo(); + } + + #endregion Private Methods + } +} \ No newline at end of file diff --git a/MP.Land/MP.Land.csproj b/MP.Land/MP.Land.csproj index 706d4fcd..7cfe02cc 100644 --- a/MP.Land/MP.Land.csproj +++ b/MP.Land/MP.Land.csproj @@ -3,7 +3,7 @@ net6.0 MP.Land - 6.16.2507.0315 + 6.16.2507.0410 Debug;Release;Debug_LiManDebug en True diff --git a/MP.Land/Pages/DbInfo.razor b/MP.Land/Pages/DbInfo.razor new file mode 100644 index 00000000..06e365c3 --- /dev/null +++ b/MP.Land/Pages/DbInfo.razor @@ -0,0 +1,3 @@ +@page "/DbInfo" + + diff --git a/MP.Land/Pages/DbInfo.razor.cs b/MP.Land/Pages/DbInfo.razor.cs new file mode 100644 index 00000000..633831f8 --- /dev/null +++ b/MP.Land/Pages/DbInfo.razor.cs @@ -0,0 +1,25 @@ +using Microsoft.AspNetCore.Components; + +namespace MP.Land.Pages +{ + public partial class DbInfo : ComponentBase + { + #region Protected Properties + + [Inject] + protected Data.LMessageService MServ { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods + + protected override void OnInitialized() + { + MServ.ShowSearch = true; + MServ.PageName = "DB Info"; + MServ.PageIcon = "fas fa-database"; + } + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/MP.Land/Resources/ChangeLog.html b/MP.Land/Resources/ChangeLog.html index 87d53175..48206a7d 100644 --- a/MP.Land/Resources/ChangeLog.html +++ b/MP.Land/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo Tablet MAPO - DotNet6 -

Versione: 6.16.2507.0315

+

Versione: 6.16.2507.0410


Note di rilascio:
    diff --git a/MP.Land/Resources/VersNum.txt b/MP.Land/Resources/VersNum.txt index 73d542ab..354b295b 100644 --- a/MP.Land/Resources/VersNum.txt +++ b/MP.Land/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2507.0315 +6.16.2507.0410 diff --git a/MP.Land/Resources/manifest.xml b/MP.Land/Resources/manifest.xml index 62008499..3b3319ac 100644 --- a/MP.Land/Resources/manifest.xml +++ b/MP.Land/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2507.0315 + 6.16.2507.0410 https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/MP.Land.zip https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/ChangeLog.html false diff --git a/MP.Land/Shared/NavMenu.razor b/MP.Land/Shared/NavMenu.razor index e06bfc1e..519ba0ba 100644 --- a/MP.Land/Shared/NavMenu.razor +++ b/MP.Land/Shared/NavMenu.razor @@ -99,6 +99,15 @@ @if (IsSuperAdmin) { +