From 758810be12df4dad12a08535a8ef0e0c60cf42d4 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 13 Sep 2021 15:41:21 +0200 Subject: [PATCH] Modifica comportamento UI x display update --- MP.FileData/Controllers/FileController.cs | 14 ++-- MP.Prog/Components/LoadingData.razor | 3 +- MP.Prog/Data/FileArchDataService.cs | 15 ++-- MP.Prog/Pages/Archive.razor | 23 +++--- MP.Prog/Pages/Archive.razor.cs | 98 ++++++----------------- 5 files changed, 54 insertions(+), 99 deletions(-) diff --git a/MP.FileData/Controllers/FileController.cs b/MP.FileData/Controllers/FileController.cs index 087316d5..0fa8db6d 100644 --- a/MP.FileData/Controllers/FileController.cs +++ b/MP.FileData/Controllers/FileController.cs @@ -44,10 +44,10 @@ namespace MP.FileData.Controllers /// pattern di ricerca (*.*) /// Regole di ricerca applicate /// - public bool CheckFileArchived(string idxMacchina, string path, int numDayPre, string searchPattern, SearchRules currRule) + public int CheckFileArchived(string idxMacchina, string path, int numDayPre, string searchPattern, SearchRules currRule) { Log.Info($"CheckFileArchived S00 | macchina: {idxMacchina} | path: {path} | pattern: {searchPattern} | # ExcludedFileExt: {currRule.ExcludedFileExt.Count()}"); - bool answ = false; + int checkDone = 0; DirectoryInfo dirInfo = new DirectoryInfo(path); FileInfo[] fileListRaw = dirInfo.GetFiles(searchPattern, SearchOption.AllDirectories); List fileList = new List(); @@ -86,6 +86,7 @@ namespace MP.FileData.Controllers } else { + checkDone++; // cerca nel DB... FileModel currRecord = archivedFile .Where(x => x.Active && x.Path == file.FullName) @@ -139,9 +140,10 @@ namespace MP.FileData.Controllers if (fileChecked != null && fileChecked.Count > 0) { FileSetChecked(fileChecked); + Log.Info($"CheckFileArchived S05 | refreshed {fileChecked.Count} files"); } - return answ; + return checkDone; } public void Dispose() @@ -280,7 +282,7 @@ namespace MP.FileData.Controllers FileContent = File.ReadAllBytes(o.FullName) }).ToList(); - // gestione Tags (da migliorare...) + // elenco Tags List currTags = localDbCtx.DbSetTags.ToList(); // calcolo MD5 e tags @@ -441,7 +443,7 @@ namespace MP.FileData.Controllers } /// - /// Effettua update di un record in archivio da lista (SOLO STATUS) + /// Effettua update di un record in archivio da lista (solo status, da /// /// /// @@ -468,7 +470,7 @@ namespace MP.FileData.Controllers } /// - /// Aggiorna un Ordine + /// Aggiorna un record FILE /// /// /// diff --git a/MP.Prog/Components/LoadingData.razor b/MP.Prog/Components/LoadingData.razor index d3228baf..b0624468 100644 --- a/MP.Prog/Components/LoadingData.razor +++ b/MP.Prog/Components/LoadingData.razor @@ -1,4 +1,5 @@ -
+

Working

+

loading data

