Prima versione caricamento dati NUOVI da filesystem
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -98,31 +99,79 @@ namespace MP.FileData.Controllers
|
||||
{
|
||||
maxNum = maxNum <= 0 ? 100 : maxNum;
|
||||
List<DatabaseModels.ArticoloModel> dbResult = new List<DatabaseModels.ArticoloModel>();
|
||||
|
||||
int totRecord = dbCtx
|
||||
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 = dbCtx
|
||||
.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 ..." });
|
||||
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();
|
||||
}
|
||||
}
|
||||
else
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua la comparazione tra i file in archivio ed i file attuali e segna info LastCheck e Changed (se cambiati)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool CheckFileArchived(string idxMacchina, string path, string searchPattern)
|
||||
{
|
||||
bool answ = false;
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(path);
|
||||
FileInfo[] fileList = dirInfo.GetFiles("*.*");
|
||||
List<FileInfo> fileNew = new List<FileInfo>();
|
||||
List<FileInfo> fileMod = new List<FileInfo>();
|
||||
|
||||
// recupera elenco file nel DB
|
||||
var archivedFile = FileGetByPath(path, true);
|
||||
|
||||
// verifica i file
|
||||
foreach (var file in fileList)
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetArticoli
|
||||
.Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal))
|
||||
.OrderBy(x => x.DescArticolo)
|
||||
.ToList();
|
||||
// cerca nel DB...
|
||||
var currRecord = archivedFile
|
||||
.Where(x => x.Path == file.FullName)
|
||||
.FirstOrDefault();
|
||||
// se NON trova lo crea
|
||||
if (currRecord == null)
|
||||
{
|
||||
fileNew.Add(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
fileMod.Add(file);
|
||||
}
|
||||
}
|
||||
|
||||
return dbResult;
|
||||
// salvo i NUOVI file
|
||||
if (fileNew != null && fileNew.Count > 0)
|
||||
{
|
||||
FileInsert(idxMacchina, fileNew);
|
||||
}
|
||||
// aggiorno i file modificati
|
||||
if (fileMod != null && fileMod.Count > 0)
|
||||
{
|
||||
FileUpdate(idxMacchina, fileMod);
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -131,19 +180,116 @@ namespace MP.FileData.Controllers
|
||||
dbCtx.Dispose();
|
||||
}
|
||||
|
||||
public List<DatabaseModels.FileModel> FileGetByPath(string path, bool onlyActive)
|
||||
{
|
||||
List<DatabaseModels.FileModel> dbResult = new List<DatabaseModels.FileModel>();
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
.DbSetProgFile
|
||||
.Where(x => x.Path.StartsWith(path) && ((onlyActive && x.Active) || !onlyActive))
|
||||
.OrderBy(x => x.Name)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public List<DatabaseModels.FileModel> FileGetFilt(string IdxMacchina, string CodArticolo, string SearchVal = "")
|
||||
{
|
||||
List<DatabaseModels.FileModel> dbResult = new List<DatabaseModels.FileModel>();
|
||||
|
||||
dbResult = dbCtx
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
.DbSetProgFile
|
||||
.Where(x => ((x.IdxMacchina == IdxMacchina || IdxMacchina == "0") || (x.CodArticolo == CodArticolo || CodArticolo == "ND")) && (x.Name.Contains(SearchVal) || string.IsNullOrEmpty(SearchVal)))
|
||||
.Where(x => ((x.IdxMacchina == IdxMacchina || IdxMacchina == "0") || (x.CodArticolo == CodArticolo || CodArticolo == "ND" || CodArticolo == "")) && (x.Name.Contains(SearchVal) || string.IsNullOrEmpty(SearchVal)))
|
||||
.OrderBy(x => x.Name)
|
||||
.ToList();
|
||||
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// effettua inserimento di un record in archivio come NUOVO documento tracciato
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="newFiles"></param>
|
||||
/// <returns></returns>
|
||||
public bool FileInsert(string idxMacchina, List<FileInfo> newFiles)
|
||||
{
|
||||
bool answ = false;
|
||||
DateTime adesso = DateTime.Now;
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
// converto
|
||||
List<DatabaseModels.FileModel> newRec = newFiles.Select(o => new DatabaseModels.FileModel()
|
||||
{
|
||||
Active = true,
|
||||
CodArticolo = "ND",
|
||||
Changed = false,
|
||||
IdxMacchina = idxMacchina,
|
||||
LastCheck = adesso,
|
||||
LastMod = o.LastWriteTime,
|
||||
MimeType = o.Extension,
|
||||
Name = o.Name,
|
||||
Path = o.FullName,
|
||||
Rev = 0,
|
||||
Size = o.Length,
|
||||
FileContent = File.ReadAllBytes(o.FullName)
|
||||
}).ToList();
|
||||
|
||||
// aggiungo in blocco
|
||||
localDbCtx
|
||||
.DbSetProgFile
|
||||
.AddRange(newRec);
|
||||
|
||||
// salvo
|
||||
localDbCtx.SaveChanges();
|
||||
answ = true;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// effettua inserimento di un record in archivio come NUOVO documento tracciato
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="updFiles"></param>
|
||||
/// <returns></returns>
|
||||
public bool FileUpdate(string idxMacchina, List<FileInfo> updFiles)
|
||||
{
|
||||
bool answ = false;
|
||||
DateTime adesso = DateTime.Now;
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
// converto
|
||||
List<DatabaseModels.FileModel> newRec = updFiles.Select(o => new DatabaseModels.FileModel()
|
||||
{
|
||||
Active = true,
|
||||
CodArticolo = "ND",
|
||||
Changed = false,
|
||||
IdxMacchina = idxMacchina,
|
||||
LastCheck = adesso,
|
||||
LastMod = o.LastWriteTime,
|
||||
MimeType = o.Extension,
|
||||
Name = o.Name,
|
||||
Path = o.FullName,
|
||||
Rev = 0,
|
||||
Size = o.Length,
|
||||
FileContent = File.ReadAllBytes(o.FullName)
|
||||
}).ToList();
|
||||
|
||||
// aggiungo in blocco
|
||||
localDbCtx
|
||||
.DbSetProgFile
|
||||
.UpdateRange(newRec);
|
||||
|
||||
// salvo
|
||||
localDbCtx.SaveChanges();
|
||||
answ = true;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco tabella Macchine
|
||||
/// </summary>
|
||||
@@ -151,12 +297,13 @@ namespace MP.FileData.Controllers
|
||||
public List<DatabaseModels.MacchinaModel> MacchineGetAll()
|
||||
{
|
||||
List<DatabaseModels.MacchinaModel> dbResult = new List<DatabaseModels.MacchinaModel>();
|
||||
|
||||
dbResult = dbCtx
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
.DbSetMacchine
|
||||
.OrderBy(x => x.IdxMacchina)
|
||||
.ToList();
|
||||
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace MP.FileData.DatabaseModels
|
||||
public string Name { get; set; } = "";
|
||||
public int Rev { get; set; } = 0;
|
||||
public DateTime LastMod { get; set; }
|
||||
public int Size { get; set; } = 0;
|
||||
public long Size { get; set; } = 0;
|
||||
public string Path { get; set; } = "";
|
||||
public string MimeType { get; set; } = "";
|
||||
public bool Changed { get; set; } = false;
|
||||
|
||||
@@ -8,8 +8,25 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MP.FileData
|
||||
{
|
||||
public class FileUtils
|
||||
public class FileUtils
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Elenco dei file data la directory da controllare
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="searchPattern"></param>
|
||||
/// <returns></returns>
|
||||
public static FileInfo[] GetFileList(string path, string searchPattern)
|
||||
{
|
||||
//string[] answ = Directory.GetFiles(path, searchPattern);
|
||||
DriveInfo di = new DriveInfo(path);
|
||||
DirectoryInfo dirInfo = di.RootDirectory;
|
||||
FileInfo[] answ = dirInfo.GetFiles("*.*");
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
public static async Task SaveToCsv<T>(List<T> reportData, string path)
|
||||
{
|
||||
@@ -21,5 +38,7 @@ namespace MP.FileData
|
||||
lines.AddRange(valueLines);
|
||||
await Task.Run(() => File.WriteAllLines(path, lines.ToArray()));
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -219,6 +219,24 @@ namespace MP.Prog.Data
|
||||
dbController.RollBackEntity(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna intero archivio scansionando dati x tutte le macchine che hanno un path valido
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task updateAllArchive()
|
||||
{
|
||||
try
|
||||
{
|
||||
var listaMacchine = await MacchineGetAll();
|
||||
foreach (var item in listaMacchine.Where(x => !string.IsNullOrEmpty(x.BasePath)).ToList())
|
||||
{
|
||||
dbController.CheckFileArchived(item.IdxMacchina, item.BasePath, "*.*");
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#if false
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
<span class="fas fa-search" aria-hidden="true"></span>
|
||||
</span>
|
||||
</div>
|
||||
<input type="text" class="form-control form-control-sm" placeholder="Ricerca Articolo" @bind-value="@SearchArt" />
|
||||
<input type="text" class="form-control form-control-sm" placeholder="Ricerca Articolo" @bind-value="@SearchArt" width="4em" />
|
||||
<select @bind="@SelCodArt" class="form-control form-control-sm">
|
||||
@if (ArtList != null)
|
||||
{
|
||||
|
||||
@@ -190,11 +190,13 @@ namespace MP.Prog.Pages
|
||||
|
||||
protected async Task ForceCheck()
|
||||
{
|
||||
// !!!FARE
|
||||
isLoading = true;
|
||||
await DataService.updateAllArchive();
|
||||
currRecord = null;
|
||||
SearchRecords = null;
|
||||
ListRecords = null;
|
||||
AppMService.File_Filter = SelectData.Init(5, 10);
|
||||
isLoading = false;
|
||||
await ReloadAllData();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user