From a8416ca3bcce97c959f0dd8e92f3ed7203a49a6d Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 13 Sep 2021 15:40:49 +0200 Subject: [PATCH 1/7] Spostato ricalcolo totale in setup --- MP.Prog/Pages/Setup.razor | 24 ++++++++++++++++++------ MP.Prog/Pages/Setup.razor.cs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 MP.Prog/Pages/Setup.razor.cs diff --git a/MP.Prog/Pages/Setup.razor b/MP.Prog/Pages/Setup.razor index cd9bc354..ecabc739 100644 --- a/MP.Prog/Pages/Setup.razor +++ b/MP.Prog/Pages/Setup.razor @@ -6,10 +6,22 @@ @inject MessageService AppMService -

Setup

+
+
+

Setup

+
+
+ @if(isLoading) + { + + } + else - - -@code { - -} \ No newline at end of file + { + + } +
+ @**@ +
\ No newline at end of file diff --git a/MP.Prog/Pages/Setup.razor.cs b/MP.Prog/Pages/Setup.razor.cs new file mode 100644 index 00000000..6455e67e --- /dev/null +++ b/MP.Prog/Pages/Setup.razor.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Components; +using MP.Prog.Data; + +namespace MP.Prog.Pages +{ + public partial class Setup + { + #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) + { + isLoading = true; + await DataService.updateAllArchive(maxHour); + isLoading = false; + } + + #endregion Protected Methods + } +} \ No newline at end of file From 758810be12df4dad12a08535a8ef0e0c60cf42d4 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 13 Sep 2021 15:41:21 +0200 Subject: [PATCH 2/7] 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; From 48ee4dcdaefc332b2c5b3a1ccee3ac08cf77edab Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 13 Sep 2021 18:05:31 +0200 Subject: [PATCH 3/7] update datamodel file con indici --- MP.FileData/DatabaseModels/FileModel.cs | 4 +++- ...7_InitDb.Designer.cs => 20210913153816_InitDb.Designer.cs} | 4 ++-- .../{20210908125127_InitDb.cs => 20210913153816_InitDb.cs} | 4 ++-- MP.FileData/Migrations/MoonPro_ProgContextModelSnapshot.cs | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) rename MP.FileData/Migrations/{20210908125127_InitDb.Designer.cs => 20210913153816_InitDb.Designer.cs} (98%) rename MP.FileData/Migrations/{20210908125127_InitDb.cs => 20210913153816_InitDb.cs} (97%) diff --git a/MP.FileData/DatabaseModels/FileModel.cs b/MP.FileData/DatabaseModels/FileModel.cs index 021998d8..882afca1 100644 --- a/MP.FileData/DatabaseModels/FileModel.cs +++ b/MP.FileData/DatabaseModels/FileModel.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.EntityFrameworkCore; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -15,6 +16,7 @@ namespace MP.FileData.DatabaseModels /// Tabella archivio dei File Programma /// [Table("Files")] + [Index(nameof(IdxMacchina), nameof(Active), nameof(DiskStatus))] public partial class FileModel { #region Public Properties diff --git a/MP.FileData/Migrations/20210908125127_InitDb.Designer.cs b/MP.FileData/Migrations/20210913153816_InitDb.Designer.cs similarity index 98% rename from MP.FileData/Migrations/20210908125127_InitDb.Designer.cs rename to MP.FileData/Migrations/20210913153816_InitDb.Designer.cs index 02257387..a4c555e8 100644 --- a/MP.FileData/Migrations/20210908125127_InitDb.Designer.cs +++ b/MP.FileData/Migrations/20210913153816_InitDb.Designer.cs @@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace MP.FileData.Migrations { [DbContext(typeof(MoonPro_ProgContext))] - [Migration("20210908125127_InitDb")] + [Migration("20210913153816_InitDb")] partial class InitDb { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -82,7 +82,7 @@ namespace MP.FileData.Migrations b.HasKey("FileId"); - b.HasIndex("IdxMacchina"); + b.HasIndex("IdxMacchina", "Active", "DiskStatus"); b.ToTable("Files"); }); diff --git a/MP.FileData/Migrations/20210908125127_InitDb.cs b/MP.FileData/Migrations/20210913153816_InitDb.cs similarity index 97% rename from MP.FileData/Migrations/20210908125127_InitDb.cs rename to MP.FileData/Migrations/20210913153816_InitDb.cs index 9367447b..15a642fa 100644 --- a/MP.FileData/Migrations/20210908125127_InitDb.cs +++ b/MP.FileData/Migrations/20210913153816_InitDb.cs @@ -101,9 +101,9 @@ namespace MP.FileData.Migrations column: "TagsTagId"); migrationBuilder.CreateIndex( - name: "IX_Files_IdxMacchina", + name: "IX_Files_IdxMacchina_Active_DiskStatus", table: "Files", - column: "IdxMacchina"); + columns: new[] { "IdxMacchina", "Active", "DiskStatus" }); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/MP.FileData/Migrations/MoonPro_ProgContextModelSnapshot.cs b/MP.FileData/Migrations/MoonPro_ProgContextModelSnapshot.cs index 27ca048c..9e9ff30e 100644 --- a/MP.FileData/Migrations/MoonPro_ProgContextModelSnapshot.cs +++ b/MP.FileData/Migrations/MoonPro_ProgContextModelSnapshot.cs @@ -80,7 +80,7 @@ namespace MP.FileData.Migrations b.HasKey("FileId"); - b.HasIndex("IdxMacchina"); + b.HasIndex("IdxMacchina", "Active", "DiskStatus"); b.ToTable("Files"); }); From 6940a68c0cc33cdaaa44efe5933524ef1a4ca075 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 13 Sep 2021 18:05:43 +0200 Subject: [PATCH 4/7] udpate paginazione dati solo decina apgine correnti --- MP.FileData/Controllers/FileController.cs | 94 +++++++++++------- MP.Prog/Data/FileArchDataService.cs | 114 ++++++++++++---------- MP.Prog/Data/SelectData.cs | 4 +- MP.Prog/Pages/Archive.razor | 71 +++++++------- MP.Prog/Pages/Archive.razor.cs | 33 ++++++- 5 files changed, 184 insertions(+), 132 deletions(-) diff --git a/MP.FileData/Controllers/FileController.cs b/MP.FileData/Controllers/FileController.cs index 0fa8db6d..16835ae9 100644 --- a/MP.FileData/Controllers/FileController.cs +++ b/MP.FileData/Controllers/FileController.cs @@ -35,6 +35,11 @@ namespace MP.FileData.Controllers #region Public Methods + public static string rulePath(string ruleName) + { + return string.Format($"Conf/{ruleName}"); + } + /// /// Effettua la comparazione tra i file in archivio ed i file attuali e segna info LastCheck e Changed (se cambiati) /// @@ -152,6 +157,19 @@ namespace MP.FileData.Controllers dbCtx.Dispose(); } + public int FileCountFilt(string IdxMacchina, bool OnlyActive, bool OnlyMod, string SearchVal = "") + { + int answ = 0; + using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) + { + answ = localDbCtx + .DbSetProgFile + .Where(x => (x.IdxMacchina == IdxMacchina || IdxMacchina == "0") && (x.Active == OnlyActive || !OnlyActive) && (!OnlyMod || x.DiskStatus != FileState.Ok) && (x.Name.Contains(SearchVal) || string.IsNullOrEmpty(SearchVal))) + .Count(); + } + return answ; + } + /// /// ELiminazione file da tabella /// @@ -232,7 +250,7 @@ namespace MP.FileData.Controllers return dbResult; } - public List FileGetFilt(string IdxMacchina, string CodArticolo, bool OnlyActive, bool OnlyMod, string SearchVal = "") + public List FileGetFilt(string IdxMacchina, bool OnlyActive, bool OnlyMod, int numStart, int numRecords, string SearchVal = "") { List dbResult = new List(); using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) @@ -243,6 +261,8 @@ namespace MP.FileData.Controllers .Include(t => t.Tags) .Where(x => (x.IdxMacchina == IdxMacchina || IdxMacchina == "0") && (x.Active == OnlyActive || !OnlyActive) && (!OnlyMod || x.DiskStatus != FileState.Ok) && (x.Name.Contains(SearchVal) || string.IsNullOrEmpty(SearchVal))) .OrderByDescending(x => x.LastMod) + .Skip(numStart) + .Take(numRecords) .ToList(); } return dbResult; @@ -348,6 +368,8 @@ namespace MP.FileData.Controllers public bool FileModApprove(FileModel currFile) { bool done = false; + // recupero file regole json da macchina.. + List listUpdate = new List(); using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) { @@ -355,40 +377,39 @@ namespace MP.FileData.Controllers var newFileInfo = new FileInfo(currFile.Path); listUpdate.Add(newFileInfo); - // fixme todo !!! fix da conf file - Dictionary confReplace = new Dictionary(); - confReplace.Add("(", " "); - confReplace.Add(")", " "); - - Dictionary fileExtReplace = new Dictionary(); - fileExtReplace.Add(".P-2", ""); - - // hard coded + salvataggio conf x creare json - SearchRules currRule = new SearchRules() + var currMacchina = localDbCtx + .DbSetMacchine + .Where(x => x.IdxMacchina == currFile.IdxMacchina) + .SingleOrDefault(); + if (currMacchina != null) { - Name = "Commento Filename", - Mode = SearchMode.StringOnFile, - MaxChar2Search = 100, - ReplaceCR = true, - RegExPattern = "\\b{{fileName}}" + @".{0,2}\([\w\d\s.]+\)", - RegExRepFileName = true, - ExcludedTags = new List() { "M4", "M5", "M4+A", "M4+B", "M5+A", "M5+B" }, - FileNameExtReplace = fileExtReplace, - OutReplace = confReplace, - OutExcludeFileName = true - }; + // gestione confRule... + SearchRules currRule = new SearchRules(); + try + { + string rawData = File.ReadAllText(rulePath(currMacchina.RuleName)); + currRule = JsonConvert.DeserializeObject(rawData); + } + catch (Exception exc) + { + Log.Error($"Eccezione in deserializzazione conf rule{Environment.NewLine}{exc}"); + } + // se ho letto conf + if (currRule.Name != "ND") + { + // inserisco come REVISIONE + FileInsert(currFile.IdxMacchina, listUpdate, currFile.Rev + 1, currRule); - // inserisco come REVISIONE - FileInsert(currFile.IdxMacchina, listUpdate, currFile.Rev + 1, currRule); + // archivio vecchio file + currFile.Active = false; + currFile.DiskStatus = FileState.Ok; + localDbCtx.Entry(currFile).State = EntityState.Modified; + // salvo DB + localDbCtx.SaveChanges(); - // archivio vecchio file - currFile.Active = false; - currFile.DiskStatus = FileState.Ok; - localDbCtx.Entry(currFile).State = EntityState.Modified; - // salvo DB - localDbCtx.SaveChanges(); - - done = true; + done = true; + } + } } return done; } @@ -443,7 +464,7 @@ namespace MP.FileData.Controllers } /// - /// Effettua update di un record in archivio da lista (solo status, da + /// Effettua update di un record in archivio da lista (solo status, da approvare) /// /// /// @@ -470,7 +491,7 @@ namespace MP.FileData.Controllers } /// - /// Aggiorna un record FILE + /// Aggiorna un record FILE rileggendo e ricalcolando... /// /// /// @@ -481,11 +502,16 @@ namespace MP.FileData.Controllers { try { + // elenco Tags + List currTags = localDbCtx.DbSetTags.ToList(); + + // file FileModel currData = null; currData = dbCtx .DbSetProgFile .Where(x => x.FileId == updItem.FileId) .FirstOrDefault(); + if (currData != null) { updItem.DiskStatus = FileState.Changed; diff --git a/MP.Prog/Data/FileArchDataService.cs b/MP.Prog/Data/FileArchDataService.cs index fde4e15f..c7248b9a 100644 --- a/MP.Prog/Data/FileArchDataService.cs +++ b/MP.Prog/Data/FileArchDataService.cs @@ -12,6 +12,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; +using MP.FileData.Controllers; namespace MP.Prog.Data { @@ -104,15 +105,6 @@ namespace MP.Prog.Data #endregion Private Properties - #region Protected Methods - - protected string rulePath(string ruleName) - { - return string.Format($"Conf/{ruleName}"); - } - - #endregion Protected Methods - #region Internal Methods internal Task FileApprove(FileData.DatabaseModels.FileModel currItem) @@ -224,17 +216,29 @@ namespace MP.Prog.Data dbController.Dispose(); } + public async Task FileCountFilt(SelectData CurrFilter) + { + int numCount = 0; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + numCount = dbController.FileCountFilt(CurrFilter.IdxMacchina, CurrFilter.OnlyActive, CurrFilter.OnlyMod, CurrFilter.SearchVal); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Info($"Effettuata lettura da DB + caching per FileCountFilt: {ts.TotalMilliseconds} ms"); + return await Task.FromResult(numCount); + } + public Task FileGetByKey(int FileId) { return Task.FromResult(dbController.FileGetByKey(FileId)); } - public async Task> FileGetFilt(string IdxMacchina, string CodArticolo, bool OnlyActive, bool OnlyMod, string SearchVal) + public async Task> FileGetFilt(SelectData CurrFilter) { List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = dbController.FileGetFilt(IdxMacchina, CodArticolo, OnlyActive, OnlyMod, SearchVal).ToList(); + dbResult = dbController.FileGetFilt(CurrFilter.IdxMacchina, CurrFilter.OnlyActive, CurrFilter.OnlyMod, CurrFilter.FirstRecord, CurrFilter.PageSize * 10, CurrFilter.SearchVal).ToList(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Info($"Effettuata lettura da DB + caching per FileGetFilt: {ts.TotalMilliseconds} ms"); @@ -281,54 +285,56 @@ namespace MP.Prog.Data foreach (var item in listaMacchine.Where(x => !string.IsNullOrEmpty(x.BasePath)).ToList()) { if (!string.IsNullOrEmpty(item.RuleName)) - { } - // gestione confRule... - SearchRules currRule = new SearchRules(); - try { - string rawData = File.ReadAllText(rulePath(ruleName)); - currRule = JsonConvert.DeserializeObject(rawData); - //Log.Info($"Conf rule acquisito da file {ruleName}:{Environment.NewLine}{rawData}"); - } - catch (Exception exc) - { - Log.Error($"Eccezione in deserializzazione conf rule{Environment.NewLine}{exc}"); - } - - // se NON deserializzato inizializzo hard-coded - if (currRule.Name == "ND") - { - // fare: lettura conf rule x recupero tag x singola macchina - //$"\\b{fileName}" + @".{0,2}\([\w\d\s.]+\)"; - - Dictionary confReplace = new Dictionary(); - confReplace.Add("(", " "); - confReplace.Add(")", " "); - - Dictionary fileExtReplace = new Dictionary(); - fileExtReplace.Add(".P-2", ""); - // hard coded + salvataggio conf x creare json - currRule = new SearchRules() + ruleName = item.RuleName; + // gestione confRule... + SearchRules currRule = new SearchRules(); + try { - Name = "Commento Filename", - Mode = SearchMode.StringOnFile, - MaxChar2Search = 100, - ReplaceCR = true, - RegExPattern = "\\b{{fileName}}" + @".{0,2}\([\w\d\s./]+\)", - RegExRepFileName = true, - FileNameExtReplace = fileExtReplace, - ExcludedTags = new List() { "M4", "M5", "M4+A", "M4+B", "M5+A", "M5+B" }, - OutReplace = confReplace, - OutExcludeFileName = true - }; + string rawData = File.ReadAllText(FileController.rulePath(ruleName)); + currRule = JsonConvert.DeserializeObject(rawData); + //Log.Info($"Conf rule acquisito da file {ruleName}:{Environment.NewLine}{rawData}"); + } + catch (Exception exc) + { + Log.Error($"Eccezione in deserializzazione conf rule{Environment.NewLine}{exc}"); + } - // serializzo + // se NON deserializzato inizializzo hard-coded + if (currRule.Name == "ND") + { + // fare: lettura conf rule x recupero tag x singola macchina + //$"\\b{fileName}" + @".{0,2}\([\w\d\s.]+\)"; - string rawRule = JsonConvert.SerializeObject(currRule, Formatting.Indented); - Log.Info($"Conf rule generato:{Environment.NewLine}{rawRule}"); + Dictionary confReplace = new Dictionary(); + confReplace.Add("(", " "); + confReplace.Add(")", " "); + + Dictionary fileExtReplace = new Dictionary(); + fileExtReplace.Add(".P-2", ""); + // hard coded + salvataggio conf x creare json + currRule = new SearchRules() + { + Name = "Commento Filename", + Mode = SearchMode.StringOnFile, + MaxChar2Search = 100, + ReplaceCR = true, + RegExPattern = "\\b{{fileName}}" + @".{0,2}\([\w\d\s./]+\)", + RegExRepFileName = true, + FileNameExtReplace = fileExtReplace, + ExcludedTags = new List() { "M4", "M5", "M4+A", "M4+B", "M5+A", "M5+B" }, + OutReplace = confReplace, + OutExcludeFileName = true + }; + + // serializzo + + string rawRule = JsonConvert.SerializeObject(currRule, Formatting.Indented); + Log.Info($"Conf rule generato:{Environment.NewLine}{rawRule}"); + } + + checkDone += dbController.CheckFileArchived(item.IdxMacchina, item.BasePath, numDayPre, "*.*", currRule); } - - checkDone += dbController.CheckFileArchived(item.IdxMacchina, item.BasePath, numDayPre, "*.*", currRule); } } catch (Exception exc) diff --git a/MP.Prog/Data/SelectData.cs b/MP.Prog/Data/SelectData.cs index c8e92923..01db4a56 100644 --- a/MP.Prog/Data/SelectData.cs +++ b/MP.Prog/Data/SelectData.cs @@ -9,7 +9,6 @@ namespace MP.Prog.Data { #region Public Properties - public string CodArticolo { get; set; } = ""; public DateTime DateEnd { get; set; } = DateTime.Now.AddMinutes(1); public DateTime DateStart { get; set; } = DateTime.Now.AddDays(-7); @@ -32,6 +31,7 @@ namespace MP.Prog.Data public int PageNum { get; set; } = 1; public int PageSize { get; set; } = 10; + public string SearchVal { get; set; } = ""; #endregion Public Properties @@ -69,7 +69,7 @@ namespace MP.Prog.Data return false; if (OnlyMod != item.OnlyMod) return false; - if (CodArticolo != item.CodArticolo) + if (SearchVal != item.SearchVal) return false; if (IdxMacchina != item.IdxMacchina) return false; diff --git a/MP.Prog/Pages/Archive.razor b/MP.Prog/Pages/Archive.razor index 72067d12..16edd386 100644 --- a/MP.Prog/Pages/Archive.razor +++ b/MP.Prog/Pages/Archive.razor @@ -5,46 +5,28 @@
-
- Elenco Programmi -
-
-
- @*
-
- -
-
*@ -
+
+
+
+

Elenco Programmi

+
+
-
-
-
-
-
-
- - -
+
+
+
+
+
+
+
-
-
-
-
-
- - -
-
-
-
+
@@ -62,9 +44,24 @@
-
-
- +
+
+
+
+
+ + +
+
+
+
+
+
+
+
+ + +
diff --git a/MP.Prog/Pages/Archive.razor.cs b/MP.Prog/Pages/Archive.razor.cs index 005dc8c4..74a73790 100644 --- a/MP.Prog/Pages/Archive.razor.cs +++ b/MP.Prog/Pages/Archive.razor.cs @@ -78,7 +78,10 @@ namespace MP.Prog.Pages if (!AppMService.File_Filter.OnlyActive.Equals(value)) { AppMService.File_Filter.OnlyActive = value; - var pUpd = Task.Run(async () => await ReloadData()); + var pUpd = Task.Run(async () => + { + await AsyncReload(); + }); pUpd.Wait(); } } @@ -100,7 +103,10 @@ namespace MP.Prog.Pages if (!AppMService.File_Filter.OnlyMod.Equals(value)) { AppMService.File_Filter.OnlyMod = value; - var pUpd = Task.Run(async () => await ReloadData()); + var pUpd = Task.Run(async () => + { + await AsyncReload(); + }); pUpd.Wait(); } } @@ -122,7 +128,10 @@ namespace MP.Prog.Pages if (!AppMService.File_Filter.IdxMacchina.Equals(value)) { AppMService.File_Filter.IdxMacchina = value; - var pUpd = Task.Run(async () => await ReloadData()); + var pUpd = Task.Run(async () => + { + await AsyncReload(); + }); pUpd.Wait(); } } @@ -209,6 +218,20 @@ namespace MP.Prog.Pages #region Protected Methods + protected async Task AsyncReload() + { + isLoading = true; + currRecord = null; + SearchRecords = null; + ListRecords = null; + //var pUpd = Task.Run(async () => + //{ + await ReloadData(); + isLoading = false; + //}); + //pUpd.Wait(); + } + protected void Edit(FileModel selRecord) { // rileggo dal DB il record corrente... @@ -276,8 +299,8 @@ namespace MP.Prog.Pages 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; + totalCount = await DataService.FileCountFilt(AppMService.File_Filter); + SearchRecords = await DataService.FileGetFilt(AppMService.File_Filter); // faccio paginazione SOLO NELLA DECINA attuale... (quindi non tutte le pagine ma solo subset) ListRecords = SearchRecords.Skip(numRecord * (currPage % 10 - 1)).Take(numRecord).ToList(); } From a5e0100cab17853cb234f648b47c1eaa002d6fd1 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 13 Sep 2021 18:15:59 +0200 Subject: [PATCH 5/7] Fix ricerca con paginazione da DB --- MP.Prog/Data/FileArchDataService.cs | 3 ++- MP.Prog/Data/SelectData.cs | 12 ++++++++++++ MP.Prog/Pages/Archive.razor.cs | 12 +++++------- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/MP.Prog/Data/FileArchDataService.cs b/MP.Prog/Data/FileArchDataService.cs index c7248b9a..6e645401 100644 --- a/MP.Prog/Data/FileArchDataService.cs +++ b/MP.Prog/Data/FileArchDataService.cs @@ -238,7 +238,8 @@ namespace MP.Prog.Data List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = dbController.FileGetFilt(CurrFilter.IdxMacchina, CurrFilter.OnlyActive, CurrFilter.OnlyMod, CurrFilter.FirstRecord, CurrFilter.PageSize * 10, CurrFilter.SearchVal).ToList(); + dbResult = dbController.FileGetFilt(CurrFilter.IdxMacchina, CurrFilter.OnlyActive, CurrFilter.OnlyMod, CurrFilter.NumSkip, CurrFilter.PageSize, CurrFilter.SearchVal).ToList(); + //dbResult = dbController.FileGetFilt(CurrFilter.IdxMacchina, CurrFilter.OnlyActive, CurrFilter.OnlyMod, CurrFilter.FirstRecord, CurrFilter.PageSize * 10, CurrFilter.SearchVal).ToList(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Info($"Effettuata lettura da DB + caching per FileGetFilt: {ts.TotalMilliseconds} ms"); diff --git a/MP.Prog/Data/SelectData.cs b/MP.Prog/Data/SelectData.cs index 01db4a56..f1b36f0e 100644 --- a/MP.Prog/Data/SelectData.cs +++ b/MP.Prog/Data/SelectData.cs @@ -26,6 +26,18 @@ namespace MP.Prog.Data } public string IdxMacchina { get; set; } = ""; + + /// + /// Recorda da saltare x arrivare alla pagina corrente + /// + public int NumSkip + { + get + { + return PageSize * (PageNum - 1); + } + } + public bool OnlyActive { get; set; } = true; public bool OnlyMod { get; set; } = false; diff --git a/MP.Prog/Pages/Archive.razor.cs b/MP.Prog/Pages/Archive.razor.cs index 74a73790..ca727309 100644 --- a/MP.Prog/Pages/Archive.razor.cs +++ b/MP.Prog/Pages/Archive.razor.cs @@ -19,7 +19,6 @@ namespace MP.Prog.Pages private FileModel currRecord = null; private List ListRecords; private List MacList; - private List SearchRecords; private List TagList; #endregion Private Fields @@ -222,7 +221,6 @@ namespace MP.Prog.Pages { isLoading = true; currRecord = null; - SearchRecords = null; ListRecords = null; //var pUpd = Task.Run(async () => //{ @@ -242,7 +240,6 @@ namespace MP.Prog.Pages protected async Task ForceCheck(int numDays) { currRecord = null; - SearchRecords = null; ListRecords = null; // importante altrimenti NON mostra update UI await Task.Delay(1); @@ -300,9 +297,11 @@ namespace MP.Prog.Pages // importante altrimenti NON mostra update UI await Task.Delay(1); totalCount = await DataService.FileCountFilt(AppMService.File_Filter); - SearchRecords = await DataService.FileGetFilt(AppMService.File_Filter); - // faccio paginazione SOLO NELLA DECINA attuale... (quindi non tutte le pagine ma solo subset) - ListRecords = SearchRecords.Skip(numRecord * (currPage % 10 - 1)).Take(numRecord).ToList(); + //SearchRecords = await DataService.FileGetFilt(AppMService.File_Filter); + //// faccio paginazione SOLO NELLA DECINA attuale... (quindi non tutte le pagine ma solo subset) + //ListRecords = SearchRecords.Skip(numRecord * (currPage % 10 - 1)).Take(numRecord).ToList(); + + ListRecords = await DataService.FileGetFilt(AppMService.File_Filter); } protected void ResetData() @@ -314,7 +313,6 @@ namespace MP.Prog.Pages protected async Task ResetFilter() { currRecord = null; - SearchRecords = null; ListRecords = null; AppMService.File_Filter = SelectData.Init(5, 10); SearchTag = defTag; From 07a6978e019aedfffe563bcdad632f4531ca3b0d Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 14 Sep 2021 07:53:08 +0200 Subject: [PATCH 6/7] 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 From c4acee1632a1b692173907ba1bba13928fcd5556 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 14 Sep 2021 13:15:14 +0200 Subject: [PATCH 7/7] UPdate info in refresh ricalcolo --- MP.FileData/Controllers/FileController.cs | 17 +++++++ MP.Prog/Components/ArchiveStatus.razor | 27 ++++++++-- MP.Prog/Components/ArchiveStatus.razor.cs | 60 ++++++++++++++--------- MP.Prog/Components/LoadingData.razor | 4 +- MP.Prog/Data/FileArchDataService.cs | 49 +++++++++++++----- 5 files changed, 115 insertions(+), 42 deletions(-) diff --git a/MP.FileData/Controllers/FileController.cs b/MP.FileData/Controllers/FileController.cs index 10accd55..3d9cf039 100644 --- a/MP.FileData/Controllers/FileController.cs +++ b/MP.FileData/Controllers/FileController.cs @@ -568,6 +568,23 @@ namespace MP.FileData.Controllers return ArchiveList; } + /// + /// Recupera singola macchina + /// + /// + public MacchinaModel MacchinaGetByKey(string idxMacchina) + { + MacchinaModel dbResult = new MacchinaModel(); + using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) + { + dbResult = localDbCtx + .DbSetMacchine + .Where(x => x.IdxMacchina == idxMacchina) + .SingleOrDefault(); + } + return dbResult; + } + /// /// Elenco tabella Macchine /// diff --git a/MP.Prog/Components/ArchiveStatus.razor b/MP.Prog/Components/ArchiveStatus.razor index 3c7fbc27..f35e8a8b 100644 --- a/MP.Prog/Components/ArchiveStatus.razor +++ b/MP.Prog/Components/ArchiveStatus.razor @@ -15,7 +15,29 @@
@if (ListRecords == null) { - +
+
+ @if (showProgress) + { +
+
+ @if (setupMessages.Count > 0) + { +
    + @foreach (var item in setupMessages) + { +
  • @item
  • + } +
+ } +
+
+ } +
+
+ +
+
} else if (totalCount == 0) { @@ -55,9 +77,6 @@ } -
- @lastMessage -
}
\ No newline at end of file diff --git a/MP.Prog/Components/ArchiveStatus.razor.cs b/MP.Prog/Components/ArchiveStatus.razor.cs index 2d0d455d..3287dbf9 100644 --- a/MP.Prog/Components/ArchiveStatus.razor.cs +++ b/MP.Prog/Components/ArchiveStatus.razor.cs @@ -16,22 +16,13 @@ namespace MP.Prog.Components private int numChecks = 0; + private int totalCount = 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; - } - } + private List setupMessages { get; set; } = new List(); #endregion Private Properties @@ -41,33 +32,53 @@ namespace MP.Prog.Components protected FileArchDataService DataService { get; set; } protected int percLoading { get; set; } = 0; - protected bool showProgress { get; set; } = true; + protected bool showProgress { get; set; } = false; #endregion Protected Properties + #region Private Methods + + private async Task verificaTutte(int maxHour) + { + // recupero elenco macchine + var listaMacchine = await DataService.MacchineGetAll(); + int numMacchine = listaMacchine.Count(); + foreach (var item in listaMacchine.Where(x => !string.IsNullOrEmpty(x.BasePath)).ToList()) + { + percLoading += 100 / numMacchine; + numChecks += await DataService.updateMachineArchive(item.IdxMacchina, maxHour, false); + setupMessages.Add($"{item.IdxMacchina}: {numChecks} files"); + StateHasChanged(); + + await Task.Delay(1); + } + } + + #endregion Private Methods + #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); + showProgress = true; + percLoading = 0; + await verificaTutte(maxHour); + + setupMessages.Add($"Effettuata verifica e rilettura di {numChecks} files!"); await ReloadData(); } protected async Task ClearMessage() { await Task.Delay(100); - lastMessage = ""; + setupMessages = new List(); } protected async Task ForceCheck(int maxHour) { - lastMessage = "Inizio Analisi Archivio..."; + setupMessages.Add("Inizio Analisi Archivio..."); ListRecords = null; - //await Task.Delay(1); await ArchiveCheck(maxHour); - //await Task.Delay(1); await ReloadData(); await ClearMessage(); } @@ -80,11 +91,14 @@ namespace MP.Prog.Components protected async Task ReloadData() { - await Task.Delay(10); + await Task.Delay(1); numChecks = 0; ListRecords = await DataService.GetArchiveStatus(); - await Task.Delay(100); - lastMessage = ""; + totalCount = ListRecords.Count; + await Task.Delay(1); + setupMessages = new List(); + showProgress = false; + percLoading = 0; } #endregion Protected Methods diff --git a/MP.Prog/Components/LoadingData.razor b/MP.Prog/Components/LoadingData.razor index b0624468..7ba1bac5 100644 --- a/MP.Prog/Components/LoadingData.razor +++ b/MP.Prog/Components/LoadingData.razor @@ -1,5 +1,5 @@ -

