diff --git a/MP.FileData/Controllers/FileController.cs b/MP.FileData/Controllers/FileController.cs index 087316d5..3d9cf039 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 { @@ -35,6 +36,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) /// @@ -44,10 +50,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 +92,7 @@ namespace MP.FileData.Controllers } else { + checkDone++; // cerca nel DB... FileModel currRecord = archivedFile .Where(x => x.Active && x.Path == file.FullName) @@ -139,9 +146,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() @@ -150,6 +158,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 /// @@ -230,7 +251,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)) @@ -241,6 +262,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; @@ -280,7 +303,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 @@ -346,6 +369,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)) { @@ -353,40 +378,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; } @@ -441,7 +465,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 approvare) /// /// /// @@ -468,7 +492,7 @@ namespace MP.FileData.Controllers } /// - /// Aggiorna un Ordine + /// Aggiorna un record FILE rileggendo e ricalcolando... /// /// /// @@ -479,11 +503,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; @@ -507,6 +536,55 @@ 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; + } + + /// + /// 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.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.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"); }); diff --git a/MP.Prog/Components/ArchiveStatus.razor b/MP.Prog/Components/ArchiveStatus.razor new file mode 100644 index 00000000..f35e8a8b --- /dev/null +++ b/MP.Prog/Components/ArchiveStatus.razor @@ -0,0 +1,82 @@ +
+
+ +
+
+ @if (showProgress) + { +
+
+
+ } +
+
+ @if (ListRecords == null) + { +
+
+ @if (showProgress) + { +
+
+ @if (setupMessages.Count > 0) + { +
    + @foreach (var item in setupMessages) + { +
  • @item
  • + } +
+ } +
+
+ } +
+
+ +
+
+ } + else if (totalCount == 0) + { +
Nessun record trovato
+ } + else + { + + + + + + + + + + + + @foreach (var record in ListRecords) + { + + + + + + + } + +
MacchinaPathModificatiTot File
+ @record.Nome + +
@record.BasePath
+
+ @record.NumChanged + + + @record.TotFile + +
+ } +
+
\ 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..3287dbf9 --- /dev/null +++ b/MP.Prog/Components/ArchiveStatus.razor.cs @@ -0,0 +1,106 @@ +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; + + private int totalCount = 0; + + #endregion Private Fields + + #region Private Properties + + private List setupMessages { get; set; } = new List(); + + #endregion Private Properties + + #region Protected Properties + + [Inject] + protected FileArchDataService DataService { get; set; } + + protected int percLoading { get; set; } = 0; + 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) + { + 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); + setupMessages = new List(); + } + + protected async Task ForceCheck(int maxHour) + { + setupMessages.Add("Inizio Analisi Archivio..."); + ListRecords = null; + await ArchiveCheck(maxHour); + await ReloadData(); + await ClearMessage(); + } + + protected override async Task OnInitializedAsync() + { + ListRecords = null; + await ReloadData(); + } + + protected async Task ReloadData() + { + await Task.Delay(1); + numChecks = 0; + ListRecords = await DataService.GetArchiveStatus(); + totalCount = ListRecords.Count; + await Task.Delay(1); + setupMessages = new List(); + showProgress = false; + percLoading = 0; + } + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/MP.Prog/Components/LoadingData.razor b/MP.Prog/Components/LoadingData.razor index d3228baf..7ba1bac5 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..5335a42e 100644 --- a/MP.Prog/Data/FileArchDataService.cs +++ b/MP.Prog/Data/FileArchDataService.cs @@ -12,6 +12,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; +using MP.FileData.Controllers; +using MP.FileData.DTO; namespace MP.Prog.Data { @@ -104,15 +106,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,23 +217,53 @@ 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.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"); 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 MacchinaGetByKey(string idxMacchina) + { + return Task.FromResult(dbController.MacchinaGetByKey(idxMacchina)); + } + public Task> MacchineGetAll() { return Task.FromResult(dbController.MacchineGetAll().ToList()); @@ -269,72 +292,97 @@ 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; + 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(); + stopWatch.Start(); 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)) - { } - // gestione confRule... - SearchRules currRule = new SearchRules(); - try + if (!string.IsNullOrEmpty(macchina.RuleName)) { - 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 = macchina.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 + }; + if (fullLog) + { + // serializzo + string rawRule = JsonConvert.SerializeObject(currRule, Formatting.Indented); + Log.Info($"Conf rule generato:{Environment.NewLine}{rawRule}"); + } + } + checkDone = dbController.CheckFileArchived(macchina.IdxMacchina, macchina.BasePath, numDayPre, "*.*", currRule); } - - done = dbController.CheckFileArchived(item.IdxMacchina, item.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 MACCHINA | 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/Data/SelectData.cs b/MP.Prog/Data/SelectData.cs index c8e92923..f1b36f0e 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); @@ -27,11 +26,24 @@ 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; public int PageNum { get; set; } = 1; public int PageSize { get; set; } = 10; + public string SearchVal { get; set; } = ""; #endregion Public Properties @@ -69,7 +81,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 cbe96c1c..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 @@
-
-
- +
+
+
+
+
+ + +
+
+
+
+
+
+
+
+ + +
@@ -78,7 +75,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..904f407d 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,10 +15,10 @@ namespace MP.Prog.Pages { #region Private Fields + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); private FileModel currRecord = null; private List ListRecords; private List MacList; - private List SearchRecords; private List TagList; #endregion Private Fields @@ -28,28 +29,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 +61,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 @@ -110,7 +77,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(); } } @@ -132,7 +102,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(); } } @@ -154,7 +127,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(); } } @@ -202,19 +178,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 @@ -254,6 +217,15 @@ namespace MP.Prog.Pages #region Protected Methods + protected async Task AsyncReload() + { + isLoading = true; + currRecord = null; + ListRecords = null; + await ReloadData(); + isLoading = false; + } + protected void Edit(FileModel selRecord) { // rileggo dal DB il record corrente... @@ -261,24 +233,21 @@ 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; + 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 +271,12 @@ namespace MP.Prog.Pages isLoading = false; } + protected async Task RefreshDisplayLoading() + { + await Task.Delay(1); + isLoading = false; + } + protected async Task ReloadAllData() { isLoading = true; @@ -315,10 +290,14 @@ 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); - // faccio paginazione SOLO NELLA DECINA attuale... (quindi non tutte le pagine ma solo subset) - ListRecords = SearchRecords.Skip(numRecord * (currPage % 10 - 1)).Take(numRecord).ToList(); + 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(); + + ListRecords = await DataService.FileGetFilt(AppMService.File_Filter); } protected void ResetData() @@ -330,7 +309,6 @@ namespace MP.Prog.Pages protected async Task ResetFilter() { currRecord = null; - SearchRecords = null; ListRecords = null; AppMService.File_Filter = SelectData.Init(5, 10); SearchTag = defTag; @@ -349,19 +327,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; diff --git a/MP.Prog/Pages/Setup.razor b/MP.Prog/Pages/Setup.razor index cd9bc354..f13a03f9 100644 --- a/MP.Prog/Pages/Setup.razor +++ b/MP.Prog/Pages/Setup.razor @@ -6,10 +6,12 @@ @inject MessageService AppMService -

Setup

- - - -@code { - -} \ No newline at end of file +
+
+

Setup

+
+
+ +
+ @**@ +
\ 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..0df88e8d --- /dev/null +++ b/MP.Prog/Pages/Setup.razor.cs @@ -0,0 +1,21 @@ +using Microsoft.AspNetCore.Components; +using MP.Prog.Data; +using System; +using System.Threading.Tasks; + +namespace MP.Prog.Pages +{ + public partial class Setup : ComponentBase + { + #region Protected Methods + + protected override void OnInitialized() + { + AppMService.ShowSearch = false; + AppMService.PageName = "Setup"; + AppMService.PageIcon = "fas fa-wrench pr-2"; + } + + #endregion Protected Methods + } +} \ No newline at end of file