ok download file richiesti
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<div class="p-2">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Rul file</th>
|
||||
<th scope="col">Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in FilesStatus)
|
||||
{
|
||||
<tr>
|
||||
<td scope="row">@item.Key</td>
|
||||
@if (item.Value)
|
||||
{
|
||||
<td class="text-success"><i class="fa-solid fa-circle-check"></i></td>
|
||||
<td>
|
||||
<a target ="_blank" href="Download?fileName=@Files2Download[item.Key]" class="btn btn-block btn-sm btn-success">
|
||||
<span class ="oi oi-cloud-download">
|
||||
</span> Download Data</a>
|
||||
@Files2Download[item.Key]
|
||||
</td>
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
<td class="text-danger"><i class="fa-solid fa-circle-xmark"></i></td>
|
||||
}
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -0,0 +1,27 @@
|
||||
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;
|
||||
|
||||
namespace SMGen.Components
|
||||
{
|
||||
public partial class FilesList
|
||||
{
|
||||
[Parameter]
|
||||
public Dictionary<string, bool> FilesStatus { get; set; } = new Dictionary<string, bool>();
|
||||
[Parameter]
|
||||
public Dictionary<string, string> Files2Download { get; set; } = new Dictionary<string, string>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
@page "/Download"
|
||||
|
||||
@model SMGen.Pages.DownloadModel
|
||||
@{
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace SMGen.Pages
|
||||
{
|
||||
/// <summary>
|
||||
/// Gestione donwnload file csv
|
||||
///
|
||||
/// da valutare eventualmente xlsx con https://github.com/closedxml/closedxml
|
||||
/// </summary>
|
||||
public class DownloadModel : PageModel
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private readonly IWebHostEnvironment _env;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public DownloadModel(IWebHostEnvironment env)
|
||||
{
|
||||
_env = env;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public IActionResult OnGet()
|
||||
{
|
||||
string fileName = "";
|
||||
if (Request.Query.ContainsKey("fileName"))
|
||||
{
|
||||
fileName = Request.Query["fileName"];
|
||||
}
|
||||
var filePath = Path.Combine(_env.ContentRootPath, fileName);
|
||||
//var filePath = Path.Combine(_env.WebRootPath, "..\\temp\\", fileName);
|
||||
|
||||
byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
|
||||
|
||||
return File(fileBytes, "application/force-download", fileName.Split("\\").Last());
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -26,12 +26,4 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="p-2">
|
||||
@foreach (var item in files2Read)
|
||||
{
|
||||
<span>@item.Key</span>
|
||||
<br />
|
||||
}
|
||||
</div>
|
||||
|
||||
<FilesList FilesStatus="@filesStatus" Files2Download="@files2Download"></FilesList>
|
||||
|
||||
@@ -42,6 +42,8 @@ namespace SMGen.Pages
|
||||
protected string sz_file2Read { get; set; } = "";
|
||||
protected string sz_state_machine_name { get; set; } = "";
|
||||
protected string n_state_machine_index { get; set; } = "";
|
||||
protected string pathFile{ get; set; } = "";
|
||||
protected string pathDir{ get; set; } = "";
|
||||
protected int n_states { get; set; } = 0;
|
||||
protected int n_bits { get; set; } = 0;
|
||||
protected bool b_rules_definition { get; set; } = false;
|
||||
@@ -53,6 +55,8 @@ namespace SMGen.Pages
|
||||
protected List<RuleClass> Rules { get; set; } = new List<RuleClass>();
|
||||
|
||||
protected Dictionary<string, string> files2Read { get; set; } = new Dictionary<string, string>();
|
||||
protected Dictionary<string, bool> filesStatus { get; set; } = new Dictionary<string, bool>();
|
||||
protected Dictionary<string, string> files2Download { get; set; } = new Dictionary<string, string>();
|
||||
//// va dopo
|
||||
//private StreamWriter objWriter { get; set; };
|
||||
private async Task LoadFiles(InputFileChangeEventArgs e)
|
||||
@@ -61,6 +65,8 @@ namespace SMGen.Pages
|
||||
long maxFileSize = 1024 * 15;
|
||||
int maxAllowedFiles = 150;
|
||||
loadedFiles.Clear();
|
||||
filesStatus.Clear();
|
||||
files2Read.Clear();
|
||||
|
||||
foreach (var file in e.GetMultipleFiles(maxAllowedFiles))
|
||||
{
|
||||
@@ -72,12 +78,12 @@ namespace SMGen.Pages
|
||||
var trustedFileNameForFileStorage = Path.GetRandomFileName();
|
||||
|
||||
//path del file da scrivere
|
||||
var pathFile = Path.Combine(env.ContentRootPath,
|
||||
pathFile = Path.Combine(env.ContentRootPath,
|
||||
env.EnvironmentName, "unsafe_uploads",
|
||||
trustedFileNameForFileStorage);
|
||||
|
||||
//path cartella root (development)
|
||||
var pathDir = Path.Combine(env.ContentRootPath,
|
||||
pathDir = Path.Combine(env.ContentRootPath,
|
||||
env.EnvironmentName, "unsafe_uploads");
|
||||
|
||||
//se la cartella non esiste, creo
|
||||
@@ -87,7 +93,7 @@ namespace SMGen.Pages
|
||||
}
|
||||
else
|
||||
{
|
||||
//deleteOldFiles(pathDir);
|
||||
|
||||
}
|
||||
|
||||
//creo file
|
||||
@@ -98,6 +104,7 @@ namespace SMGen.Pages
|
||||
if (file.Name.Contains(".rul"))
|
||||
{
|
||||
files2Read.Add(file.Name, pathFile);
|
||||
filesStatus.Add(file.Name, false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -188,7 +195,7 @@ namespace SMGen.Pages
|
||||
var isOk = checkDirExist(procRootDir);
|
||||
if (isOk)
|
||||
{
|
||||
evaluate_transitions($"{procRootDir}\\{item.Key.Split(".")[0]}.csv");
|
||||
evaluate_transitions($"{procRootDir}\\{item.Key.Split(".")[0]}.csv", item.Key);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -213,6 +220,7 @@ namespace SMGen.Pages
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected bool checkDirExist(string dir)
|
||||
@@ -239,7 +247,7 @@ namespace SMGen.Pages
|
||||
return answ;
|
||||
}
|
||||
|
||||
protected void evaluate_transitions(string sz_file2Write)
|
||||
protected void evaluate_transitions(string sz_file2Write, string origFileName)
|
||||
{
|
||||
using (StreamWriter sw = new StreamWriter(sz_file2Write))
|
||||
{
|
||||
@@ -256,80 +264,95 @@ namespace SMGen.Pages
|
||||
bool[] b_bit = new bool[20];
|
||||
bool b_invert = false;
|
||||
//ciclo negli stati
|
||||
for (var i = 0; i <= n_states - 1; i++)
|
||||
try
|
||||
{
|
||||
sz_actual_state = States.ToArray()[i];
|
||||
|
||||
//ciclo negli ingressi
|
||||
for (n_input = 0; n_input <= (Math.Pow(2, n_bits) - 1); n_input++)
|
||||
for (var i = 0; i <= n_states - 1; i++)
|
||||
{
|
||||
n_mask = 1;
|
||||
for (var n = 0; n <= n_bits - 1; n++)
|
||||
{
|
||||
b_bit[n] = Convert.ToBoolean(n_input & n_mask);
|
||||
n_mask = n_mask << 1;
|
||||
}
|
||||
sz_actual_state = States.ToArray()[i];
|
||||
|
||||
var exitFor = false;
|
||||
|
||||
foreach (var act_rule in Rules)
|
||||
//ciclo negli ingressi
|
||||
for (n_input = 0; n_input <= (Math.Pow(2, n_bits) - 1); n_input++)
|
||||
{
|
||||
n_bit = -1;
|
||||
if ((act_rule.state == "ALL_STATES") || (act_rule.state == sz_actual_state))
|
||||
n_mask = 1;
|
||||
for (var n = 0; n <= n_bits - 1; n++)
|
||||
{
|
||||
//DA RESETTARE A FALSE (errore da principianti...)
|
||||
b_invert = false;
|
||||
b_bit[n] = Convert.ToBoolean(n_input & n_mask);
|
||||
n_mask = n_mask << 1;
|
||||
}
|
||||
|
||||
sz_actual_bit = act_rule.expression;
|
||||
var exitFor = false;
|
||||
|
||||
//controllo se la riga contiene l'istruzione per negare il bit
|
||||
if (sz_actual_bit.Trim().StartsWith("NOT"))
|
||||
foreach (var act_rule in Rules)
|
||||
{
|
||||
n_bit = -1;
|
||||
if ((act_rule.state == "ALL_STATES") || (act_rule.state == sz_actual_state))
|
||||
{
|
||||
//inverto il bit
|
||||
b_invert = true;
|
||||
sz_actual_bit = sz_actual_bit.Replace("NOT ", "").Trim();
|
||||
}
|
||||
//cerca il nome del bit e ne trova l' indice da 0
|
||||
n_bit = Bits.FindIndex(x => x == sz_actual_bit);
|
||||
//DA RESETTARE A FALSE (errore da principianti...)
|
||||
b_invert = false;
|
||||
|
||||
sz_actual_bit = act_rule.expression;
|
||||
|
||||
if (n_bit == -1)
|
||||
{
|
||||
exitFor = true;
|
||||
}
|
||||
|
||||
if (!exitFor)
|
||||
{
|
||||
if (((!b_invert) && b_bit[n_bit]) || (b_invert && (!b_bit[n_bit])))
|
||||
//controllo se la riga contiene l'istruzione per negare il bit
|
||||
if (sz_actual_bit.Trim().StartsWith("NOT"))
|
||||
{
|
||||
sz_line = "";
|
||||
//inverto il bit
|
||||
b_invert = true;
|
||||
sz_actual_bit = sz_actual_bit.Replace("NOT ", "").Trim();
|
||||
}
|
||||
//cerca il nome del bit e ne trova l' indice da 0
|
||||
n_bit = Bits.FindIndex(x => x == sz_actual_bit);
|
||||
|
||||
//eseguo solo se diverso dallo stato corrente
|
||||
if (States.IndexOf(act_rule.next_state) != i)
|
||||
{
|
||||
|
||||
sz_line = $"{n_state_machine_index}" +
|
||||
$";" +
|
||||
$"{i}" +
|
||||
$";" +
|
||||
$"{n_input}" +
|
||||
$";" +
|
||||
$"{Events_to_send.IndexOf(act_rule.event_to_send)}" +
|
||||
$";" +
|
||||
$"{States.IndexOf(act_rule.next_state)}";
|
||||
|
||||
sw.WriteLine(sz_line);
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// sz_line = $"----{n_state_machine_index};{i};{n_input};{Events_to_send.IndexOf(act_rule.event_to_send)};{States.IndexOf(act_rule.next_state)}";
|
||||
//}
|
||||
if (n_bit == -1)
|
||||
{
|
||||
exitFor = true;
|
||||
}
|
||||
|
||||
if (!exitFor)
|
||||
{
|
||||
if (((!b_invert) && b_bit[n_bit]) || (b_invert && (!b_bit[n_bit])))
|
||||
{
|
||||
sz_line = "";
|
||||
|
||||
//eseguo solo se diverso dallo stato corrente
|
||||
if (States.IndexOf(act_rule.next_state) != i)
|
||||
{
|
||||
|
||||
sz_line = $"{n_state_machine_index}" +
|
||||
$";" +
|
||||
$"{i}" +
|
||||
$";" +
|
||||
$"{n_input}" +
|
||||
$";" +
|
||||
$"{Events_to_send.IndexOf(act_rule.event_to_send)}" +
|
||||
$";" +
|
||||
$"{States.IndexOf(act_rule.next_state)}";
|
||||
|
||||
sw.WriteLine(sz_line);
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// sz_line = $"----{n_state_machine_index};{i};{n_input};{Events_to_send.IndexOf(act_rule.event_to_send)};{States.IndexOf(act_rule.next_state)}";
|
||||
//}
|
||||
exitFor = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
filesStatus[origFileName] = true;
|
||||
files2Download.Add(origFileName, sz_file2Write);
|
||||
//var files2Del = Directory.GetFiles(sz_file2Read);
|
||||
|
||||
//foreach (var item in files2Del)
|
||||
//{
|
||||
// File.Delete(item);
|
||||
//}
|
||||
}
|
||||
catch
|
||||
{
|
||||
filesStatus[origFileName] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
}
|
||||
},
|
||||
"ServerConf": {
|
||||
"ProcCsvRootPath": "C:\\Temp\\Rules\\PROCESSED"
|
||||
"ProcCsvRootPath": "Temp\\Rules\\PROCESSED"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user