112 lines
3.6 KiB
C#
112 lines
3.6 KiB
C#
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 SMGen;
|
|
using SMGen.Shared;
|
|
using SMGen.Components;
|
|
using EgwCoreLib.Razor;
|
|
using EgwCoreLib.Razor.Data;
|
|
using SMGen.Data;
|
|
using SMGen.Core;
|
|
using NLog.Fluent;
|
|
using SMGen.Data.Data;
|
|
using SMGen.Data.Services;
|
|
|
|
namespace SMGen.Pages
|
|
{
|
|
public partial class CheckUnused
|
|
{
|
|
[Inject]
|
|
protected IConfiguration conf { get; set; } = null!;
|
|
[Inject]
|
|
protected SMGDataService SMGDService { get; set; } = null!;
|
|
|
|
protected string pathDir { get; set; } = "";
|
|
|
|
protected string pathFile { get; set; } = "";
|
|
|
|
protected Dictionary<string, FilesClass> Files { get; set; } = new Dictionary<string, FilesClass>();
|
|
|
|
protected FileLinesClass k = new FileLinesClass();
|
|
|
|
protected async Task doProc()
|
|
{
|
|
await Task.Delay(1);
|
|
foreach(var item in Files)
|
|
{
|
|
k = await SMGDService.DoCheckUnusedEvSt(item.Value);
|
|
}
|
|
}
|
|
|
|
private async Task LoadFiles(InputFileChangeEventArgs e)
|
|
{
|
|
List<IBrowserFile> loadedFiles = new();
|
|
long maxFileSize = 1024 * 1024;
|
|
loadedFiles.Clear();
|
|
Files.Clear();
|
|
|
|
foreach (var file in e.GetMultipleFiles())
|
|
{
|
|
try
|
|
{
|
|
loadedFiles.Add(file);
|
|
|
|
//assegno un nome file randomico x sicurezza
|
|
var trustedFileNameForFileStorage = Path.GetRandomFileName();
|
|
|
|
//path del file da scrivere
|
|
pathFile = Path.Combine("Temp", "unsafe_uploads",
|
|
trustedFileNameForFileStorage);
|
|
|
|
//path cartella root (development)
|
|
pathDir = Path.Combine("Temp", "unsafe_uploads");
|
|
|
|
//se la cartella non esiste, creo
|
|
if (!Directory.Exists(pathDir))
|
|
{
|
|
Directory.CreateDirectory(pathDir);
|
|
Log.Info($"Creato directory {pathDir}");
|
|
}
|
|
|
|
// 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}");
|
|
}
|
|
}
|
|
await InvokeAsync(() => StateHasChanged());
|
|
}
|
|
}
|
|
} |