From 07a6978e019aedfffe563bcdad632f4531ca3b0d Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 14 Sep 2021 07:53:08 +0200 Subject: [PATCH] Continuo pagina setup x ricalcolo completo archivio --- MP.FileData/Controllers/FileController.cs | 33 ++++++++ MP.FileData/DTO/ArchiveStatusDTO.cs | 22 ++++++ MP.Prog/Components/ArchiveStatus.razor | 63 ++++++++++++++++ MP.Prog/Components/ArchiveStatus.razor.cs | 92 +++++++++++++++++++++++ MP.Prog/Data/FileArchDataService.cs | 13 ++++ MP.Prog/Pages/Archive.razor.cs | 4 - MP.Prog/Pages/Setup.razor | 12 +-- MP.Prog/Pages/Setup.razor.cs | 25 ++---- 8 files changed, 231 insertions(+), 33 deletions(-) create mode 100644 MP.FileData/DTO/ArchiveStatusDTO.cs create mode 100644 MP.Prog/Components/ArchiveStatus.razor create mode 100644 MP.Prog/Components/ArchiveStatus.razor.cs diff --git a/MP.FileData/Controllers/FileController.cs b/MP.FileData/Controllers/FileController.cs index 16835ae9..10accd55 100644 --- a/MP.FileData/Controllers/FileController.cs +++ b/MP.FileData/Controllers/FileController.cs @@ -9,6 +9,7 @@ using System.Text; using System.Threading.Tasks; using MP.FileData.DatabaseModels; using Newtonsoft.Json; +using MP.FileData.DTO; namespace MP.FileData.Controllers { @@ -535,6 +536,38 @@ namespace MP.FileData.Controllers return done; } + public List GetArchiveStatus() + { + List ArchiveList = new List(); + using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) + { + ArchiveList = localDbCtx + .DbSetMacchine + .Select(x => new ArchiveStatusDTO() + { + IdxMacchina = x.IdxMacchina, + Nome = x.Nome, + Descrizione = x.Descrizione, + BasePath = x.BasePath + }) + .ToList(); + // ora ciclo a cercare i file... + foreach (var item in ArchiveList) + { + item.TotFile = localDbCtx + .DbSetProgFile + .Where(x => x.IdxMacchina == item.IdxMacchina && x.Active) + .Count(); + + item.NumChanged = localDbCtx + .DbSetProgFile + .Where(x => x.IdxMacchina == item.IdxMacchina && x.Active && x.DiskStatus == FileState.Changed) + .Count(); + } + } + return ArchiveList; + } + /// /// Elenco tabella Macchine /// diff --git a/MP.FileData/DTO/ArchiveStatusDTO.cs b/MP.FileData/DTO/ArchiveStatusDTO.cs new file mode 100644 index 00000000..bf70e51e --- /dev/null +++ b/MP.FileData/DTO/ArchiveStatusDTO.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MP.FileData.DTO +{ + // + // This is here so CodeMaid doesn't reorganize this document + // + public class ArchiveStatusDTO + { + public string IdxMacchina { get; set; } = ""; + public string Nome { get; set; } = ""; + public string Descrizione { get; set; } = ""; + public string BasePath { get; set; } = ""; + + public int TotFile { get; set; } = 0; + public int NumChanged { get; set; } = 0; + } +} diff --git a/MP.Prog/Components/ArchiveStatus.razor b/MP.Prog/Components/ArchiveStatus.razor new file mode 100644 index 00000000..3c7fbc27 --- /dev/null +++ b/MP.Prog/Components/ArchiveStatus.razor @@ -0,0 +1,63 @@ +
+
+ +
+
+ @if (showProgress) + { +
+
+
+ } +
+
+ @if (ListRecords == null) + { + + } + else if (totalCount == 0) + { +
Nessun record trovato
+ } + else + { + + + + + + + + + + + + @foreach (var record in ListRecords) + { + + + + + + + } + +
MacchinaPathModificatiTot File
+ @record.Nome + +
@record.BasePath
+
+ @record.NumChanged + + + @record.TotFile + +
+
+ @lastMessage +
+ } +
+
\ No newline at end of file diff --git a/MP.Prog/Components/ArchiveStatus.razor.cs b/MP.Prog/Components/ArchiveStatus.razor.cs new file mode 100644 index 00000000..2d0d455d --- /dev/null +++ b/MP.Prog/Components/ArchiveStatus.razor.cs @@ -0,0 +1,92 @@ +using Microsoft.AspNetCore.Components; +using MP.FileData.DTO; +using MP.Prog.Data; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.Prog.Components +{ + public partial class ArchiveStatus + { + #region Private Fields + + private List ListRecords; + + private int numChecks = 0; + + #endregion Private Fields + + #region Private Properties + + private string lastMessage { get; set; } = ""; + + private int totalCount + { + get + { + int answ = 0; + if (ListRecords != null) + answ = ListRecords.Count(); + return answ; + } + } + + #endregion Private Properties + + #region Protected Properties + + [Inject] + protected FileArchDataService DataService { get; set; } + + protected int percLoading { get; set; } = 0; + protected bool showProgress { get; set; } = true; + + #endregion Protected Properties + + #region Protected Methods + + protected async Task ArchiveCheck(int maxHour) + { + numChecks = await DataService.updateAllArchive(maxHour); + lastMessage = $"Effettuata verifica e rilettura di {numChecks} files!"; + await Task.Delay(1); + await ReloadData(); + } + + protected async Task ClearMessage() + { + await Task.Delay(100); + lastMessage = ""; + } + + protected async Task ForceCheck(int maxHour) + { + lastMessage = "Inizio Analisi Archivio..."; + ListRecords = null; + //await Task.Delay(1); + await ArchiveCheck(maxHour); + //await Task.Delay(1); + await ReloadData(); + await ClearMessage(); + } + + protected override async Task OnInitializedAsync() + { + ListRecords = null; + await ReloadData(); + } + + protected async Task ReloadData() + { + await Task.Delay(10); + numChecks = 0; + ListRecords = await DataService.GetArchiveStatus(); + await Task.Delay(100); + lastMessage = ""; + } + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/MP.Prog/Data/FileArchDataService.cs b/MP.Prog/Data/FileArchDataService.cs index 6e645401..2d624808 100644 --- a/MP.Prog/Data/FileArchDataService.cs +++ b/MP.Prog/Data/FileArchDataService.cs @@ -13,6 +13,7 @@ using System.Text; using System.Threading.Tasks; using System.Diagnostics; using MP.FileData.Controllers; +using MP.FileData.DTO; namespace MP.Prog.Data { @@ -246,6 +247,18 @@ namespace MP.Prog.Data return await Task.FromResult(dbResult); } + public async Task> GetArchiveStatus() + { + List dbResult = new List(); + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + dbResult = dbController.GetArchiveStatus(); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Info($"Effettuata lettura da DB + caching per GetArchiveStatus: {ts.TotalMilliseconds} ms"); + return await Task.FromResult(dbResult); + } + public Task> MacchineGetAll() { return Task.FromResult(dbController.MacchineGetAll().ToList()); diff --git a/MP.Prog/Pages/Archive.razor.cs b/MP.Prog/Pages/Archive.razor.cs index ca727309..904f407d 100644 --- a/MP.Prog/Pages/Archive.razor.cs +++ b/MP.Prog/Pages/Archive.razor.cs @@ -222,12 +222,8 @@ namespace MP.Prog.Pages isLoading = true; currRecord = null; ListRecords = null; - //var pUpd = Task.Run(async () => - //{ await ReloadData(); isLoading = false; - //}); - //pUpd.Wait(); } protected void Edit(FileModel selRecord) diff --git a/MP.Prog/Pages/Setup.razor b/MP.Prog/Pages/Setup.razor index ecabc739..f13a03f9 100644 --- a/MP.Prog/Pages/Setup.razor +++ b/MP.Prog/Pages/Setup.razor @@ -11,17 +11,7 @@

Setup

- @if(isLoading) - { - - } - else - - { - - } +
@**@ \ No newline at end of file diff --git a/MP.Prog/Pages/Setup.razor.cs b/MP.Prog/Pages/Setup.razor.cs index 6455e67e..0df88e8d 100644 --- a/MP.Prog/Pages/Setup.razor.cs +++ b/MP.Prog/Pages/Setup.razor.cs @@ -1,30 +1,19 @@ using Microsoft.AspNetCore.Components; using MP.Prog.Data; +using System; +using System.Threading.Tasks; namespace MP.Prog.Pages { - public partial class Setup + public partial class Setup : ComponentBase { - #region Private Properties - - private bool isLoading { get; set; } = false; - - #endregion Private Properties - - #region Protected Properties - - [Inject] - protected FileArchDataService DataService { get; set; } - - #endregion Protected Properties - #region Protected Methods - protected async void ForceCheck(int maxHour) + protected override void OnInitialized() { - isLoading = true; - await DataService.updateAllArchive(maxHour); - isLoading = false; + AppMService.ShowSearch = false; + AppMService.PageName = "Setup"; + AppMService.PageIcon = "fas fa-wrench pr-2"; } #endregion Protected Methods