Riorganizzazione cleanup directory
This commit is contained in:
@@ -755,9 +755,8 @@ namespace SMGen.Data.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Log.Debug($"F{n++:00}");
|
||||
await FileUpdate(file.origFileName, file);
|
||||
Log.Debug($"F{n++:00}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+113
-78
@@ -1,9 +1,7 @@
|
||||
using EgwCoreLib.Razor;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
using Microsoft.VisualBasic;
|
||||
using NLog.Fluent;
|
||||
using SMGen.Core;
|
||||
using NLog;
|
||||
using SMGen.Data;
|
||||
using SMGen.Data.Data;
|
||||
using SMGen.Data.Services;
|
||||
@@ -12,26 +10,47 @@ namespace SMGen.Pages
|
||||
{
|
||||
public partial class FilesFix
|
||||
{
|
||||
#region Protected Fields
|
||||
|
||||
protected static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
protected SelectSMIn2EvParams currFilter = new SelectSMIn2EvParams();
|
||||
protected Dictionary<int, string> eventsFromDb = new Dictionary<int, string>();
|
||||
protected DataPager? pagerRulFix = null!;
|
||||
protected Dictionary<int, string> statesFromDb = new Dictionary<int, string>();
|
||||
|
||||
[Inject]
|
||||
protected SMGDataService SMGDService { get; set; } = null!;
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
protected Dictionary<string, FilesClass> Files { get; set; } = new Dictionary<string, FilesClass>();
|
||||
|
||||
protected int maxAllowedFiles { get; set; } = 100;
|
||||
|
||||
protected string pathDir { get; set; } = "";
|
||||
|
||||
protected string pathFile { get; set; } = "";
|
||||
|
||||
protected int resetSucc { get; set; } = 0;
|
||||
|
||||
private async Task LoadFiles(InputFileChangeEventArgs e)
|
||||
{
|
||||
List<IBrowserFile> loadedFiles = new();
|
||||
long maxFileSize = 1024 * 1024;
|
||||
loadedFiles.Clear();
|
||||
Files.Clear();
|
||||
[Inject]
|
||||
protected SMGDataService SMGDService { get; set; } = null!;
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected void ForceReload(int newNum)
|
||||
{
|
||||
numRecord = newNum;
|
||||
}
|
||||
|
||||
protected void ForceReloadPage(int newNum)
|
||||
{
|
||||
currPage = newNum;
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
// path cartella root (development)
|
||||
pathDir = Path.Combine("Temp", "unsafe_uploads");
|
||||
// se la cartella non esistesse la creo
|
||||
@@ -41,6 +60,88 @@ namespace SMGen.Pages
|
||||
Log.Info($"Creato directory {pathDir}");
|
||||
}
|
||||
|
||||
// svuoto cartella prima di partire
|
||||
deleteOldFiles(pathDir);
|
||||
await Task.Delay(1);
|
||||
await SMGDService.ExecFlushRedisPattern(Core.Constants.FILES_TO_PROC);
|
||||
}
|
||||
|
||||
protected async Task pgResetReq(bool doReset)
|
||||
{
|
||||
if (doReset)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
if (pagerRulFix != null)
|
||||
{
|
||||
pagerRulFix.resetCurrPage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task ReloadData()
|
||||
{
|
||||
Files = await SMGDService.FilesGetAll();
|
||||
}
|
||||
|
||||
protected void UpdateTotCount(int newTotCount)
|
||||
{
|
||||
totalCount = newTotCount;
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private int currPage
|
||||
{
|
||||
get => currFilter.CurrPage;
|
||||
set => currFilter.CurrPage = value;
|
||||
}
|
||||
|
||||
private int numRecord
|
||||
{
|
||||
get => currFilter.NumRec;
|
||||
set => currFilter.NumRec = value;
|
||||
}
|
||||
|
||||
private int totalCount
|
||||
{
|
||||
get => currFilter.TotCount;
|
||||
set => currFilter.TotCount = value;
|
||||
}
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Procedee a bonificare la cartella di upload dei files + vecchi di 3 mesi
|
||||
/// </summary>
|
||||
private void deleteOldFiles(string dirPath)
|
||||
{
|
||||
// elenco files nella directory
|
||||
string[] files = Directory.GetFiles(dirPath);
|
||||
// li guardo tutti e se vecchi li elimino...
|
||||
foreach (string file in files)
|
||||
{
|
||||
FileInfo fi = new FileInfo(file);
|
||||
if (fi.LastAccessTime < DateTime.Now.AddMinutes(-10))
|
||||
{
|
||||
fi.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadFiles(InputFileChangeEventArgs e)
|
||||
{
|
||||
List<IBrowserFile> loadedFiles = new();
|
||||
long maxFileSize = 1024 * 1024;
|
||||
loadedFiles.Clear();
|
||||
Files.Clear();
|
||||
|
||||
// svuoto cartella prima di partire
|
||||
deleteOldFiles(pathDir);
|
||||
|
||||
foreach (var file in e.GetMultipleFiles(maxAllowedFiles))
|
||||
{
|
||||
try
|
||||
@@ -90,72 +191,6 @@ namespace SMGen.Pages
|
||||
await ReloadData();
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
await SMGDService.ExecFlushRedisPattern(Core.Constants.FILES_TO_PROC);
|
||||
}
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected void ForceReload(int newNum)
|
||||
{
|
||||
numRecord = newNum;
|
||||
}
|
||||
|
||||
protected void ForceReloadPage(int newNum)
|
||||
{
|
||||
currPage = newNum;
|
||||
}
|
||||
|
||||
protected SelectSMIn2EvParams currFilter = new SelectSMIn2EvParams();
|
||||
|
||||
protected DataPager? pagerRulFix = null!;
|
||||
|
||||
protected async Task pgResetReq(bool doReset)
|
||||
{
|
||||
if (doReset)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
if (pagerRulFix != null)
|
||||
{
|
||||
pagerRulFix.resetCurrPage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void UpdateTotCount(int newTotCount)
|
||||
{
|
||||
totalCount = newTotCount;
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private int currPage
|
||||
{
|
||||
get => currFilter.CurrPage;
|
||||
set => currFilter.CurrPage = value;
|
||||
}
|
||||
|
||||
private int numRecord
|
||||
{
|
||||
get => currFilter.NumRec;
|
||||
set => currFilter.NumRec = value;
|
||||
}
|
||||
|
||||
private int totalCount
|
||||
{
|
||||
get => currFilter.TotCount;
|
||||
set => currFilter.TotCount = value;
|
||||
}
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
protected async Task ReloadData()
|
||||
{
|
||||
Files = await SMGDService.FilesGetAll();
|
||||
}
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
@@ -113,6 +113,17 @@ namespace SMGen.Pages
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
// path cartella root (development)
|
||||
pathDir = Path.Combine("Temp", "unsafe_uploads");
|
||||
//se la cartella non esistesse la creo
|
||||
if (!Directory.Exists(pathDir))
|
||||
{
|
||||
Directory.CreateDirectory(pathDir);
|
||||
Log.Info($"Creato directory {pathDir}");
|
||||
}
|
||||
// svuoto cartella prima di partire
|
||||
deleteOldFiles(pathDir);
|
||||
|
||||
await Task.Delay(1);
|
||||
await SMGDService.ExecFlushRedisPattern(Constants.FILES_TO_PROC);
|
||||
}
|
||||
@@ -197,14 +208,6 @@ namespace SMGen.Pages
|
||||
loadedFiles.Clear();
|
||||
Files.Clear();
|
||||
|
||||
// path cartella root (development)
|
||||
pathDir = Path.Combine("Temp", "unsafe_uploads");
|
||||
//se la cartella non esistesse la creo
|
||||
if (!Directory.Exists(pathDir))
|
||||
{
|
||||
Directory.CreateDirectory(pathDir);
|
||||
Log.Info($"Creato directory {pathDir}");
|
||||
}
|
||||
// svuoto cartella prima di partire
|
||||
deleteOldFiles(pathDir);
|
||||
|
||||
|
||||
@@ -77,6 +77,17 @@ namespace SMGen.Pages
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
// path cartella root (development)
|
||||
pathDir = Path.Combine("Temp", "unsafe_uploads");
|
||||
//se la cartella non esistesse la creo
|
||||
if (!Directory.Exists(pathDir))
|
||||
{
|
||||
Directory.CreateDirectory(pathDir);
|
||||
Log.Info($"Creato directory {pathDir}");
|
||||
}
|
||||
// svuoto cartella prima di partire
|
||||
deleteOldFiles(pathDir);
|
||||
|
||||
await Task.Delay(1);
|
||||
await SMGDService.ExecFlushRedisPattern(Constants.FILES_TO_PROC);
|
||||
}
|
||||
@@ -151,14 +162,6 @@ namespace SMGen.Pages
|
||||
loadedFiles.Clear();
|
||||
Files.Clear();
|
||||
|
||||
// path cartella root (development)
|
||||
pathDir = Path.Combine("Temp", "unsafe_uploads");
|
||||
// se la cartella non esistesse la creo
|
||||
if (!Directory.Exists(pathDir))
|
||||
{
|
||||
Directory.CreateDirectory(pathDir);
|
||||
Log.Info($"Creato directory {pathDir}");
|
||||
}
|
||||
// svuoto cartella prima di partire
|
||||
deleteOldFiles(pathDir);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user