Working

-
+@*

Working

*@ +

loading data

diff --git a/MP.Prog/Data/FileArchDataService.cs b/MP.Prog/Data/FileArchDataService.cs index 2d624808..5335a42e 100644 --- a/MP.Prog/Data/FileArchDataService.cs +++ b/MP.Prog/Data/FileArchDataService.cs @@ -259,6 +259,11 @@ namespace MP.Prog.Data return await Task.FromResult(dbResult); } + public Task MacchinaGetByKey(string idxMacchina) + { + return Task.FromResult(dbController.MacchinaGetByKey(idxMacchina)); + } + public Task> MacchineGetAll() { return Task.FromResult(dbController.MacchineGetAll().ToList()); @@ -288,6 +293,24 @@ namespace MP.Prog.Data /// Numero giorni x ricerca all'indietro da data corrente / 0 = nessun limite /// public async Task updateAllArchive(int numDayPre) + { + int checkDone = 0; + var listaMacchine = await MacchineGetAll(); + foreach (var item in listaMacchine.Where(x => !string.IsNullOrEmpty(x.BasePath)).ToList()) + { + checkDone += await updateMachineArchive(item.IdxMacchina, numDayPre, false); + } + + return await Task.FromResult(checkDone); + } + + /// + /// Aggiorna archivio di una amcchina scansionando path relativo + /// + /// Codice macchina + /// Numero giorni x ricerca all'indietro da data corrente / 0 = nessun limite + /// + public async Task updateMachineArchive(string idxMacchina, int numDayPre, bool fullLog) { int checkDone = 0; Stopwatch stopWatch = new Stopwatch(); @@ -295,12 +318,12 @@ namespace MP.Prog.Data string ruleName = "Rule01.json"; try { - var listaMacchine = await MacchineGetAll(); - foreach (var item in listaMacchine.Where(x => !string.IsNullOrEmpty(x.BasePath)).ToList()) + var macchina = MacchinaGetByKey(idxMacchina).Result; + if (macchina != null && !string.IsNullOrEmpty(macchina.BasePath)) { - if (!string.IsNullOrEmpty(item.RuleName)) + if (!string.IsNullOrEmpty(macchina.RuleName)) { - ruleName = item.RuleName; + ruleName = macchina.RuleName; // gestione confRule... SearchRules currRule = new SearchRules(); try @@ -340,24 +363,24 @@ namespace MP.Prog.Data OutReplace = confReplace, OutExcludeFileName = true }; - - // serializzo - - string rawRule = JsonConvert.SerializeObject(currRule, Formatting.Indented); - Log.Info($"Conf rule generato:{Environment.NewLine}{rawRule}"); + if (fullLog) + { + // serializzo + string rawRule = JsonConvert.SerializeObject(currRule, Formatting.Indented); + Log.Info($"Conf rule generato:{Environment.NewLine}{rawRule}"); + } } - - checkDone += dbController.CheckFileArchived(item.IdxMacchina, item.BasePath, numDayPre, "*.*", currRule); + checkDone = dbController.CheckFileArchived(macchina.IdxMacchina, macchina.BasePath, numDayPre, "*.*", currRule); } } } catch (Exception exc) { - Log.Error($"Eccezione in updateAllArchive{Environment.NewLine}{exc}{Environment.NewLine}{exc.InnerException}"); + Log.Error($"Eccezione in updateMachineArchive{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"); + Log.Info($"Effettuato update archivio file MACCHINA | last {numDayPre} days | {checkDone} checked | {ts.TotalMilliseconds} ms"); return await Task.FromResult(checkDone); }