diff --git a/MP.Prog/Data/FileArchDataService.cs b/MP.Prog/Data/FileArchDataService.cs index a4d32bcb..fde4e15f 100644 --- a/MP.Prog/Data/FileArchDataService.cs +++ b/MP.Prog/Data/FileArchDataService.cs @@ -269,9 +269,11 @@ namespace MP.Prog.Data /// /// Numero giorni x ricerca all'indietro da data corrente / 0 = nessun limite /// - public async Task updateAllArchive(int numDayPre) + public async Task updateAllArchive(int numDayPre) { - bool done = false; + int checkDone = 0; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); string ruleName = "Rule01.json"; try { @@ -286,7 +288,7 @@ namespace MP.Prog.Data { string rawData = File.ReadAllText(rulePath(ruleName)); currRule = JsonConvert.DeserializeObject(rawData); - Log.Info($"Conf rule acquisito da file {ruleName}:{Environment.NewLine}{rawData}"); + //Log.Info($"Conf rule acquisito da file {ruleName}:{Environment.NewLine}{rawData}"); } catch (Exception exc) { @@ -326,15 +328,18 @@ namespace MP.Prog.Data Log.Info($"Conf rule generato:{Environment.NewLine}{rawRule}"); } - done = dbController.CheckFileArchived(item.IdxMacchina, item.BasePath, numDayPre, "*.*", currRule); + checkDone += dbController.CheckFileArchived(item.IdxMacchina, item.BasePath, numDayPre, "*.*", currRule); } } catch (Exception exc) { Log.Error($"Eccezione in updateAllArchive{Environment.NewLine}{exc}{Environment.NewLine}{exc.InnerException}"); } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Info($"Effettuato update archivio file | last {numDayPre} days | {checkDone} checked | {ts.TotalMilliseconds} ms"); - return await Task.FromResult(done); + return await Task.FromResult(checkDone); } #endregion Public Methods diff --git a/MP.Prog/Pages/Archive.razor b/MP.Prog/Pages/Archive.razor index cbe96c1c..72067d12 100644 --- a/MP.Prog/Pages/Archive.razor +++ b/MP.Prog/Pages/Archive.razor @@ -10,17 +10,17 @@
-
+ @*
+
+ +
+
*@ +
- -
-
-
-
-
@@ -44,7 +44,7 @@
-
+
@@ -78,7 +78,6 @@ } @if (ListRecords == null) { -

Working

} else if (totalCount == 0) diff --git a/MP.Prog/Pages/Archive.razor.cs b/MP.Prog/Pages/Archive.razor.cs index c491d13d..005dc8c4 100644 --- a/MP.Prog/Pages/Archive.razor.cs +++ b/MP.Prog/Pages/Archive.razor.cs @@ -2,6 +2,7 @@ using Microsoft.JSInterop; using MP.FileData.DatabaseModels; using MP.Prog.Data; +using NLog; using System; using System.Collections.Generic; using System.Linq; @@ -14,6 +15,7 @@ namespace MP.Prog.Pages { #region Private Fields + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); private FileModel currRecord = null; private List ListRecords; private List MacList; @@ -28,28 +30,10 @@ namespace MP.Prog.Pages protected string defTag = ""; + protected int totalCount = 0; + #endregion Protected Fields -#if false - private int _currPage { get; set; } = 1; - - private int _numRecord { get; set; } = 10; - - private int currPage - { - get => _currPage; - set - { - if (_currPage != value) - { - _currPage = value; - var pUpd = Task.Run(async () => await ReloadData()); - pUpd.Wait(); - } - } - } -#endif - #region Private Properties private int currPage @@ -78,22 +62,6 @@ namespace MP.Prog.Pages } } -#if false - private int numRecord - { - get => _numRecord; - set - { - if (_numRecord != value) - { - _numRecord = value; - var pUpd = Task.Run(async () => await ReloadData()); - pUpd.Wait(); - } - } - } -#endif - private bool OnlyActive { get @@ -202,19 +170,6 @@ namespace MP.Prog.Pages } } - protected int totalCount - { - get - { - int answ = 0; - if (SearchRecords != null) - { - answ = SearchRecords.Count; - } - return answ; - } - } - #endregion Protected Properties #region Private Methods @@ -261,24 +216,22 @@ namespace MP.Prog.Pages pUpd.Wait(); } - protected void ForceCheck(int maxHour) + protected async Task ForceCheck(int numDays) { - var pUpd = Task.Run(async () => - { - currRecord = null; - SearchRecords = null; - ListRecords = null; - await DataService.updateAllArchive(maxHour); - AppMService.File_Filter = SelectData.Init(5, 10); - await ReloadAllData(); - isLoading = false; - }); - pUpd.Wait(); + currRecord = null; + SearchRecords = null; + ListRecords = null; + // importante altrimenti NON mostra update UI + await Task.Delay(1); + //AppMService.File_Filter = SelectData.Init(5, 10); + var numCheck = await DataService.updateAllArchive(numDays); + await ReloadAllData(); + await Task.Delay(1); + await RefreshDisplayLoading(); } protected override async Task OnInitializedAsync() { - DataService.ResetController(); SearchTag = defTag; AppMService.ShowSearch = false; AppMService.PageName = "Archivio File Programmi"; @@ -302,6 +255,12 @@ namespace MP.Prog.Pages isLoading = false; } + protected async Task RefreshDisplayLoading() + { + await Task.Delay(1); + isLoading = false; + } + protected async Task ReloadAllData() { isLoading = true; @@ -315,8 +274,10 @@ namespace MP.Prog.Pages protected async Task ReloadData() { isLoading = true; + // importante altrimenti NON mostra update UI await Task.Delay(1); SearchRecords = await DataService.FileGetFilt(AppMService.File_Filter.IdxMacchina, AppMService.File_Filter.CodArticolo, AppMService.File_Filter.OnlyActive, AppMService.File_Filter.OnlyMod, AppMService.SearchVal); + totalCount = SearchRecords.Count; // faccio paginazione SOLO NELLA DECINA attuale... (quindi non tutte le pagine ma solo subset) ListRecords = SearchRecords.Skip(numRecord * (currPage % 10 - 1)).Take(numRecord).ToList(); } @@ -349,19 +310,6 @@ namespace MP.Prog.Pages currRecord = selRecord; } - protected async Task TestLoading() - { - //isLoading = !isLoading; - await TestLoadingCloseTest(); - isLoading = false; - } - - protected async Task TestLoadingCloseTest() - { - isLoading = true; - await Task.Delay(1000); - } - protected async Task UpdateData() { currRecord = null;