From 7bf9062e1b2c97705cbfeda4302d0a5998971f91 Mon Sep 17 00:00:00 2001 From: "zaccaria.majid" Date: Tue, 8 Aug 2023 17:08:43 +0200 Subject: [PATCH] ok rilevamento eventi e stati non utilizzati per ogni file --- SMGen.Data/Data/FileLinesClass.cs | 15 ++ SMGen.Data/Services/SMGDataService.cs | 128 ++++++++++++++++++ SMGen.sln | 2 +- SMGen/Pages/CheckUnused.razor | 66 +++++++++ SMGen/Pages/CheckUnused.razor.cs | 112 +++++++++++++++ SMGen/Shared/NavMenu.razor | 5 + .../PROCESSED/BIT/12_FAMIGLIA_JETCO_NEW.csv | 66 ++++----- 7 files changed, 356 insertions(+), 38 deletions(-) create mode 100644 SMGen.Data/Data/FileLinesClass.cs create mode 100644 SMGen/Pages/CheckUnused.razor create mode 100644 SMGen/Pages/CheckUnused.razor.cs diff --git a/SMGen.Data/Data/FileLinesClass.cs b/SMGen.Data/Data/FileLinesClass.cs new file mode 100644 index 0000000..8ec5b57 --- /dev/null +++ b/SMGen.Data/Data/FileLinesClass.cs @@ -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 statesOK = new Dictionary(); + public Dictionary eventsOK = new Dictionary(); + public List lines = new List(); + } +} diff --git a/SMGen.Data/Services/SMGDataService.cs b/SMGen.Data/Services/SMGDataService.cs index 57de60e..9fe36c6 100644 --- a/SMGen.Data/Services/SMGDataService.cs +++ b/SMGen.Data/Services/SMGDataService.cs @@ -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 States { get; set; } = new List(); private List TranInList2add { get; set; } = new List(); public Dictionary eventsFromDb = new Dictionary(); + //private Dictionary linesChecked { get; set; } = new Dictionary(); + private FileLinesClass linesChecked { get; set; } = new FileLinesClass(); + + + public async Task 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; + } + + /// /// Valuta un file di ruoles x ingressi 2 eventi e restituisce esito /// diff --git a/SMGen.sln b/SMGen.sln index a6690bd..26bb908 100644 --- a/SMGen.sln +++ b/SMGen.sln @@ -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 diff --git a/SMGen/Pages/CheckUnused.razor b/SMGen/Pages/CheckUnused.razor new file mode 100644 index 0000000..371c8ea --- /dev/null +++ b/SMGen/Pages/CheckUnused.razor @@ -0,0 +1,66 @@ +@page "/CheckUnused" + + + + + + +@if (Files.Count > 0) +{ + + @if (k != null && k.statesOK.Count > 0 && k.eventsOK.Count > 0 && k.lines.Count > 0) + { +
+
+
+

STATI

+
+
+ @foreach (var line in k.lines) + { + @if (line.StartsWith("$STATE")) + { + + @if (k.statesOK.ContainsKey(line.Split(":")[2].ToUpper().Trim())) + { + @line +
+ } + else + { + @line +
+ } + } + } +
+
+
+
+

EVENTI

+
+
+ @foreach (var line in k.lines) + { + @if (line.StartsWith("$EVENT")) + { +
+ + @if (k.eventsOK.ContainsKey(line.Split(":")[2].ToUpper().Trim())) + { + @line +
+ } + else + { + @line +
+ } +
+ } + } +
+
+
+ } +} \ No newline at end of file diff --git a/SMGen/Pages/CheckUnused.razor.cs b/SMGen/Pages/CheckUnused.razor.cs new file mode 100644 index 0000000..5758be0 --- /dev/null +++ b/SMGen/Pages/CheckUnused.razor.cs @@ -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 Files { get; set; } = new Dictionary(); + + 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 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()); + } + } +} \ No newline at end of file diff --git a/SMGen/Shared/NavMenu.razor b/SMGen/Shared/NavMenu.razor index 0b8b19d..3f8a58e 100644 --- a/SMGen/Shared/NavMenu.razor +++ b/SMGen/Shared/NavMenu.razor @@ -34,6 +34,11 @@ Gen. SM Stati + diff --git a/SMGen/Temp/Rules/PROCESSED/BIT/12_FAMIGLIA_JETCO_NEW.csv b/SMGen/Temp/Rules/PROCESSED/BIT/12_FAMIGLIA_JETCO_NEW.csv index 7f79371..6df8784 100644 --- a/SMGen/Temp/Rules/PROCESSED/BIT/12_FAMIGLIA_JETCO_NEW.csv +++ b/SMGen/Temp/Rules/PROCESSED/BIT/12_FAMIGLIA_JETCO_NEW.csv @@ -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