264 lines
7.7 KiB
C#
264 lines
7.7 KiB
C#
using EgwCoreLib.Razor;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Forms;
|
|
using NLog;
|
|
using SMGen.Core;
|
|
using SMGen.Data;
|
|
using SMGen.Data.Data;
|
|
using SMGen.Data.Services;
|
|
|
|
namespace SMGen.Pages
|
|
{
|
|
public partial class SMEvent2State
|
|
{
|
|
#region Protected Fields
|
|
|
|
protected static Logger Log = LogManager.GetCurrentClassLogger();
|
|
protected bool _OrderByEvNxSt = false;
|
|
protected bool _OrderByEvSt = false;
|
|
protected bool _OrderByStEv = true;
|
|
protected SelectSMIn2EvParams currFilter = new SelectSMIn2EvParams();
|
|
|
|
protected DataPager? pagerSMIn2Ev = null!;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected bool CalcEmptyState { get; set; } = true;
|
|
|
|
protected bool CalcItself { get; set; } = false;
|
|
|
|
[Inject]
|
|
protected IConfiguration conf { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IWebHostEnvironment env { get; set; } = null!;
|
|
|
|
protected Dictionary<string, FilesClass> Files { get; set; } = new Dictionary<string, FilesClass>();
|
|
protected int maxAllowedFiles { get; set; } = 100;
|
|
|
|
protected bool OrderByEvNxSt
|
|
{
|
|
get => _OrderByEvNxSt;
|
|
set
|
|
{
|
|
_OrderByEvNxSt = value;
|
|
if (value)
|
|
{
|
|
OrderType = Core.Enum.ORDERTYPE.eventNextState;
|
|
OrderByStEv = false;
|
|
OrderByEvSt = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected bool OrderByEvSt
|
|
{
|
|
get => _OrderByEvSt;
|
|
set
|
|
{
|
|
_OrderByEvSt = value;
|
|
if (value)
|
|
{
|
|
OrderType = Core.Enum.ORDERTYPE.eventState;
|
|
OrderByEvNxSt = false;
|
|
OrderByStEv = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected bool OrderByStEv
|
|
{
|
|
get => _OrderByStEv;
|
|
set
|
|
{
|
|
_OrderByStEv = value;
|
|
if (value)
|
|
{
|
|
OrderType = Core.Enum.ORDERTYPE.stateEvent;
|
|
OrderByEvNxSt = false;
|
|
OrderByEvSt = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected Core.Enum.ORDERTYPE OrderType { get; set; } = Core.Enum.ORDERTYPE.stateEvent;
|
|
protected string pathDir { get; set; } = "";
|
|
|
|
protected string pathFile { get; set; } = "";
|
|
protected int resetSucc { get; set; } = 0;
|
|
|
|
[Inject]
|
|
protected SMGDataService SMGDService { get; set; } = null!;
|
|
|
|
protected string statiCsvPath
|
|
{
|
|
get => conf.GetValue<string>("ServerConf:StatiCsvPath");
|
|
}
|
|
|
|
#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
|
|
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);
|
|
}
|
|
|
|
protected async Task pgResetReq(bool doReset)
|
|
{
|
|
if (doReset)
|
|
{
|
|
await Task.Delay(1);
|
|
if (pagerSMIn2Ev != null)
|
|
{
|
|
pagerSMIn2Ev.resetCurrPage();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected async Task updateFilter(SelectSMIn2EvParams newParams)
|
|
{
|
|
await Task.Delay(1);
|
|
currPage = 1;
|
|
// salvo comunque filtro reparto x utente
|
|
await Task.Delay(1);
|
|
await InvokeAsync(() => StateHasChanged());
|
|
currFilter = newParams;
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
|
|
//// va dopo
|
|
//private StreamWriter objWriter { get; set; };
|
|
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
|
|
{
|
|
loadedFiles.Add(file);
|
|
|
|
//assegno un nome file randomico x sicurezza
|
|
var trustedFileNameForFileStorage = Path.GetRandomFileName();
|
|
|
|
//path del file da scrivere
|
|
pathFile = Path.Combine(pathDir, trustedFileNameForFileStorage);
|
|
|
|
// creo file
|
|
using (FileStream fs = new(pathFile, FileMode.Create))
|
|
{
|
|
// copio il contenuto del file
|
|
await file.OpenReadStream(maxFileSize).CopyToAsync(fs);
|
|
// scrivo log
|
|
Log.Info($"Salvato file temp {pathFile}");
|
|
}
|
|
|
|
if (file.Name.Contains(".rul"))
|
|
{
|
|
var newFIle = new FilesClass()
|
|
{
|
|
tempFileName = pathFile,
|
|
isOk = false,
|
|
origFileName = file.Name,
|
|
calcRunning = false,
|
|
DLoadFileName = ""
|
|
};
|
|
|
|
Files.Add(file.Name, newFIle);
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore durante salvataggio file temp {file.Name}: {exc}{Environment.NewLine}");
|
|
}
|
|
}
|
|
if (Files != null && Files.Count > 0)
|
|
{
|
|
await SMGDService.FilesLoadRedis(Files);
|
|
}
|
|
resetSucc = 0;
|
|
await InvokeAsync(() => StateHasChanged());
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |