From 8b66602575ecd232c244a26f6f92f2e61e1d59bd Mon Sep 17 00:00:00 2001 From: "zaccaria.majid" Date: Wed, 7 Jun 2023 16:51:05 +0200 Subject: [PATCH] fix scansione cartella B --- .../Services/WebDoorCreatorService.cs | 53 ++++++++++++++++--- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/WebDoorCreator.Data/Services/WebDoorCreatorService.cs b/WebDoorCreator.Data/Services/WebDoorCreatorService.cs index 2ce15c3..f461d28 100644 --- a/WebDoorCreator.Data/Services/WebDoorCreatorService.cs +++ b/WebDoorCreator.Data/Services/WebDoorCreatorService.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Identity.UI.Services; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; +using Microsoft.IdentityModel.Protocols; using Microsoft.Reporting.Map.WebForms.BingMaps; using Newtonsoft.Json; using NLog; @@ -12,6 +13,7 @@ using System.Text; using WebDoorCreator.Core; using WebDoorCreator.Data.Controllers; using WebDoorCreator.Data.DbModels; +using WebDoorCreator.Data.DTO; namespace WebDoorCreator.Data.Services { @@ -62,6 +64,8 @@ namespace WebDoorCreator.Data.Services Log.Info("Avviata classe WebDoorCreatorService"); } + + #endregion Public Constructors #region Public Properties @@ -1859,14 +1863,18 @@ namespace WebDoorCreator.Data.Services } - public async Task scanDirA() + public async Task scanDirB() { bool answ = false; - string rootPathNew = _configuration.GetValue("CompoBaseDirs:NewCompoDir"); + string rootPathNew = _configuration.GetValue("CompoBaseDirs:NewCompoDir"); List doorOpTypesList = new List(); + List originalFiles = new List(); + List newFiles = new List(); string[] dirs = Directory.GetDirectories(rootPathNew); + //Cerco quali sono i componenti da scansionare List listActiveCompo = await CompoGetAllActive(Path.Combine(rootPathNew, @"Default.ini")); + System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create(); //Ciclo in tutte le cartelle ed estraggo le cartelle dei componenti foreach (string dir in dirs) { @@ -1898,13 +1906,35 @@ namespace WebDoorCreator.Data.Services }; doorOpTypesList.Add(tempHwType); } - - foreach(var tplDir in templateDirectories) + foreach (var tplDir in templateDirectories) { string[] tpls = Directory.GetFiles(tplDir, "*"); - foreach(var tpl in tpls) + var archiviedFiles = dbController.DoorOpTypeGetByPath(tplDir); + foreach (var tpl in tpls) { - var fileName = Path.GetFileName(tpl).Split("\\")[Path.GetFileName(tpl).Split("\\").Length-1]; + FileInfo fi = new FileInfo(tpl); + var fileName = Path.GetFileName(tpl).Split("\\")[Path.GetFileName(tpl).Split("\\").Length - 1]; + var fileContent = File.ReadAllBytes(tpl); + var hash = md5.ComputeHash(fileContent); + var newMD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); + + var path2Search = archiviedFiles + .Where(x => x.OpCode == tpl) + .FirstOrDefault(); + + if(path2Search == null) + { + + } + + //FileDTO currFileInfo = new FileDTO() + //{ + // FilePath = fileName, + // FileDim = fi.Length, + // FileMD5 = newMD5, + // lastModTime = fi.LastWriteTime + //}; + //newFiles.Add() } } } @@ -1920,6 +1950,7 @@ namespace WebDoorCreator.Data.Services List HwsList = new List(); bool hwAdded = false; List listActiveCompo = await CompoGetAllActive(Path.Combine(rootPath, @"Default.ini")); + System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create(); //ciclo nelle directrory per beccare tutti gli hw e le relatice path del file di origine foreach (string dir in dirs) { @@ -2011,6 +2042,7 @@ namespace WebDoorCreator.Data.Services foreach (string templateFile in templateFiles) { + FileInfo fi = new FileInfo(templateFile); string defGpNum = ""; var lines = File.ReadAllLines(templateFile).ToList(); @@ -2049,7 +2081,9 @@ namespace WebDoorCreator.Data.Services DefaultVal = defGpNum, InputType = " ", }; - + var fileContent = File.ReadAllBytes(templateFile); + var hash = md5.ComputeHash(fileContent); + var oldMD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); DoorOpTypeModel tempType = new DoorOpTypeModel() { ParentId = item.DoorOpTypId, @@ -2057,7 +2091,10 @@ namespace WebDoorCreator.Data.Services OpCode = @$"{dir}\{tName[tName.Length - 1]}\{Path.GetFileName(templateFile)}", HasHw = true, IsConcrete = true, - HwCode = $"{compoCode}".Replace(" ", "_") + HwCode = $"{compoCode}".Replace(" ", "_"), + FileDim = fi.Length, + FileMD5 = oldMD5, + LastMod = fi.LastWriteTime }; doorOpTypesList.Add(tempType); if (values.Where(x => x.TableName == temp.TableName && x.FieldName == temp.FieldName && x.Value == temp.Value).Count() == 0 && temp.TableName != null && temp.FieldName != null && temp.Value != null)