diff --git a/MP.FileData/Controllers/FileController.cs b/MP.FileData/Controllers/FileController.cs index 84b7a312..087316d5 100644 --- a/MP.FileData/Controllers/FileController.cs +++ b/MP.FileData/Controllers/FileController.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using MP.FileData.DatabaseModels; +using Newtonsoft.Json; namespace MP.FileData.Controllers { @@ -34,57 +35,42 @@ namespace MP.FileData.Controllers #region Public Methods - /// - /// Elenco tabella Articoli (FILTRATO!!!) - /// - /// - /// - /// - public List ArtGetFilt(string searchVal, int maxNum = 100) - { - maxNum = maxNum <= 0 ? 100 : maxNum; - List dbResult = new List(); - using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) - { - int totRecord = localDbCtx - .DbSetArticoli - .Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal)) - .Count(); - if (totRecord > maxNum) - { - dbResult = localDbCtx - .DbSetArticoli - .Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal)) - .OrderBy(x => x.DescArticolo) - .Take(maxNum) - .ToList(); - dbResult.Add(new DatabaseModels.ArticoloModel() { CodArticolo = "#####", DescArticolo = $"... +{totRecord - maxNum} rec ..." }); - } - else - { - dbResult = localDbCtx - .DbSetArticoli - .Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal)) - .OrderBy(x => x.DescArticolo) - .ToList(); - } - } - return dbResult; - } - /// /// Effettua la comparazione tra i file in archivio ed i file attuali e segna info LastCheck e Changed (se cambiati) /// + /// cod macchina + /// path ricerca x macchina + /// Numero giorni x ricerca all'indietro da data corrente / 0 = nessun limite + /// pattern di ricerca (*.*) + /// Regole di ricerca applicate /// - public bool CheckFileArchived(string idxMacchina, string path, string searchPattern) + public bool 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; DirectoryInfo dirInfo = new DirectoryInfo(path); - FileInfo[] fileList = dirInfo.GetFiles(searchPattern); + FileInfo[] fileListRaw = dirInfo.GetFiles(searchPattern, SearchOption.AllDirectories); + List fileList = new List(); + DateTime adesso = DateTime.Now; + // se ho un limite x giorni indietor x modifiche --> limito! + if (numDayPre > 0) + { + foreach (var item in fileListRaw) + { + if (adesso.Subtract(item.LastWriteTime).TotalDays <= numDayPre) + { + fileList.Add(item); + } + } + } + else + { + fileList = fileListRaw.ToList(); + } + Log.Info($"CheckFileArchived S01 | file trovati: {fileList.Count()}"); List fileNew = new List(); List fileChecked = new List(); List fileMod = new List(); - DateTime adesso = DateTime.Now; // recupera elenco file nel DB var archivedFile = FileGetByPath(path, true); @@ -93,38 +79,46 @@ namespace MP.FileData.Controllers // verifica i file foreach (var file in fileList) { - // cerca nel DB... - FileModel currRecord = archivedFile - .Where(x => x.Active && x.Path == file.FullName) - .OrderByDescending(y => y.Rev) - .FirstOrDefault(); - // se NON trova lo crea - if (currRecord == null) + // escludo i file con desinenza da escludere... + if (!string.IsNullOrEmpty(file.Extension) && currRule.ExcludedFileExt.Contains(file.Extension)) { - fileNew.Add(file); + Log.Info($"CheckFileArchived S02: escluso {file.Name} | estensione {file.Extension}"); } else { - // verifico se data modifica sia cambiata... - if (currRecord.LastMod != file.LastWriteTime) + // cerca nel DB... + FileModel currRecord = archivedFile + .Where(x => x.Active && x.Path == file.FullName) + .OrderByDescending(y => y.Rev) + .FirstOrDefault(); + // se NON trova lo crea + if (currRecord == null) { - // calcolo e verifico MD5 - var fileContent = File.ReadAllBytes(file.FullName); - var hash = md5.ComputeHash(fileContent); - var newMD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); - if (newMD5 != currRecord.MD5) + fileNew.Add(file); + } + else + { + // verifico se data modifica sia cambiata... + if (currRecord.LastMod != file.LastWriteTime) { - fileMod.Add(currRecord); + // calcolo e verifico MD5 + var fileContent = File.ReadAllBytes(file.FullName); + var hash = md5.ComputeHash(fileContent); + var newMD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); + if (newMD5 != currRecord.MD5) + { + fileMod.Add(currRecord); + } + else + { + fileChecked.Add(currRecord); + } } else { fileChecked.Add(currRecord); } } - else - { - fileChecked.Add(currRecord); - } } } } @@ -132,12 +126,14 @@ namespace MP.FileData.Controllers // salvo i NUOVI file if (fileNew != null && fileNew.Count > 0) { - FileInsert(idxMacchina, fileNew, 0); + FileInsert(idxMacchina, fileNew, 0, currRule); + Log.Info($"CheckFileArchived S03 | insert {fileNew.Count} files"); } // aggiorno i file modificati if (fileMod != null && fileMod.Count > 0) { FileSetUpdated(fileMod); + Log.Info($"CheckFileArchived S04 | update {fileMod.Count} files"); } // segno data-ora ultimo controllo x file invariati if (fileChecked != null && fileChecked.Count > 0) @@ -176,7 +172,7 @@ namespace MP.FileData.Controllers // se ce ne fosse un altro precedente --> lo (ri)attiva var file2open = localDbCtx .DbSetProgFile - .Where(x => x.Articolo == currItem.Articolo && x.IdxMacchina == currItem.IdxMacchina) + .Where(x => x.Name == currItem.Name && x.IdxMacchina == currItem.IdxMacchina) .OrderByDescending(y => y.Rev) .FirstOrDefault(); if (file2open != null) @@ -242,7 +238,7 @@ namespace MP.FileData.Controllers dbResult = localDbCtx .DbSetProgFile .Include(m => m.Macchina) - .Include(a => a.Articolo) + .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) .ToList(); @@ -257,8 +253,10 @@ namespace MP.FileData.Controllers /// /// /// - public bool FileInsert(string idxMacchina, List newFiles, int rev) + public bool FileInsert(string idxMacchina, List newFiles, int rev, SearchRules currRule) { + // fare: lettura conf x macchina + Log.Info($"FileInsert S01 per macchina {idxMacchina}: {newFiles.Count} files da valutare"); bool answ = false; DateTime adesso = DateTime.Now; // MD5 hash @@ -270,7 +268,6 @@ namespace MP.FileData.Controllers List newRec = newFiles.Select(o => new DatabaseModels.FileModel() { Active = true, - CodArticolo = "ND", DiskStatus = FileState.Ok, IdxMacchina = idxMacchina, LastCheck = adesso, @@ -283,11 +280,51 @@ namespace MP.FileData.Controllers FileContent = File.ReadAllBytes(o.FullName) }).ToList(); - // calcolo MD5 + // gestione Tags (da migliorare...) + List currTags = localDbCtx.DbSetTags.ToList(); + + // calcolo MD5 e tags foreach (var item in newRec) { var hash = md5.ComputeHash(item.FileContent); item.MD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); + + List Tags = new List(); + List Tag4File = new List(); + // se necessario bonifico filename... + string fileName = item.Name; + if (currRule.FileNameExtReplace.Count > 0) + { + foreach (var fReplace in currRule.FileNameExtReplace) + { + fileName = fileName.Replace(fReplace.Key, fReplace.Value).Trim(); + } + } + // cerco codice tag da configurazione + Tags = TagsUtils.searchProgComment(fileName, item.FileStringContent, currRule); + + foreach (var tag in Tags) + { + var foundTag = currTags.SingleOrDefault(x => x.TagId == tag); + // aggiungo i tags SE non ci fossero + if (foundTag == null) + { + var newTag = new TagModel() { TagId = tag }; + currTags.Add(newTag); + Tag4File.Add(newTag); + } + else + { + // al file aggiungo comunque + Tag4File.Add(foundTag); + } + } + // aggiungo ai file + if (Tag4File.Count > 0) + { + // salvo i tags relativi ai files + item.Tags = Tag4File; + } } // aggiungo in blocco @@ -295,11 +332,14 @@ namespace MP.FileData.Controllers .DbSetProgFile .AddRange(newRec); + Log.Info($"FileInsert S02 per macchina {idxMacchina}: {newRec.Count} files da aggiungere EFCore"); + // salvo localDbCtx.SaveChanges(); answ = true; } } + Log.Info($"FileInsert S03 per macchina {idxMacchina}"); return answ; } @@ -313,8 +353,31 @@ 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() + { + 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 + }; + // inserisco come REVISIONE - FileInsert(currFile.IdxMacchina, listUpdate, currFile.Rev + 1); + FileInsert(currFile.IdxMacchina, listUpdate, currFile.Rev + 1, currRule); // archivio vecchio file currFile.Active = false; @@ -444,6 +507,151 @@ namespace MP.FileData.Controllers return done; } + /// + /// Elenco tabella Macchine + /// + /// + public List MacchineGetAll() + { + List dbResult = new List(); + using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) + { + dbResult = localDbCtx + .DbSetMacchine + .OrderBy(x => x.IdxMacchina) + .ToList(); + } + return dbResult; + } + + public void ResetController() + { + dbCtx = new MoonPro_ProgContext(_configuration); + Log.Info("Effettuato reset FileController"); + } + + /// + /// Annulla modifiche su una specifica entity (cancel update) + /// + /// + /// + public bool RollBackEntity(object item) + { + bool answ = false; + try + { + if (dbCtx.Entry(item).State == Microsoft.EntityFrameworkCore.EntityState.Deleted || dbCtx.Entry(item).State == Microsoft.EntityFrameworkCore.EntityState.Modified) + { + dbCtx.Entry(item).Reload(); + } + } + catch (Exception exc) + { + Log.Error($"Eccezione in rollBackEntity{Environment.NewLine}{exc}"); + } + return answ; + } + + /// + /// Elenco TAGS (tutti) + /// + /// + /// + /// + public List TagGetAll() + { + List dbResult = new List(); + using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) + { + dbResult = localDbCtx + .DbSetTags + .OrderBy(x => x.TagId) + .ToList(); + } + return dbResult; + } + + /// + /// Elenco TAGS (FILTRATO!!!) + /// + /// + /// + /// + public List TagGetFilt(string searchVal, int maxNum = 100) + { + maxNum = maxNum <= 0 ? 100 : maxNum; + List dbResult = new List(); + using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) + { + int totRecord = localDbCtx + .DbSetTags + .Where(x => x.TagId.Contains(searchVal)) + .Count(); + if (totRecord > maxNum) + { + dbResult = localDbCtx + .DbSetTags + .Where(x => x.TagId.Contains(searchVal)) + .OrderBy(x => x.TagId) + .Take(maxNum) + .ToList(); + dbResult.Add(new DatabaseModels.TagModel() { TagId = $"... +{totRecord - maxNum} rec ..." }); + } + else + { + dbResult = localDbCtx + .DbSetTags + .Where(x => x.TagId.Contains(searchVal)) + .OrderBy(x => x.TagId) + .ToList(); + } + } + return dbResult; + } + + /// + /// Ricerca singolo record + /// + /// + /// + public TagModel TagGetSingle(string TagId) + { + TagModel dbResult = new TagModel(); + using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) + { + dbResult = localDbCtx + .DbSetTags + .Where(x => x.TagId == TagId) + .FirstOrDefault(); + } + return dbResult; + } + + /// + /// inserisce i tag + /// + /// + /// + public bool TagInsert(List newTags) + { + bool done = false; + using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) + { + try + { + localDbCtx.DbSetTags.AddRange(newTags); + localDbCtx.SaveChanges(); + } + catch (Exception exc) + { + Log.Error($"Eccezione in TagInsert{Environment.NewLine}{exc}"); + } + } + return done; + } + + #endregion Public Methods + #if false /// /// Elenco Azioni (decodifica) @@ -500,54 +708,6 @@ namespace MP.FileData.Controllers return dbResult; } #endif - - /// - /// Elenco tabella Macchine - /// - /// - public List MacchineGetAll() - { - List dbResult = new List(); - using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) - { - dbResult = localDbCtx - .DbSetMacchine - .OrderBy(x => x.IdxMacchina) - .ToList(); - } - return dbResult; - } - - public void ResetController() - { - dbCtx = new MoonPro_ProgContext(_configuration); - Log.Info("Effettuato reset FileController"); - } - - /// - /// Annulla modifiche su una specifica entity (cancel update) - /// - /// - /// - public bool RollBackEntity(object item) - { - bool answ = false; - try - { - if (dbCtx.Entry(item).State == Microsoft.EntityFrameworkCore.EntityState.Deleted || dbCtx.Entry(item).State == Microsoft.EntityFrameworkCore.EntityState.Modified) - { - dbCtx.Entry(item).Reload(); - } - } - catch (Exception exc) - { - Log.Error($"Eccezione in rollBackEntity{Environment.NewLine}{exc}"); - } - return answ; - } - - #endregion Public Methods - #if false /// /// Elenco tabella controlli da filtro diff --git a/MP.FileData/DatabaseModels/ArticoloModel.cs b/MP.FileData/DatabaseModels/ArticoloModel.cs deleted file mode 100644 index c1e6e739..00000000 --- a/MP.FileData/DatabaseModels/ArticoloModel.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -// -// This is here so CodeMaid doesn't reorganize this document -// -namespace MP.FileData.DatabaseModels -{ - [Table("Articoli")] - public partial class ArticoloModel - { - #region Public Properties - - [Key] - public string CodArticolo { get; set; } - public string DescArticolo { get; set; } - public string Disegno { get; set; } - public string Tipo { get; set; } - - #endregion Public Properties - } -} diff --git a/MP.FileData/DatabaseModels/FileModel.cs b/MP.FileData/DatabaseModels/FileModel.cs index af9953b5..021998d8 100644 --- a/MP.FileData/DatabaseModels/FileModel.cs +++ b/MP.FileData/DatabaseModels/FileModel.cs @@ -22,7 +22,6 @@ namespace MP.FileData.DatabaseModels [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int FileId { get; set; } public bool Active { get; set; } = true; - public string CodArticolo { get; set; } public string IdxMacchina { get; set; } = ""; public string Name { get; set; } = ""; public int Rev { get; set; } = 0; @@ -51,8 +50,6 @@ namespace MP.FileData.DatabaseModels } } - [ForeignKey("CodArticolo")] - public virtual ArticoloModel Articolo { get; set; } [ForeignKey("IdxMacchina")] public virtual MacchinaModel Macchina { get; set; } diff --git a/MP.FileData/DatabaseModels/MacchinaModel.cs b/MP.FileData/DatabaseModels/MacchinaModel.cs index d56aaee2..35f4a5e7 100644 --- a/MP.FileData/DatabaseModels/MacchinaModel.cs +++ b/MP.FileData/DatabaseModels/MacchinaModel.cs @@ -18,7 +18,7 @@ namespace MP.FileData.DatabaseModels [Key] public string IdxMacchina { get; set; } = ""; - public string CodMacchina { get; set; } = ""; + public string RuleName { get; set; } = ""; public string Nome { get; set; } = ""; public string Descrizione { get; set; } = ""; public string BasePath { get; set; } = ""; diff --git a/MP.FileData/Migrations/20210907103215_InitDb.Designer.cs b/MP.FileData/Migrations/20210908125127_InitDb.Designer.cs similarity index 79% rename from MP.FileData/Migrations/20210907103215_InitDb.Designer.cs rename to MP.FileData/Migrations/20210908125127_InitDb.Designer.cs index eca66e12..02257387 100644 --- a/MP.FileData/Migrations/20210907103215_InitDb.Designer.cs +++ b/MP.FileData/Migrations/20210908125127_InitDb.Designer.cs @@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace MP.FileData.Migrations { [DbContext(typeof(MoonPro_ProgContext))] - [Migration("20210907103215_InitDb")] + [Migration("20210908125127_InitDb")] partial class InitDb { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -37,34 +37,6 @@ namespace MP.FileData.Migrations b.ToTable("FileModelTagModel"); }); - modelBuilder.Entity("MP.FileData.DatabaseModels.ArticoloModel", b => - { - b.Property("CodArticolo") - .HasColumnType("nvarchar(450)"); - - b.Property("DescArticolo") - .HasColumnType("nvarchar(max)"); - - b.Property("Disegno") - .HasColumnType("nvarchar(max)"); - - b.Property("Tipo") - .HasColumnType("nvarchar(max)"); - - b.HasKey("CodArticolo"); - - b.ToTable("Articoli"); - - b.HasData( - new - { - CodArticolo = "ND", - DescArticolo = "--- Tutti ---", - Disegno = "", - Tipo = "ND" - }); - }); - modelBuilder.Entity("MP.FileData.DatabaseModels.FileModel", b => { b.Property("FileId") @@ -75,9 +47,6 @@ namespace MP.FileData.Migrations b.Property("Active") .HasColumnType("bit"); - b.Property("CodArticolo") - .HasColumnType("nvarchar(450)"); - b.Property("DiskStatus") .HasColumnType("int"); @@ -113,8 +82,6 @@ namespace MP.FileData.Migrations b.HasKey("FileId"); - b.HasIndex("CodArticolo"); - b.HasIndex("IdxMacchina"); b.ToTable("Files"); @@ -128,9 +95,6 @@ namespace MP.FileData.Migrations b.Property("BasePath") .HasColumnType("nvarchar(max)"); - b.Property("CodMacchina") - .HasColumnType("nvarchar(max)"); - b.Property("Descrizione") .HasColumnType("nvarchar(max)"); @@ -143,6 +107,9 @@ namespace MP.FileData.Migrations b.Property("Note") .HasColumnType("nvarchar(max)"); + b.Property("RuleName") + .HasColumnType("nvarchar(max)"); + b.Property("ShowOrder") .HasColumnType("int"); @@ -155,11 +122,11 @@ namespace MP.FileData.Migrations { IdxMacchina = "0", BasePath = "", - CodMacchina = "0", Descrizione = "--- Tutte ---", ImgUrl = "", Nome = "--- Tutte ---", Note = "", + RuleName = "0", ShowOrder = 0 }); }); @@ -191,16 +158,10 @@ namespace MP.FileData.Migrations modelBuilder.Entity("MP.FileData.DatabaseModels.FileModel", b => { - b.HasOne("MP.FileData.DatabaseModels.ArticoloModel", "Articolo") - .WithMany() - .HasForeignKey("CodArticolo"); - b.HasOne("MP.FileData.DatabaseModels.MacchinaModel", "Macchina") .WithMany() .HasForeignKey("IdxMacchina"); - b.Navigation("Articolo"); - b.Navigation("Macchina"); }); #pragma warning restore 612, 618 diff --git a/MP.FileData/Migrations/20210907103215_InitDb.cs b/MP.FileData/Migrations/20210908125127_InitDb.cs similarity index 73% rename from MP.FileData/Migrations/20210907103215_InitDb.cs rename to MP.FileData/Migrations/20210908125127_InitDb.cs index 4ab48e1b..9367447b 100644 --- a/MP.FileData/Migrations/20210907103215_InitDb.cs +++ b/MP.FileData/Migrations/20210908125127_InitDb.cs @@ -7,26 +7,12 @@ namespace MP.FileData.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.CreateTable( - name: "Articoli", - columns: table => new - { - CodArticolo = table.Column(type: "nvarchar(450)", nullable: false), - DescArticolo = table.Column(type: "nvarchar(max)", nullable: true), - Disegno = table.Column(type: "nvarchar(max)", nullable: true), - Tipo = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Articoli", x => x.CodArticolo); - }); - migrationBuilder.CreateTable( name: "Macchine", columns: table => new { IdxMacchina = table.Column(type: "nvarchar(450)", nullable: false), - CodMacchina = table.Column(type: "nvarchar(max)", nullable: true), + RuleName = table.Column(type: "nvarchar(max)", nullable: true), Nome = table.Column(type: "nvarchar(max)", nullable: true), Descrizione = table.Column(type: "nvarchar(max)", nullable: true), BasePath = table.Column(type: "nvarchar(max)", nullable: true), @@ -57,7 +43,6 @@ namespace MP.FileData.Migrations FileId = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Active = table.Column(type: "bit", nullable: false), - CodArticolo = table.Column(type: "nvarchar(450)", nullable: true), IdxMacchina = table.Column(type: "nvarchar(450)", nullable: true), Name = table.Column(type: "nvarchar(max)", nullable: true), Rev = table.Column(type: "int", nullable: false), @@ -73,12 +58,6 @@ namespace MP.FileData.Migrations constraints: table => { table.PrimaryKey("PK_Files", x => x.FileId); - table.ForeignKey( - name: "FK_Files_Articoli_CodArticolo", - column: x => x.CodArticolo, - principalTable: "Articoli", - principalColumn: "CodArticolo", - onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Files_Macchine_IdxMacchina", column: x => x.IdxMacchina, @@ -111,26 +90,16 @@ namespace MP.FileData.Migrations onDelete: ReferentialAction.Cascade); }); - migrationBuilder.InsertData( - table: "Articoli", - columns: new[] { "CodArticolo", "DescArticolo", "Disegno", "Tipo" }, - values: new object[] { "ND", "--- Tutti ---", "", "ND" }); - migrationBuilder.InsertData( table: "Macchine", - columns: new[] { "IdxMacchina", "BasePath", "CodMacchina", "Descrizione", "ImgUrl", "Nome", "Note", "ShowOrder" }, - values: new object[] { "0", "", "0", "--- Tutte ---", "", "--- Tutte ---", "", 0 }); + columns: new[] { "IdxMacchina", "BasePath", "Descrizione", "ImgUrl", "Nome", "Note", "RuleName", "ShowOrder" }, + values: new object[] { "0", "", "--- Tutte ---", "", "--- Tutte ---", "", "0", 0 }); migrationBuilder.CreateIndex( name: "IX_FileModelTagModel_TagsTagId", table: "FileModelTagModel", column: "TagsTagId"); - migrationBuilder.CreateIndex( - name: "IX_Files_CodArticolo", - table: "Files", - column: "CodArticolo"); - migrationBuilder.CreateIndex( name: "IX_Files_IdxMacchina", table: "Files", @@ -148,9 +117,6 @@ namespace MP.FileData.Migrations migrationBuilder.DropTable( name: "Tags"); - migrationBuilder.DropTable( - name: "Articoli"); - migrationBuilder.DropTable( name: "Macchine"); } diff --git a/MP.FileData/Migrations/MoonPro_ProgContextModelSnapshot.cs b/MP.FileData/Migrations/MoonPro_ProgContextModelSnapshot.cs index 1be4c878..27ca048c 100644 --- a/MP.FileData/Migrations/MoonPro_ProgContextModelSnapshot.cs +++ b/MP.FileData/Migrations/MoonPro_ProgContextModelSnapshot.cs @@ -35,34 +35,6 @@ namespace MP.FileData.Migrations b.ToTable("FileModelTagModel"); }); - modelBuilder.Entity("MP.FileData.DatabaseModels.ArticoloModel", b => - { - b.Property("CodArticolo") - .HasColumnType("nvarchar(450)"); - - b.Property("DescArticolo") - .HasColumnType("nvarchar(max)"); - - b.Property("Disegno") - .HasColumnType("nvarchar(max)"); - - b.Property("Tipo") - .HasColumnType("nvarchar(max)"); - - b.HasKey("CodArticolo"); - - b.ToTable("Articoli"); - - b.HasData( - new - { - CodArticolo = "ND", - DescArticolo = "--- Tutti ---", - Disegno = "", - Tipo = "ND" - }); - }); - modelBuilder.Entity("MP.FileData.DatabaseModels.FileModel", b => { b.Property("FileId") @@ -73,9 +45,6 @@ namespace MP.FileData.Migrations b.Property("Active") .HasColumnType("bit"); - b.Property("CodArticolo") - .HasColumnType("nvarchar(450)"); - b.Property("DiskStatus") .HasColumnType("int"); @@ -111,8 +80,6 @@ namespace MP.FileData.Migrations b.HasKey("FileId"); - b.HasIndex("CodArticolo"); - b.HasIndex("IdxMacchina"); b.ToTable("Files"); @@ -126,9 +93,6 @@ namespace MP.FileData.Migrations b.Property("BasePath") .HasColumnType("nvarchar(max)"); - b.Property("CodMacchina") - .HasColumnType("nvarchar(max)"); - b.Property("Descrizione") .HasColumnType("nvarchar(max)"); @@ -141,6 +105,9 @@ namespace MP.FileData.Migrations b.Property("Note") .HasColumnType("nvarchar(max)"); + b.Property("RuleName") + .HasColumnType("nvarchar(max)"); + b.Property("ShowOrder") .HasColumnType("int"); @@ -153,11 +120,11 @@ namespace MP.FileData.Migrations { IdxMacchina = "0", BasePath = "", - CodMacchina = "0", Descrizione = "--- Tutte ---", ImgUrl = "", Nome = "--- Tutte ---", Note = "", + RuleName = "0", ShowOrder = 0 }); }); @@ -189,16 +156,10 @@ namespace MP.FileData.Migrations modelBuilder.Entity("MP.FileData.DatabaseModels.FileModel", b => { - b.HasOne("MP.FileData.DatabaseModels.ArticoloModel", "Articolo") - .WithMany() - .HasForeignKey("CodArticolo"); - b.HasOne("MP.FileData.DatabaseModels.MacchinaModel", "Macchina") .WithMany() .HasForeignKey("IdxMacchina"); - b.Navigation("Articolo"); - b.Navigation("Macchina"); }); #pragma warning restore 612, 618 diff --git a/MP.FileData/ModelBuilderExtensions.cs b/MP.FileData/ModelBuilderExtensions.cs index 74beddde..354ccc88 100644 --- a/MP.FileData/ModelBuilderExtensions.cs +++ b/MP.FileData/ModelBuilderExtensions.cs @@ -18,14 +18,9 @@ namespace MP.FileData /// public static void Seed(this ModelBuilder modelBuilder) { - // inizializzazione dei valori di default x USER + // inizializzazione dei valori di default x MACCHINA modelBuilder.Entity().HasData( - new MacchinaModel { IdxMacchina = "0", CodMacchina = "0", Descrizione = "--- Tutte ---", Nome = "--- Tutte ---", BasePath = "", ImgUrl = "", Note = "", ShowOrder = 0 } - ); - - // inizializzazione dei valori di default x Plant - modelBuilder.Entity().HasData( - new ArticoloModel { CodArticolo = "ND", DescArticolo = "--- Tutti ---", Disegno = "", Tipo = "ND" } + new MacchinaModel { IdxMacchina = "0", RuleName = "0", Descrizione = "--- Tutte ---", Nome = "--- Tutte ---", BasePath = "", ImgUrl = "", Note = "", ShowOrder = 0 } ); } diff --git a/MP.FileData/MoonPro_ProgContext.cs b/MP.FileData/MoonPro_ProgContext.cs index 441c0b86..4b31796c 100644 --- a/MP.FileData/MoonPro_ProgContext.cs +++ b/MP.FileData/MoonPro_ProgContext.cs @@ -59,9 +59,9 @@ namespace MP.FileData #region Public Properties - public virtual DbSet DbSetArticoli { get; set; } public virtual DbSet DbSetMacchine { get; set; } public virtual DbSet DbSetProgFile { get; set; } + public virtual DbSet DbSetTags { get; set; } #endregion Public Properties diff --git a/MP.FileData/SearchRules.cs b/MP.FileData/SearchRules.cs new file mode 100644 index 00000000..d928d5a2 --- /dev/null +++ b/MP.FileData/SearchRules.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MP.FileData +{ + public enum SearchMode + { + /// + /// Ricerca occorrenze di una RegExp dentro il contenuto del file + /// + StringOnFile, + + /// + /// Cerca da path relativo + nume file + /// + PathAndName + } + + public class SearchRules + { + #region Public Properties + + /// + /// Estensioni file esclusi + /// + public List ExcludedFileExt { get; set; } = new List(); + + /// + /// Pattern esclusione Tags (stop-words) + /// + public List ExcludedTags { get; set; } = new List(); + + /// + /// Pattern in formato RegExp + /// + public Dictionary FileNameExtReplace { get; set; } = new Dictionary(); + + /// + /// Quantità massima di caratteri da analizzare, 0 = tutti + /// + public int MaxChar2Search { get; set; } = 100; + + /// + /// Modalità ricerca + /// + public SearchMode Mode { get; set; } = SearchMode.StringOnFile; + + /// + /// Nome della regola di ricerca + /// + public string Name { get; set; } = "ND"; + + /// + /// Configurazione opzionale x rimozione filename da output finali + /// + public bool OutExcludeFileName { get; set; } = true; + + /// + /// Replace in uscita per "bonificare" il tag + /// + public Dictionary OutReplace { get; set; } = new Dictionary(); + + /// + /// Pattern in formato RegExp + /// + public string RegExPattern { get; set; } = ""; + + /// + /// Configurazione opzionale x sostituzione placeholder {{fileName}} in RegExp con il VERO nome file + /// + public bool RegExRepFileName { get; set; } = true; + + /// + /// Configurazione opzionale x sostituzione carriage return --> spazi + /// + public bool ReplaceCR { get; set; } = true; + + #endregion Public Properties + } +} \ No newline at end of file diff --git a/MP.FileData/TagsUtils.cs b/MP.FileData/TagsUtils.cs new file mode 100644 index 00000000..15dfb70c --- /dev/null +++ b/MP.FileData/TagsUtils.cs @@ -0,0 +1,106 @@ +using NLog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace MP.FileData +{ + /// + /// Helper estrazione tag x programmi + /// + public class TagsUtils + { + #region Private Fields + + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + #endregion Private Fields + + #region Protected Fields + + protected static List ExcludeTags = new List(); + + #endregion Protected Fields + + #region Public Methods + + /// + /// Cerca tag di commento inseriti nel formato + /// NOME_PROG(commento) + /// + /// es: O00123(172L D20.5) --> estrae 172L, D20.5 + /// + /// Nome del file (da cercare per contenuto) + /// Contenuto del file da analizzare + /// Parametri analisi + /// + public static List searchProgComment(string fileName, string fileContent, SearchRules currRule) + { + // verifico se trimmare contenuto file + if (fileContent.Length > currRule.MaxChar2Search && currRule.MaxChar2Search > 0) + { + fileContent = fileContent.Substring(0, currRule.MaxChar2Search); + } + // bonifico: a capo --> spazi + fileContent = fileContent.Replace(Environment.NewLine, " ").ToUpper(); + //string pattern = $"\\b{fileName}" + @".{0,2}\([\w\d\s.]+\)"; + string pattern = currRule.RegExPattern; + if (currRule.RegExRepFileName) + { + pattern = pattern.Replace("{{fileName}}", fileName); + } + List answ = new List(); + if (fileContent.Length > 0) + { + // uso regexp + MatchCollection matchTags = Regex.Matches(fileContent, pattern); + if (matchTags.Count > 0) + { + for (int count = 0; count < matchTags.Count; count++) + { + string currMatch = matchTags[count].Value; + // bonifica preliminare (se richiesta) + if (currRule.OutExcludeFileName) + { + currMatch = currMatch.Replace(fileName, ""); + } + if (currRule.OutReplace.Count > 0) + { + foreach (var item in currRule.OutReplace) + { + currMatch = currMatch.Replace(item.Key, item.Value); + } + } + // trim finale + currMatch = currMatch.Trim(); + + // split con spazi + var splitTags = currMatch.Split(" "); + foreach (var item in splitTags) + { + if (!string.IsNullOrEmpty(item)) + { + if (!currRule.ExcludedTags.Contains(item) && item != fileName) + { + // esclusione valori ignorati + answ.Add(item); + } + } + } + } + } + } + // se nullo --> segnalo! + if (answ.Count == 0) + { + Log.Warn($"searchProgComment Attenzione Tag non trovati | {fileName} | pattern: {pattern}{Environment.NewLine}{fileContent}"); + } + return answ; + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/MP.Prog/Components/DataPager.razor b/MP.Prog/Components/DataPager.razor index 818627ba..3d577d19 100644 --- a/MP.Prog/Components/DataPager.razor +++ b/MP.Prog/Components/DataPager.razor @@ -4,37 +4,17 @@
@if (totalCount > 0) { - - - - - - - - - - - +
    +
  • +
  • @for (int i = @startPage; i <= endPage; ++i) { var pageNum = i; - - - @pageNum - - +
  • } - - - - - - - - - - - +
  • +
  • +
}
@@ -42,9 +22,9 @@
@if (showLoading) { - - - +
+
+
}
diff --git a/MP.Prog/Components/DataPager.razor.cs b/MP.Prog/Components/DataPager.razor.cs index adc3e47e..c88f0745 100644 --- a/MP.Prog/Components/DataPager.razor.cs +++ b/MP.Prog/Components/DataPager.razor.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using Microsoft.AspNetCore.Components; +using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Components; -using MP.Prog.Components; -using MP.Prog.Data; namespace MP.Prog.Components { @@ -168,9 +164,14 @@ namespace MP.Prog.Components #region Protected Methods - protected void HandlePaginationItemClick(string page) + protected string cssActive(int numPage) { - currPage = int.Parse(page); + string answ = ""; + if (numPage == currPage) + { + answ = "active"; + } + return answ; } protected override async Task OnInitializedAsync() @@ -178,6 +179,11 @@ namespace MP.Prog.Components await Task.Run(() => showLoading = false); } + protected void PaginationItemClick(int page) + { + currPage = page; + } + #endregion Protected Methods } } \ No newline at end of file diff --git a/MP.Prog/Components/DiffView.razor b/MP.Prog/Components/DiffView.razor index 845fc93e..346db6ca 100644 --- a/MP.Prog/Components/DiffView.razor +++ b/MP.Prog/Components/DiffView.razor @@ -24,8 +24,8 @@
-
- @numChanges modifiche +
+ @numChanges modifiche
diff --git a/MP.Prog/Components/FileEditor.razor.cs b/MP.Prog/Components/FileEditor.razor.cs index d600311a..dd163112 100644 --- a/MP.Prog/Components/FileEditor.razor.cs +++ b/MP.Prog/Components/FileEditor.razor.cs @@ -36,9 +36,6 @@ namespace MP.Prog.Components #region Public Properties - [Parameter] - public List ArtList { get; set; } - [Parameter] public FileModel currItem { @@ -61,6 +58,9 @@ namespace MP.Prog.Components [Parameter] public List MacList { get; set; } + [Parameter] + public List TagList { get; set; } + #endregion Public Properties #region Private Methods diff --git a/MP.Prog/Components/Test.razor b/MP.Prog/Components/Test.razor new file mode 100644 index 00000000..075ca757 --- /dev/null +++ b/MP.Prog/Components/Test.razor @@ -0,0 +1,27 @@ +

Test

+ + + +@code{ + private bool DisablePlaceOrderButton { get; set; } = false; + + public string Title { get; set; } = "Place Order"; + + private async Task PlaceOrder_Clicked() + { + + await DisablePlaceOrder(); + + DisablePlaceOrderButton = false; + Title = "Place Order"; + + } + + async Task DisablePlaceOrder() + { + DisablePlaceOrderButton = true; + Title = "Wait..."; + await Task.Delay(1000); + + } +} \ No newline at end of file diff --git a/MP.Prog/Conf/.placeholder b/MP.Prog/Conf/.placeholder new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/MP.Prog/Conf/.placeholder @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/MP.Prog/Conf/Rule01.json b/MP.Prog/Conf/Rule01.json new file mode 100644 index 00000000..1ee93dff --- /dev/null +++ b/MP.Prog/Conf/Rule01.json @@ -0,0 +1,29 @@ +{ + "ExcludedTags": [ + "M4", + "M5", + "M4+A", + "M4+B", + "M5+A", + "M5+B" + ], + "ExcludedFileExt": [ + ".xls", + ".xls#", + ".xlsx" + ], + "FileNameExtReplace": { + ".P-2": "" + }, + "MaxChar2Search": 100, + "Mode": 0, + "Name": "Tag da Commento Filename", + "OutExcludeFileName": true, + "OutReplace": { + "(": " ", + ")": " " + }, + "RegExPattern": "\\b{{fileName}}.{0,2}\\([\\w\\d\\s./\\-=]+\\)", + "RegExRepFileName": true, + "ReplaceCR": true +} \ No newline at end of file diff --git a/MP.Prog/Data/FileArchDataService.cs b/MP.Prog/Data/FileArchDataService.cs index 0f1d2a5c..a4d32bcb 100644 --- a/MP.Prog/Data/FileArchDataService.cs +++ b/MP.Prog/Data/FileArchDataService.cs @@ -2,12 +2,16 @@ using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using MP.FileData; +using Newtonsoft.Json; using NLog; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Diagnostics; namespace MP.Prog.Data { @@ -19,7 +23,7 @@ namespace MP.Prog.Data private static ILogger _logger; - private static List ElencoMacchine = new List(); + private static List ElencoMacchine = new List(); private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); @@ -50,7 +54,7 @@ namespace MP.Prog.Data #region Public Fields - public static MP.FileData.Controllers.FileController dbController; + public static FileData.Controllers.FileController dbController; #endregion Public Fields @@ -71,7 +75,7 @@ namespace MP.Prog.Data } else { - dbController = new MP.FileData.Controllers.FileController(configuration); + dbController = new FileData.Controllers.FileController(configuration); StringBuilder sb = new StringBuilder(); sb.AppendLine($"DbController OK"); _logger.LogInformation(sb.ToString()); @@ -100,6 +104,15 @@ 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) @@ -205,39 +218,40 @@ namespace MP.Prog.Data #region Public Methods - public Task> ArticoliGetFilt(string SearchVal) - { - return Task.FromResult(dbController.ArtGetFilt(SearchVal, 200).ToList()); - //return Task.FromResult(dbController.ArtGetFilt(SearchVal, 20).ToList()); - } - public void Dispose() { // Clear database controller dbController.Dispose(); } - public Task FileGetByKey(int FileId) + public Task FileGetByKey(int FileId) { return Task.FromResult(dbController.FileGetByKey(FileId)); } - public Task> FileGetFilt(string IdxMacchina, string CodArticolo, bool OnlyActive, bool OnlyMod, string SearchVal) + public async Task> FileGetFilt(string IdxMacchina, string CodArticolo, bool OnlyActive, bool OnlyMod, string SearchVal) { - return Task.FromResult(dbController.FileGetFilt(IdxMacchina, CodArticolo, OnlyActive, OnlyMod, SearchVal).ToList()); + List dbResult = new List(); + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + dbResult = dbController.FileGetFilt(IdxMacchina, CodArticolo, OnlyActive, OnlyMod, 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 Task> MacchineGetAll() + public Task> MacchineGetAll() { return Task.FromResult(dbController.MacchineGetAll().ToList()); } - public Task> MachineList() + public async Task> MachineList() { List answ = new List(); answ.Add(new AutocompleteModel { LabelField = "--- TUTTE ---", ValueField = "*" }); answ.AddRange(dbController.MacchineGetAll().Select(x => new AutocompleteModel { LabelField = $"{x.IdxMacchina} | {x.Nome} {x.Descrizione} ", ValueField = x.IdxMacchina }).ToList()); - return Task.FromResult(answ); + return await Task.FromResult(answ); } public void rollBackEdit(object item) @@ -245,22 +259,82 @@ namespace MP.Prog.Data dbController.RollBackEntity(item); } + public async Task> TagGetFilt(string SearchVal) + { + return await Task.FromResult(dbController.TagGetFilt(SearchVal, 200).ToList()); + } + /// /// Aggiorna intero archivio scansionando dati x tutte le macchine che hanno un path valido /// + /// Numero giorni x ricerca all'indietro da data corrente / 0 = nessun limite /// - public async Task updateAllArchive() + public async Task updateAllArchive(int numDayPre) { + bool done = false; + string ruleName = "Rule01.json"; try { var listaMacchine = await MacchineGetAll(); foreach (var item in listaMacchine.Where(x => !string.IsNullOrEmpty(x.BasePath)).ToList()) { - dbController.CheckFileArchived(item.IdxMacchina, item.BasePath, "*.*"); + 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() + { + 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}"); + } + + done = dbController.CheckFileArchived(item.IdxMacchina, item.BasePath, numDayPre, "*.*", currRule); } } - catch - { } + catch (Exception exc) + { + Log.Error($"Eccezione in updateAllArchive{Environment.NewLine}{exc}{Environment.NewLine}{exc.InnerException}"); + } + + return await Task.FromResult(done); } #endregion Public Methods diff --git a/MP.Prog/Data/SelectData.cs b/MP.Prog/Data/SelectData.cs index 62f2a68b..c8e92923 100644 --- a/MP.Prog/Data/SelectData.cs +++ b/MP.Prog/Data/SelectData.cs @@ -12,10 +12,27 @@ namespace MP.Prog.Data public string CodArticolo { get; set; } = ""; public DateTime DateEnd { get; set; } = DateTime.Now.AddMinutes(1); public DateTime DateStart { get; set; } = DateTime.Now.AddDays(-7); + + /// + /// Primo record x selezione paginata, tipicamente primo della "decina" della pagina corrente + /// + public int FirstRecord + { + get + { + int primaPag = PageNum % 10; + int decina = PageNum - primaPag; + return PageSize * decina + 1; + } + } + public string IdxMacchina { get; set; } = ""; public bool OnlyActive { get; set; } = true; public bool OnlyMod { get; set; } = false; + public int PageNum { get; set; } = 1; + public int PageSize { get; set; } = 10; + #endregion Public Properties #region Public Methods @@ -43,6 +60,11 @@ namespace MP.Prog.Data { if (!(obj is SelectData item)) return false; + + if (PageSize != item.PageSize) + return false; + if (PageNum != item.PageNum) + return false; if (OnlyActive != item.OnlyActive) return false; if (OnlyMod != item.OnlyMod) diff --git a/MP.Prog/MP.Prog.csproj b/MP.Prog/MP.Prog.csproj index 8f98d113..d2f8bc3c 100644 --- a/MP.Prog/MP.Prog.csproj +++ b/MP.Prog/MP.Prog.csproj @@ -5,11 +5,7 @@ - - - - - + @@ -20,7 +16,8 @@ - + + diff --git a/MP.Prog/Pages/Archive.razor b/MP.Prog/Pages/Archive.razor index 31c0b83f..cbe96c1c 100644 --- a/MP.Prog/Pages/Archive.razor +++ b/MP.Prog/Pages/Archive.razor @@ -1,5 +1,7 @@ @page "/Archive" +@using MP.Prog.Components +
@@ -10,12 +12,19 @@
-
-
+
+
+ +
+
+
@@ -25,17 +34,17 @@
-
+
- +
-
+
@@ -47,7 +56,7 @@ { foreach (var item in MacList) { - + } } @@ -65,12 +74,12 @@
@if (currRecord != null) { - + } @if (ListRecords == null) { - - RELOADING +

Working

+ } else if (totalCount == 0) { @@ -89,7 +98,7 @@ Size State Macchina - Articolo + Tags Modificato @*Controllo*@ @@ -132,12 +141,14 @@ -
@record.Macchina.CodMacchina
+
@record.Macchina.Nome
@record.Macchina.Descrizione
-
@record.Articolo.Disegno
-
@record.Articolo.DescArticolo
+ @foreach (var item in record.Tags) + { + @item.TagId + }
@record.LastMod.ToString("yyyy.MM.dd")
@@ -156,6 +167,6 @@ }
\ No newline at end of file diff --git a/MP.Prog/Pages/Archive.razor.cs b/MP.Prog/Pages/Archive.razor.cs index f9279fde..c491d13d 100644 --- a/MP.Prog/Pages/Archive.razor.cs +++ b/MP.Prog/Pages/Archive.razor.cs @@ -5,6 +5,7 @@ using MP.Prog.Data; using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace MP.Prog.Pages @@ -13,25 +14,23 @@ namespace MP.Prog.Pages { #region Private Fields - private List ArtList; - private FileModel currRecord = null; private List ListRecords; private List MacList; private List SearchRecords; + private List TagList; #endregion Private Fields #region Protected Fields - protected string _SearchArt; + protected string _SearchTag; - protected string defCodArt = ""; + protected string defTag = ""; #endregion Protected Fields - #region Private Properties - +#if false private int _currPage { get; set; } = 1; private int _numRecord { get; set; } = 10; @@ -49,9 +48,37 @@ namespace MP.Prog.Pages } } } +#endif + + #region Private Properties + + private int currPage + { + get + { + return AppMService.File_Filter.PageNum; + } + set + { + AppMService.File_Filter.PageNum = value; + } + } private bool isLoading { get; set; } = false; + private int numRecord + { + get + { + return AppMService.File_Filter.PageSize; + } + set + { + AppMService.File_Filter.PageSize = value; + } + } + +#if false private int numRecord { get => _numRecord; @@ -65,6 +92,7 @@ namespace MP.Prog.Pages } } } +#endif private bool OnlyActive { @@ -110,28 +138,6 @@ namespace MP.Prog.Pages } } - private string SelCodArt - { - get - { - string answ = ""; - if (AppMService.File_Filter != null) - { - answ = AppMService.File_Filter.CodArticolo; - } - return answ; - } - set - { - if (!AppMService.File_Filter.CodArticolo.Equals(value)) - { - AppMService.File_Filter.CodArticolo = value; - var pUpd = Task.Run(async () => await ReloadData()); - pUpd.Wait(); - } - } - } - private string SelIdxMacc { get @@ -170,26 +176,25 @@ namespace MP.Prog.Pages [Inject] protected NavigationManager NavManager { get; set; } - protected string SearchArt + protected string SearchTag { get { - return _SearchArt; + return _SearchTag; } set { - isLoading = true; - _SearchArt = value; + _SearchTag = value; // se son > 3 char... debounce... if (string.IsNullOrEmpty(value)) { - _SearchArt = defCodArt; + _SearchTag = defTag; } - if (value.Length >= defCodArt.Length) + if (value.Length >= defTag.Length) { var pUpd = Task.Run(async () => { - ArtList = await DataService.ArticoliGetFilt(SearchArt); + TagList = await DataService.TagGetFilt(SearchTag); }); pUpd.Wait(); } @@ -245,14 +250,6 @@ namespace MP.Prog.Pages return answ; } - private async Task ReloadData() - { - isLoading = true; - SearchRecords = await DataService.FileGetFilt(AppMService.File_Filter.IdxMacchina, AppMService.File_Filter.CodArticolo, AppMService.File_Filter.OnlyActive, AppMService.File_Filter.OnlyMod, AppMService.SearchVal); - ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); - isLoading = false; - } - #endregion Private Methods #region Protected Methods @@ -264,37 +261,45 @@ namespace MP.Prog.Pages pUpd.Wait(); } - protected async Task ForceCheck() + protected void ForceCheck(int maxHour) { - isLoading = true; - await DataService.updateAllArchive(); - currRecord = null; - SearchRecords = null; - ListRecords = null; - AppMService.File_Filter = SelectData.Init(5, 10); - isLoading = false; - await ReloadAllData(); - } - - protected void ForceReload(int newNum) - { - numRecord = newNum; - } - - protected void ForceReloadPage(int newNum) - { - currPage = newNum; + 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(); } protected override async Task OnInitializedAsync() { DataService.ResetController(); - SearchArt = defCodArt; + SearchTag = defTag; AppMService.ShowSearch = false; AppMService.PageName = "Archivio File Programmi"; AppMService.PageIcon = "fas fa-folder pr-2"; AppMService.EA_SearchUpdated += OnSeachUpdated; await ReloadAllData(); + isLoading = false; + } + + protected async Task PagerReloadNum(int newNum) + { + numRecord = newNum; + await ReloadData(); + isLoading = false; + } + + protected async Task PagerReloadPage(int newNum) + { + currPage = newNum; + await ReloadData(); + isLoading = false; } protected async Task ReloadAllData() @@ -302,14 +307,20 @@ namespace MP.Prog.Pages isLoading = true; MacList = await DataService.MacchineGetAll(); SelIdxMacc = "0"; - SearchArt = defCodArt; - - ArtList = await DataService.ArticoliGetFilt(SearchArt); - - isLoading = false; + SearchTag = defTag; + TagList = await DataService.TagGetFilt(SearchTag); await ReloadData(); } + protected async Task ReloadData() + { + isLoading = true; + 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(); + } + protected void ResetData() { DataService.rollBackEdit(currRecord); @@ -322,18 +333,14 @@ namespace MP.Prog.Pages SearchRecords = null; ListRecords = null; AppMService.File_Filter = SelectData.Init(5, 10); - SearchArt = defCodArt; + SearchTag = defTag; await ReloadAllData(); + isLoading = false; } - protected void ResetSearchArt() + protected void ResetSearchTag() { - SearchArt = defCodArt; - } - - protected void searchArtUpd(string newCod) - { - SelCodArt = newCod; + SearchTag = defTag; } protected void Select(FileModel selRecord) @@ -342,6 +349,19 @@ 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 d7f551ca..cd9bc354 100644 --- a/MP.Prog/Pages/Setup.razor +++ b/MP.Prog/Pages/Setup.razor @@ -8,45 +8,8 @@

Setup

-
-
-