ok scan files nelle cartelle.

This commit is contained in:
zaccaria.majid
2023-08-30 17:04:20 +02:00
parent e51b311203
commit d6dad0211f
13 changed files with 282 additions and 61 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>WebDoorCreator - Egalware</i>
<h4>Version: 0.9.2308.2917</h4>
<h4>Version: 0.9.2308.3017</h4>
<br /> Release note:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
0.9.2308.2917
0.9.2308.3017
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>0.9.2308.2917</version>
<version>0.9.2308.3017</version>
<url>http://nexus.steamware.net/repository/SWS/WDC/stable/WDC.UI.zip</url>
<changelog>http://nexus.steamware.net/repository/SWS/WDC/stable/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+1
View File
@@ -59,6 +59,7 @@ namespace WebDoorCreator.Core
public const string rKeyVocLemma = $"{redisBaseAddr}:Cache:VocLemma";
public const string rKeyVocLemmaTEMP = $"{redisBaseAddr}:Cache:VocLemmaTEMP";
public const string rKeyLanguage = $"{redisBaseAddr}:Cache:Languages";
public const string rKeyDirsScan = $"{redisBaseAddr}:Cache:Scan";
/// <summary>
/// variabili accessorie ulteriori
+9 -1
View File
@@ -4,7 +4,7 @@
{
#region Public Enums
public enum UserLevel
{
@@ -32,6 +32,14 @@
CodeDescending
}
public enum fileStatus
{
none = 0,
add,
mod,
rem
}
#endregion Public Enums
}
}
+5 -3
View File
@@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static WebDoorCreator.Core.Enum;
namespace WebDoorCreator.Data.DTO
{
@@ -13,14 +14,15 @@ namespace WebDoorCreator.Data.DTO
[Serializable]
public class FileDTO
{
public string HwCode { get; set; } = "";
//public string HwCode { get; set; } = "";
public string FileBaseDir { get; set; } = "";
public string FileAbsPath { get; set; } = "";
//public string FileAbsPath { get; set; } = "";
public string FileRelPath { get; set; } = "";
public string FileMD5 { get; set; } = "";
public long FileDim { get; set; } = 0;
public DateTime lastModTime { get; set; } = DateTime.Now;
public int status { get; set; } = 0;
public fileStatus status { get; set; } = fileStatus.none;
public bool action { get; set; } = false;
}
}
@@ -2904,7 +2904,7 @@ namespace WebDoorCreator.Data.Services
if (!string.IsNullOrEmpty(rawData))
{
source = "REDIS";
var tempResult = JsonConvert.DeserializeObject<List<DoorOpTypeModel>>(rawData)?.Where(x=>x.OpCode.StartsWith(path)).ToList();
var tempResult = JsonConvert.DeserializeObject<List<DoorOpTypeModel>>(rawData)?.Where(x => x.OpCode.StartsWith(path)).ToList();
if (tempResult == null)
{
dbResult = new List<DoorOpTypeModel>();
@@ -2924,6 +2924,7 @@ namespace WebDoorCreator.Data.Services
}
return dbResult;
}
#if false
public async Task<List<DoorOpTypeModel>> scanAndCompare()
{
@@ -2979,11 +2980,11 @@ namespace WebDoorCreator.Data.Services
DoorOpTypeModel tempTpl = new DoorOpTypeModel()
{
ParentId = 0,
Description = $"Template for {itemNew.HwCode}",
//-.-------Description = $"Template for {itemNew.HwCode}",
OpCode = @$"{itemNew.FileAbsPath.Replace("NewComp", "CurComp")}",
HasHw = true,
IsConcrete = true,
HwCode = itemNew.HwCode,
//HwCode = itemNew.HwCode,
FileDim = currFileDim,
FileMD5 = newMD5,
LastMod = currFileLastMod,
@@ -3009,11 +3010,13 @@ namespace WebDoorCreator.Data.Services
return doorOpTypesList;
}
#endif
/// <summary>
/// Esegue scansione dir richeista
/// </summary>
/// <param name="rootPath"></param>
/// <returns></returns>
#if false
public async Task<List<FileDTO>> scanSrcDestDir(string rootPath)
{
await Task.Delay(1);
@@ -3072,15 +3075,16 @@ namespace WebDoorCreator.Data.Services
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"scanAndCompare in: {ts.TotalMilliseconds} ms");
Log.Debug($"scanSrcDestDir in: {ts.TotalMilliseconds} ms");
}
catch (Exception exc)
{
Log.Error($"Exception during scanAndCompare: {exc}{Environment.NewLine}");
Log.Error($"Exception during scanSrcDestDir: {exc}{Environment.NewLine}");
}
return dirAFiles;
}
#endif
/// <summary>
/// Update company
/// </summary>
@@ -3449,6 +3453,111 @@ namespace WebDoorCreator.Data.Services
return dbResult;
}
/// <summary>
/// Esegue scansione dir richeista
/// </summary>
/// <param name="rootPath"></param>
/// <returns></returns>
public async Task<Dictionary<string, FileDTO>> scanSrcDestDir(string rootPath)
{
await Task.Delay(1);
List<FileDTO> dirAFiles = new List<FileDTO>();
Dictionary<string, FileDTO> filesDict = new Dictionary<string, FileDTO>();
try
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
string[] dirs = Directory.GetDirectories(rootPath);
using (MD5 md5 = MD5.Create())
{
foreach (var dir in dirs)
{
string[] iniFiles = Directory.GetFiles(dir, "Config.ini");
string compoCode = "";
foreach (var file in iniFiles)
{
List<string> lines = File.ReadAllLines(file).ToList();
IniFile fIni = new IniFile(file);
var compoName = fIni.ReadString("Compo", "Name", "COMPONAME");
var compoT = fIni.ReadString("Template", "Name", "TEMPSHAPE");
compoCode = compoName.Split("/")[0].Trim();
}
string[] templateDirectories = Directory.GetDirectories(dir);
foreach (var tplDir in templateDirectories)
{
string[] tpls = Directory.GetFiles(tplDir, "*");
//var archiviedFiles = dbController.DoorOpTypeGetByPath(tplDir);
foreach (var tpl in tpls)
{
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();
FileDTO currFileInfo = new FileDTO()
{
//FileBaseDir = tplDir,
//FileAbsPath = fi.FullName,
FileRelPath = fileName,
FileDim = fi.Length,
FileMD5 = newMD5,
lastModTime = fi.LastWriteTime
};
var src = fi.FullName.Split("\\").Skip(3).ToArray();
StringBuilder sb = new StringBuilder();
foreach (var line in src)
{
if (src.Last().ToString() == line)
{
sb.Append($"{line}");
}
else
{
sb.Append($"{line}\\");
}
}
if (!filesDict.ContainsKey(sb.ToString()))
{
filesDict.Add(sb.ToString(), currFileInfo);
}
}
}
}
}
string currKey = $"{Constants.rKeyDirsScan}:{rootPath}";
string rawData = JsonConvert.SerializeObject(filesDict);
await redisDb.StringSetAsync(currKey, rawData);
string filez = "";
if (rootPath.Contains("Cur"))
{
filez = "DX.txt";
}
else
{
filez = "SX.txt";
}
File.WriteAllText(filez, rawData);
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"scanSrcDestDir in: {ts.TotalMilliseconds} ms");
}
catch (Exception exc)
{
Log.Error($"Exception during scanSrcDestDir: {exc}{Environment.NewLine}");
}
return filesDict;
}
#endregion Public Methods
#region Protected Properties
@@ -1,15 +1,37 @@
<button @onclick="()=>scanB()">Scan Dir New</button>
<div class="d-flex justify-content-evenly p-3" style="min-height: 50rem;">
<div class="col-5 border border-dark" style="min-height: 40rem;">
@if (tempDOT != null)
<table class="table table-striped" style="min-height: 50rem;">
<thead>
<tr>
<th>New files</th>
<th class="d-flex justify-content-center">
<button class="btn btn-sm bnt-dark" @onclick="()=>selectAll()"><i class="fa-regular fa-square-check"></i></button>
<button class="btn btn-sm bnt-dark" @onclick="()=>unselectAll()"><i class="fa-solid fa-retweet"></i></button>
</th>
<th class="text-end">Old files</th>
</tr>
</thead>
<tbody>
@foreach (var item in files2Chk)
{
@foreach (var item in tempDOT)
{
<div>@($"{Path.GetFileName(item.OpCode)} {item.status} {item.FileMD5}")</div>
}
<tr>
<td>
@if (item.Value.status == Core.Enum.fileStatus.add || item.Value.status == Core.Enum.fileStatus.mod)
{
@item.Key
}
</td>
<td class="text-center">
<button class="btn @btnCssClass(item.Value.status, item.Value.action)" @onclick="()=>changeDoAct(item)"><i class="@btnIcon(item.Value.status)"></i></button>
</td>
<td class="text-end">
@if (item.Value.status == Core.Enum.fileStatus.rem || item.Value.status == Core.Enum.fileStatus.mod)
{
@item.Key
}
</td>
</tr>
}
</div>
<div class="col-5 border border-dark" style="min-height: 40rem;">
</div>
</div>
</tbody>
</table>
@@ -1,51 +1,87 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using System.Net.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Web.Virtualization;
using Microsoft.JSInterop;
using EgwCoreLib.Razor;
using EgwCoreLib.Utils;
using WebDoorCreator.Data;
using WebDoorCreator.Data.DbModels;
using WebDoorCreator.UI;
using WebDoorCreator.UI.Components;
using WebDoorCreator.UI.Components.Buttons;
using WebDoorCreator.UI.Components.CompMan;
using WebDoorCreator.UI.Components.DoorMan;
using WebDoorCreator.UI.Components.DoorDef;
using WebDoorCreator.UI.Components.Gen;
using WebDoorCreator.UI.Components.Order;
using WebDoorCreator.UI.Components.Users;
using WebDoorCreator.UI.Components.Hardware;
using WebDoorCreator.UI.Components.SvgComp;
using WebDoorCreator.UI.Components.Filters;
using WebDoorCreator.UI.Components.Report;
using WebDoorCreator.UI.Components.FilesMan;
using WebDoorCreator.UI.Components.TemplateMan;
using WebDoorCreator.UI.Shared;
using WebDoorCreator.Data.DTO;
using WebDoorCreator.Data.Services;
namespace WebDoorCreator.UI.Components.FilesMan
{
public partial class CompoCompare
{
protected List<DoorOpTypeModel> tempDOT = new List<DoorOpTypeModel>();
private Dictionary<string, FileDTO> files2Chk = new Dictionary<string, FileDTO>();
[Inject]
protected IConfiguration configuration { get; set; } = null!;
[Inject]
protected WebDoorCreatorService WDCService { get; set; } = null!;
protected List<DoorOpTypeModel> tempDOT = new List<DoorOpTypeModel>();
protected async Task scanB()
private string rootPathNew
{
tempDOT.Clear();
await WDCService.populateHws();
tempDOT = await WDCService.scanAndCompare();
get => configuration.GetValue<string>("CompoBaseDirs:NewCompoDir");
}
private string rootPathOld
{
get => configuration.GetValue<string>("CompoBaseDirs:CurrCompoDir");
}
protected string btnCssClass(Core.Enum.fileStatus fStat, bool doAct)
{
string answ = "";
if (fStat == Core.Enum.fileStatus.add && doAct)
{
answ = "btn-success";
}
else if (fStat == Core.Enum.fileStatus.mod && doAct)
{
answ = "btn-warning";
}
else if (fStat == Core.Enum.fileStatus.rem && doAct)
{
answ = "btn-danger";
}
else
{
answ = "btn-secondary";
}
return answ;
}
protected string btnIcon(Core.Enum.fileStatus fStat)
{
string answ = "";
if (fStat == Core.Enum.fileStatus.add)
{
answ = "fa-solid fa-circle-arrow-right";
}
else if (fStat == Core.Enum.fileStatus.mod)
{
answ = "fa-solid fa-code-pull-request";
}
else if (fStat == Core.Enum.fileStatus.rem)
{
answ = "fa-solid fa-square-minus";
}
return answ;
}
protected async Task selectAll()
{
await Task.Delay(1);
foreach(var item in files2Chk)
{
item.Value.action = true;
}
}
protected async Task unselectAll()
{
await Task.Delay(1);
foreach (var item in files2Chk)
{
item.Value.action = false;
}
}
protected async Task save()
@@ -53,5 +89,46 @@ namespace WebDoorCreator.UI.Components.FilesMan
await WDCService.DoorOpTypeAddRange(tempDOT);
}
protected async Task scanB()
{
files2Chk = new Dictionary<string, FileDTO>();
tempDOT.Clear();
await WDCService.populateHws();
var oldFiles = await WDCService.scanSrcDestDir(rootPathOld);
var newFiles = await WDCService.scanSrcDestDir(rootPathNew);
//tempDOT = await WDCService.scanAndCompare();
foreach (var item in newFiles)
{
if (oldFiles.ContainsKey(item.Key))
{
if (oldFiles[item.Key].FileMD5 != item.Value.FileMD5)
{
item.Value.status = Core.Enum.fileStatus.mod;
}
oldFiles.Remove(item.Key);
//files2Chk.Add(item.Key, item.Value);
}
else
{
item.Value.status = Core.Enum.fileStatus.add;
}
files2Chk.Add(item.Key, item.Value);
}
foreach (var item in oldFiles)
{
item.Value.status = Core.Enum.fileStatus.rem;
files2Chk.Add(item.Key, item.Value);
}
files2Chk = files2Chk.Where(x => x.Value.status > 0).ToDictionary(x => x.Key, x => x.Value);
}
protected async Task changeDoAct(KeyValuePair<string, FileDTO> currObj)
{
await Task.Delay(1);
files2Chk[currObj.Key].action = !files2Chk[currObj.Key].action;
}
}
}
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -144,7 +144,7 @@
protected async Task scanB()
{
tempDOT.Clear();
tempDOT = await WDCService.scanAndCompare();
//tempDOT = await WDCService.scanAndCompare();
}
protected async Task save()
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<Version>0.9.2308.2917</Version>
<Version>0.9.2308.3017</Version>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-WebDoorCreator.UI-dfe95fed-1398-4144-bd43-8b3a765d6608</UserSecretsId>
</PropertyGroup>