ok rilevamento eventi e stati non utilizzati per ogni file

This commit is contained in:
zaccaria.majid
2023-08-08 17:08:43 +02:00
parent 3eb4b86cd6
commit 7bf9062e1b
7 changed files with 356 additions and 38 deletions
+15
View File
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SMGen.Data.Data
{
public class FileLinesClass
{
public Dictionary<string, int> statesOK = new Dictionary<string, int>();
public Dictionary<string, int> eventsOK = new Dictionary<string, int>();
public List<string> lines = new List<string>();
}
}
+128
View File
@@ -2,12 +2,14 @@
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using NLog;
using Org.BouncyCastle.Utilities;
using SMGen.Core;
using SMGen.Data.Controllers;
using SMGen.Data.Data;
using SMGen.Data.DbModels;
using StackExchange.Redis;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
namespace SMGen.Data.Services
@@ -238,6 +240,132 @@ namespace SMGen.Data.Services
private List<string> States { get; set; } = new List<string>();
private List<TransizioneIngressiModelTemp> TranInList2add { get; set; } = new List<TransizioneIngressiModelTemp>();
public Dictionary<int, string> eventsFromDb = new Dictionary<int, string>();
//private Dictionary<string, bool> linesChecked { get; set; } = new Dictionary<string, bool>();
private FileLinesClass linesChecked { get; set; } = new FileLinesClass();
public async Task<FileLinesClass> DoCheckUnusedEvSt(FilesClass currFile)
{
States.Clear();
Bits.Clear();
Events_to_send.Clear();
Rules.Clear();
eventsAll.Clear();
evOk.Clear();
string lineOk = "";
// recupero nome file x partire
string filePath = currFile.tempFileName;
FileLinesClass answ = new FileLinesClass();
string[] lines = File.ReadAllLines(filePath, Encoding.UTF8);
try
{
foreach (var line in lines)
{
lineOk = line;
if (!lineOk.StartsWith("#") && !string.IsNullOrEmpty(lineOk) && lineOk.Length >= 3)
{
if (lineOk.Contains("#"))
{
var lineSplit = lineOk.Split("#");
lineOk = lineSplit[0];
}
var sz_tokens = lineOk.Split(":");
var sz_temp = sz_tokens[0].Trim();
switch (sz_temp)
{
case "$DEFINITIONS":
b_rules_definition = false;
break;
case "$NAME":
break;
case "$IDX":
break;
case "$STATE":
if (!StatesAll.ContainsKey(sz_tokens[2].Trim().ToUpper()))
{
StatesAll.Add(sz_tokens[2].Trim().ToUpper(), int.Parse(sz_tokens[1].Trim().ToUpper()));
}
break;
case "$EVENT":
if (!Events_to_send.ContainsValue(int.Parse(sz_tokens[1].Trim().ToUpper())))
{
Events_to_send.Add(sz_tokens[2].Trim().ToUpper(), int.Parse(sz_tokens[1].Trim().ToUpper()));
}
var newEvent = new AnagEventiModelTemp()
{
IdxTipo = int.Parse(sz_tokens[1].Trim().ToUpper()),
Nome = sz_tokens[2].Trim().ToUpper()
};
break;
case "$RULES":
b_rules_definition = true;
break;
case "$DO":
b_rules_definition = false;
break;
default:
if (b_rules_definition)
{
var state = sz_temp.Trim().ToUpper();
var event_to_send = sz_tokens[1].Trim().ToUpper();
var next_state = sz_tokens[2].Trim().ToUpper();
var temp_rule = new RuleClass()
{
state = state,
event_to_send = event_to_send,
next_state = next_state
};
Rules.Add(temp_rule);
States2Rules.Add(next_state);
}
break;
}
}
else
{
//linesChecked.Add(line, true);
}
}
foreach (var item in States2Rules)
{
if (!StatesAll2.ContainsKey(item))
{
StatesAll2.Add(item, StatesAll[item]);
}
}
foreach (var ev in Events_to_send)
{
var rule2Ev = Rules.FirstOrDefault(x => x.event_to_send == ev.Key);
if (rule2Ev != null)
{
if (!evOk.ContainsKey(ev.Key) && !evOk.ContainsValue(ev.Value))
{
evOk.Add(ev.Key, ev.Value);
}
}
}
}
catch (Exception exc)
{
Log.Error($"{exc}{Environment.NewLine}");
}
answ.statesOK = StatesAll2;
answ.eventsOK = evOk;
answ.lines = lines.ToList();
return answ;
}
/// <summary>
/// Valuta un file di ruoles x ingressi 2 eventi e restituisce esito
/// </summary>
+1 -1
View File
@@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SMGen", "SMGen\SMGen.csproj
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SMGen.Data", "SMGen.Data\SMGen.Data.csproj", "{CF2D0A2F-DED0-4D5D-8C31-099B3C3ED16D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SMGen.Core", "SMGen.Core\SMGen.Core.csproj", "{43E583E7-B94B-4FC6-8473-4AC6A93F76B9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SMGen.Core", "SMGen.Core\SMGen.Core.csproj", "{43E583E7-B94B-4FC6-8473-4AC6A93F76B9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
+66
View File
@@ -0,0 +1,66 @@
@page "/CheckUnused"
<InputFile OnChange="@LoadFiles" multiple />
<button @onclick="()=>doProc()">Process</button>
@if (Files.Count > 0)
{
@if (k != null && k.statesOK.Count > 0 && k.eventsOK.Count > 0 && k.lines.Count > 0)
{
<div class="d-flex justify-content-between">
<div class="card">
<div class="card-header">
<h4>STATI</h4>
</div>
<div class="card-body overflow-auto" style="max-height: 50rem">
@foreach (var line in k.lines)
{
@if (line.StartsWith("$STATE"))
{
@if (k.statesOK.ContainsKey(line.Split(":")[2].ToUpper().Trim()))
{
<span class="text-success">@line</span>
<br />
}
else
{
<span class="text-danger">@line</span>
<br />
}
}
}
</div>
</div>
<div class="card">
<div class="card-header">
<h4>EVENTI</h4>
</div>
<div class="card-body overflow-auto" style="max-height: 50rem">
@foreach (var line in k.lines)
{
@if (line.StartsWith("$EVENT"))
{
<div>
@if (k.eventsOK.ContainsKey(line.Split(":")[2].ToUpper().Trim()))
{
<span class="text-success">@line</span>
<br />
}
else
{
<span class="text-danger">@line</span>
<br />
}
</div>
}
}
</div>
</div>
</div>
}
}
+112
View File
@@ -0,0 +1,112 @@
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());
}
}
}
+5
View File
@@ -34,6 +34,11 @@
<span class="oi oi-plus" aria-hidden="true"></span> Gen. SM Stati
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link p-2" href="CheckUnused">
<span class="oi oi-plus" aria-hidden="true"></span> Controllo inutilizzi
</NavLink>
</div>
</nav>
</div>
@@ -21,43 +21,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;0;50;50
12;0;14;11
12;0;40;34
12;1;1;13
12;1;2;2
12;1;3;3
12;1;4;4
12;1;5;5
12;1;6;6
12;1;7;7
12;1;8;8
12;1;9;9
12;1;10;10
12;1;12;11
12;1;19;30
12;1;26;27
12;1;31;31
12;1;32;32
12;1;37;33
12;1;38;34
12;1;39;35
12;1;49;49
12;1;50;50
12;1;14;11
12;1;15;12
12;1;16;13
12;1;17;14
12;1;20;14
12;1;21;13
12;1;22;14
12;1;23;23
12;1;24;24
12;1;25;25
12;1;28;26
12;1;29;28
12;1;30;29
12;1;33;15
12;1;35;13
12;1;36;14
12;1;40;34
12;2;0;0
12;2;1;13
12;2;3;3
12;2;4;4
@@ -80,6 +44,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;2;14;11
12;2;28;26
12;2;40;34
12;3;0;0
12;3;1;13
12;3;2;2
12;3;4;4
@@ -102,6 +67,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;3;14;11
12;3;28;26
12;3;40;34
12;4;0;0
12;4;1;13
12;4;2;2
12;4;3;3
@@ -124,6 +90,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;4;14;11
12;4;28;26
12;4;40;34
12;5;0;0
12;5;1;13
12;5;2;2
12;5;3;3
@@ -146,6 +113,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;5;14;11
12;5;28;26
12;5;40;34
12;6;0;0
12;6;1;13
12;6;2;2
12;6;3;3
@@ -168,6 +136,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;6;14;11
12;6;28;26
12;6;40;34
12;7;0;0
12;7;1;13
12;7;2;2
12;7;3;3
@@ -190,6 +159,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;7;14;11
12;7;28;26
12;7;40;34
12;8;0;0
12;8;1;13
12;8;2;2
12;8;3;3
@@ -212,6 +182,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;8;14;11
12;8;28;26
12;8;40;34
12;9;0;0
12;9;1;13
12;9;2;2
12;9;3;3
@@ -234,6 +205,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;9;14;11
12;9;28;26
12;9;40;34
12;10;0;0
12;10;1;13
12;10;2;2
12;10;3;3
@@ -256,6 +228,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;10;14;11
12;10;28;26
12;10;40;34
12;11;0;0
12;11;1;13
12;11;2;2
12;11;3;3
@@ -291,6 +264,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;11;35;13
12;11;36;14
12;11;40;34
12;12;0;0
12;12;1;13
12;12;2;2
12;12;3;3
@@ -324,6 +298,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;12;33;15
12;12;35;13
12;12;40;34
12;13;0;0
12;13;2;2
12;13;3;3
12;13;4;4
@@ -355,6 +330,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;13;30;29
12;13;33;15
12;13;40;34
12;14;0;0
12;14;1;13
12;14;2;2
12;14;3;3
@@ -389,6 +365,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;14;33;15
12;14;35;13
12;14;40;34
12;15;0;0
12;15;1;13
12;15;2;2
12;15;3;3
@@ -421,6 +398,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;15;30;29
12;15;35;13
12;15;40;34
12;23;0;0
12;23;1;13
12;23;2;2
12;23;3;3
@@ -458,6 +436,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;23;35;13
12;23;36;14
12;23;40;34
12;24;0;0
12;24;1;13
12;24;2;2
12;24;3;3
@@ -491,6 +470,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;24;33;15
12;24;35;13
12;24;40;34
12;25;0;0
12;25;1;13
12;25;2;2
12;25;3;3
@@ -527,6 +507,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;25;35;13
12;25;36;14
12;25;40;34
12;26;0;0
12;26;1;13
12;26;2;2
12;26;3;3
@@ -564,6 +545,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;26;35;13
12;26;36;14
12;26;40;34
12;27;0;0
12;27;1;13
12;27;2;2
12;27;3;3
@@ -586,6 +568,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;27;14;11
12;27;28;26
12;27;40;34
12;28;0;0
12;28;1;13
12;28;2;2
12;28;3;3
@@ -609,6 +592,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;28;14;11
12;28;16;13
12;28;40;34
12;29;0;0
12;29;1;13
12;29;2;2
12;29;3;3
@@ -633,6 +617,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;29;16;13
12;29;24;24
12;29;40;34
12;30;0;0
12;30;1;13
12;30;2;2
12;30;3;3
@@ -654,6 +639,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;30;50;50
12;30;14;11
12;30;40;34
12;31;0;0
12;31;1;13
12;31;2;2
12;31;3;3
@@ -676,6 +662,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;31;14;11
12;31;28;26
12;31;40;34
12;32;0;0
12;32;1;13
12;32;2;2
12;32;3;3
@@ -698,6 +685,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;32;14;11
12;32;28;26
12;32;40;34
12;33;0;0
12;33;1;13
12;33;2;2
12;33;3;3
@@ -720,6 +708,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;33;14;11
12;33;28;26
12;33;40;34
12;34;0;0
12;34;1;13
12;34;2;2
12;34;3;3
@@ -744,6 +733,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;34;16;13
12;34;24;24
12;34;28;26
12;35;0;0
12;35;1;13
12;35;2;2
12;35;3;3
@@ -766,6 +756,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;35;14;11
12;35;28;26
12;35;40;34
12;49;0;0
12;49;1;13
12;49;2;2
12;49;3;3
@@ -788,6 +779,7 @@ IdxFamiglia;IdxStato;IdxTipo;next_IdxStato
12;49;14;11
12;49;28;26
12;49;40;34
12;50;0;0
12;50;1;13
12;50;2;2
12;50;3;3
1 IdxFamiglia IdxStato IdxTipo next_IdxStato
21 12 0 50 50
22 12 0 14 11
23 12 0 40 34
24 12 1 2 1 0 13 0
12 1 2 2
12 1 3 3
12 1 4 4
12 1 5 5
12 1 6 6
12 1 7 7
12 1 8 8
12 1 9 9
12 1 10 10
12 1 12 11
12 1 19 30
12 1 26 27
12 1 31 31
12 1 32 32
12 1 37 33
12 1 38 34
12 1 39 35
12 1 49 49
12 1 50 50
12 1 14 11
12 1 15 12
12 1 16 13
12 1 17 14
12 1 20 14
12 1 21 13
12 1 22 14
12 1 23 23
12 1 24 24
12 1 25 25
12 1 28 26
12 1 29 28
12 1 30 29
12 1 33 15
12 1 35 13
12 1 36 14
12 1 40 34
25 12 2 1 13
26 12 2 3 3
27 12 2 4 4
44 12 2 14 11
45 12 2 28 26
46 12 2 40 34
47 12 3 0 0
48 12 3 1 13
49 12 3 2 2
50 12 3 4 4
67 12 3 14 11
68 12 3 28 26
69 12 3 40 34
70 12 4 0 0
71 12 4 1 13
72 12 4 2 2
73 12 4 3 3
90 12 4 14 11
91 12 4 28 26
92 12 4 40 34
93 12 5 0 0
94 12 5 1 13
95 12 5 2 2
96 12 5 3 3
113 12 5 14 11
114 12 5 28 26
115 12 5 40 34
116 12 6 0 0
117 12 6 1 13
118 12 6 2 2
119 12 6 3 3
136 12 6 14 11
137 12 6 28 26
138 12 6 40 34
139 12 7 0 0
140 12 7 1 13
141 12 7 2 2
142 12 7 3 3
159 12 7 14 11
160 12 7 28 26
161 12 7 40 34
162 12 8 0 0
163 12 8 1 13
164 12 8 2 2
165 12 8 3 3
182 12 8 14 11
183 12 8 28 26
184 12 8 40 34
185 12 9 0 0
186 12 9 1 13
187 12 9 2 2
188 12 9 3 3
205 12 9 14 11
206 12 9 28 26
207 12 9 40 34
208 12 10 0 0
209 12 10 1 13
210 12 10 2 2
211 12 10 3 3
228 12 10 14 11
229 12 10 28 26
230 12 10 40 34
231 12 11 0 0
232 12 11 1 13
233 12 11 2 2
234 12 11 3 3
264 12 11 35 13
265 12 11 36 14
266 12 11 40 34
267 12 12 0 0
268 12 12 1 13
269 12 12 2 2
270 12 12 3 3
298 12 12 33 15
299 12 12 35 13
300 12 12 40 34
301 12 13 0 0
302 12 13 2 2
303 12 13 3 3
304 12 13 4 4
330 12 13 30 29
331 12 13 33 15
332 12 13 40 34
333 12 14 0 0
334 12 14 1 13
335 12 14 2 2
336 12 14 3 3
365 12 14 33 15
366 12 14 35 13
367 12 14 40 34
368 12 15 0 0
369 12 15 1 13
370 12 15 2 2
371 12 15 3 3
398 12 15 30 29
399 12 15 35 13
400 12 15 40 34
401 12 23 0 0
402 12 23 1 13
403 12 23 2 2
404 12 23 3 3
436 12 23 35 13
437 12 23 36 14
438 12 23 40 34
439 12 24 0 0
440 12 24 1 13
441 12 24 2 2
442 12 24 3 3
470 12 24 33 15
471 12 24 35 13
472 12 24 40 34
473 12 25 0 0
474 12 25 1 13
475 12 25 2 2
476 12 25 3 3
507 12 25 35 13
508 12 25 36 14
509 12 25 40 34
510 12 26 0 0
511 12 26 1 13
512 12 26 2 2
513 12 26 3 3
545 12 26 35 13
546 12 26 36 14
547 12 26 40 34
548 12 27 0 0
549 12 27 1 13
550 12 27 2 2
551 12 27 3 3
568 12 27 14 11
569 12 27 28 26
570 12 27 40 34
571 12 28 0 0
572 12 28 1 13
573 12 28 2 2
574 12 28 3 3
592 12 28 14 11
593 12 28 16 13
594 12 28 40 34
595 12 29 0 0
596 12 29 1 13
597 12 29 2 2
598 12 29 3 3
617 12 29 16 13
618 12 29 24 24
619 12 29 40 34
620 12 30 0 0
621 12 30 1 13
622 12 30 2 2
623 12 30 3 3
639 12 30 50 50
640 12 30 14 11
641 12 30 40 34
642 12 31 0 0
643 12 31 1 13
644 12 31 2 2
645 12 31 3 3
662 12 31 14 11
663 12 31 28 26
664 12 31 40 34
665 12 32 0 0
666 12 32 1 13
667 12 32 2 2
668 12 32 3 3
685 12 32 14 11
686 12 32 28 26
687 12 32 40 34
688 12 33 0 0
689 12 33 1 13
690 12 33 2 2
691 12 33 3 3
708 12 33 14 11
709 12 33 28 26
710 12 33 40 34
711 12 34 0 0
712 12 34 1 13
713 12 34 2 2
714 12 34 3 3
733 12 34 16 13
734 12 34 24 24
735 12 34 28 26
736 12 35 0 0
737 12 35 1 13
738 12 35 2 2
739 12 35 3 3
756 12 35 14 11
757 12 35 28 26
758 12 35 40 34
759 12 49 0 0
760 12 49 1 13
761 12 49 2 2
762 12 49 3 3
779 12 49 14 11
780 12 49 28 26
781 12 49 40 34
782 12 50 0 0
783 12 50 1 13
784 12 50 2 2
785 12 50 3 3