From d1f75060873013afb7a2941cabbb44b8488137a2 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 28 Jul 2023 17:18:26 +0200 Subject: [PATCH 1/2] Update x gestione lettura/scrittura + logs --- SMGen/Pages/SMEvent2State.razor.cs | 394 ++++++++++++++------------ SMGen/Pages/SMIn2Event.razor.cs | 427 ++++++++++++++++------------- SMGen/SMGen.csproj | 6 + SMGen/logs/.placeholder | 0 4 files changed, 448 insertions(+), 379 deletions(-) create mode 100644 SMGen/logs/.placeholder diff --git a/SMGen/Pages/SMEvent2State.razor.cs b/SMGen/Pages/SMEvent2State.razor.cs index 760684b..40064d9 100644 --- a/SMGen/Pages/SMEvent2State.razor.cs +++ b/SMGen/Pages/SMEvent2State.razor.cs @@ -1,22 +1,37 @@ using EgwCoreLib.Razor; -using Microsoft.AspNetCore.Components.Forms; using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Forms; +using NLog; +using SMGen.Data; using SMGen.Data.DbModels; using SMGen.Data.Services; -using SMGen.Data; -using Microsoft.VisualBasic; -using NLog; namespace SMGen.Pages { public partial class SMEvent2State { + #region Protected Fields + + protected static Logger Log = LogManager.GetCurrentClassLogger(); protected SelectSMIn2EvParams currFilter = new SelectSMIn2EvParams(); protected DataPager? pagerSMIn2Ev = null!; + + #endregion Protected Fields + + #region Protected Properties + protected bool b_rules_definition { get; set; } = false; - protected static Logger Log = LogManager.GetCurrentClassLogger(); + protected bool calcEmptyState + { + get => conf.GetValue("SetupOptions:DoCalcEmptyState"); + } + + protected bool calcItself + { + get => conf.GetValue("SetupOptions:DoCalcItself"); + } [Inject] protected IConfiguration conf { get; set; } = null!; @@ -24,29 +39,14 @@ namespace SMGen.Pages [Inject] protected IWebHostEnvironment env { get; set; } = null!; - [Inject] - protected SMGDataService SMGDService { get; set; } = null!; - protected List Events_to_send { get; set; } = new List(); + protected List events2Add { get; set; } = new List(); protected List fileLines { get; set; } = new List(); - private Dictionary filesStatus - { - get => currFilter.FilesStatus; - set => currFilter.FilesStatus = value; - } - private Dictionary files2Download - { - get => currFilter.Files2Download; - set => currFilter.Files2Download = value; - } - protected Dictionary files2Read { get; set; } = new Dictionary(); - protected List TranInList2add { get; set; } = new List(); - protected string n_state_machine_index { get; set; } = ""; protected int n_states { get; set; } = 0; @@ -59,29 +59,36 @@ namespace SMGen.Pages { get => conf.GetValue("ServerConf:ProcCsvRootPath"); } - protected bool calcItself - { - get => conf.GetValue("SetupOptions:DoCalcItself"); - } - protected bool calcEmptyState - { - get => conf.GetValue("SetupOptions:DoCalcEmptyState"); - } + + protected List Rules { get; set; } = new List(); + + [Inject] + protected SMGDataService SMGDService { get; set; } = null!; + + protected List States2Rules { get; set; } = new List(); + + protected Dictionary StatesAll { get; set; } = new Dictionary(); + + protected Dictionary StatesAll2 { get; set; } = new Dictionary(); + protected string statiCsvPath { get => conf.GetValue("ServerConf:StatiCsvPath"); } - protected List Rules { get; set; } = new List(); - protected Dictionary StatesAll { get; set; } = new Dictionary(); - protected Dictionary StatesAll2 { get; set; } = new Dictionary(); - protected List States2Rules { get; set; } = new List(); - //protected string sz_file2Read { get; set; } = "D:\\Repo\\Mapo-IOB\\StateMachine\\_DEFAULT\\60_STD_MACHINE.rul"; protected string sz_file2Read { get; set; } = ""; protected string sz_file2Write { get; set; } = "prova.csv"; + protected string sz_state_machine_name { get; set; } = ""; + + protected List TranInList2add { get; set; } = new List(); + + #endregion Protected Properties + + #region Protected Methods + protected bool checkDirExist(string dir) { bool answ = false; @@ -106,100 +113,6 @@ namespace SMGen.Pages return answ; } - protected async Task Read_rule_file_transitions() - { - foreach (var item in files2Read) - { - sz_file2Read = item.Value; - - using (StreamReader sr = new StreamReader(sz_file2Read)) - { - StatesAll.Clear(); - Events_to_send.Clear(); - Rules.Clear(); - string line = ""; - while ((line = await sr.ReadLineAsync().ConfigureAwait(false)) != null) - { - if (!line.StartsWith("#") && !string.IsNullOrEmpty(line)) - { - var sz_tokens = line.Split(":"); - - var sz_temp = sz_tokens[0].Trim(); - switch (sz_temp) - { - case "$DEFINITIONS": - b_rules_definition = false; - break; - - case "$NAME": - sz_state_machine_name = sz_tokens[1].Trim(); - break; - - case "$IDX": - n_state_machine_index = sz_tokens[1].Trim(); - break; -#if false - - case "$N_STATES": - n_states = int.Parse(sz_tokens[1].Trim()); - break; -#endif - - case "$STATE": - StatesAll.Add(sz_tokens[2].Trim().ToUpper(), int.Parse(sz_tokens[1].Trim().ToUpper())); - break; - - case "$EVENT": - Events_to_send.Add(sz_tokens[2].Trim().ToUpper()); - var newEvent = new AnagEventiModelTemp() - { - IdxTipo = int.Parse(sz_tokens[1].Trim().ToUpper()), - Nome = sz_tokens[2].Trim().ToUpper() - }; - - events2Add.Add(newEvent); - break; - - case "$RULES": - b_rules_definition = true; - break; - - case "$DO": - b_rules_definition = false; - var isOk = checkDirExist(Path.Combine(procRootDir, statiCsvPath)); - if (isOk) - { - var fileName = $"{item.Key.Split(".")[0]}.csv"; - evaluate_transitions($"{Path.Combine(procRootDir, statiCsvPath, fileName)}", item.Key); - } - 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; - } - - //fileLines.Add(lineSplit[0]); - } - } - } - } - } protected async void evaluate_transitions(string sz_file2Write, string origFileName) { TranInList2add.Clear(); @@ -219,7 +132,6 @@ namespace SMGen.Pages } } - //ciclo negli stati try { @@ -270,7 +182,6 @@ namespace SMGen.Pages TranInList2add.Add(newTranIn); } - } exitFor = true; } @@ -293,9 +204,177 @@ namespace SMGen.Pages } } + protected void ForceReload(int newNum) + { + numRecord = newNum; + } + + protected void ForceReloadPage(int newNum) + { + currPage = newNum; + } + + protected async Task pgResetReq(bool doReset) + { + if (doReset) + { + await Task.Delay(1); + if (pagerSMIn2Ev != null) + { + pagerSMIn2Ev.resetCurrPage(); + } + } + } + + protected async Task Read_rule_file_transitions() + { + foreach (var item in files2Read) + { + sz_file2Read = item.Value; + + using (StreamReader sr = new StreamReader(sz_file2Read)) + { + StatesAll.Clear(); + Events_to_send.Clear(); + Rules.Clear(); + string line = ""; + while ((line = await sr.ReadLineAsync().ConfigureAwait(false)) != null) + { + if (!line.StartsWith("#") && !string.IsNullOrEmpty(line)) + { + var sz_tokens = line.Split(":"); + + var sz_temp = sz_tokens[0].Trim(); + switch (sz_temp) + { + case "$DEFINITIONS": + b_rules_definition = false; + break; + + case "$NAME": + sz_state_machine_name = sz_tokens[1].Trim(); + break; + + case "$IDX": + n_state_machine_index = sz_tokens[1].Trim(); + break; +#if false + + case "$N_STATES": + n_states = int.Parse(sz_tokens[1].Trim()); + break; +#endif + + case "$STATE": + StatesAll.Add(sz_tokens[2].Trim().ToUpper(), int.Parse(sz_tokens[1].Trim().ToUpper())); + break; + + case "$EVENT": + Events_to_send.Add(sz_tokens[2].Trim().ToUpper()); + var newEvent = new AnagEventiModelTemp() + { + IdxTipo = int.Parse(sz_tokens[1].Trim().ToUpper()), + Nome = sz_tokens[2].Trim().ToUpper() + }; + + events2Add.Add(newEvent); + break; + + case "$RULES": + b_rules_definition = true; + break; + + case "$DO": + b_rules_definition = false; + var isOk = checkDirExist(Path.Combine(procRootDir, statiCsvPath)); + if (isOk) + { + var fileName = $"{item.Key.Split(".")[0]}.csv"; + evaluate_transitions($"{Path.Combine(procRootDir, statiCsvPath, fileName)}", item.Key); + } + 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; + } + + //fileLines.Add(lineSplit[0]); + } + } + } + } + } + + 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 Dictionary files2Download + { + get => currFilter.Files2Download; + set => currFilter.Files2Download = value; + } + + private Dictionary filesStatus + { + get => currFilter.FilesStatus; + set => currFilter.FilesStatus = 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 /// - /// Procedee a bonificare la cartella di upload dei files + vecchi di 3 mesi + /// Procedee a bonificare la cartella di upload dei files + vecchi di 3 mesi /// private void deleteOldFiles(string dirPath) { @@ -311,46 +390,6 @@ namespace SMGen.Pages } } } - private int totalCount - { - get => currFilter.TotCount; - set => currFilter.TotCount = value; - } - private int numRecord - { - get => currFilter.NumRec; - set => currFilter.NumRec = value; - } - private int currPage - { - get => currFilter.CurrPage; - set => currFilter.CurrPage = value; - } - protected void UpdateTotCount(int newTotCount) - { - totalCount = newTotCount; - } - 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 async Task pgResetReq(bool doReset) - { - if (doReset) - { - await Task.Delay(1); - if (pagerSMIn2Ev != null) - { - pagerSMIn2Ev.resetCurrPage(); - } - } - } //// va dopo //private StreamWriter objWriter { get; set; }; @@ -385,9 +424,7 @@ namespace SMGen.Pages if (!Directory.Exists(pathDir)) { Directory.CreateDirectory(pathDir); - } - else - { + Log.Info($"Creato directory {pathDir}"); } //creo file @@ -407,14 +444,7 @@ namespace SMGen.Pages } } } - protected void ForceReload(int newNum) - { - numRecord = newNum; - } - protected void ForceReloadPage(int newNum) - { - currPage = newNum; - } + #endregion Private Methods } } \ No newline at end of file diff --git a/SMGen/Pages/SMIn2Event.razor.cs b/SMGen/Pages/SMIn2Event.razor.cs index 794a971..8b29b22 100644 --- a/SMGen/Pages/SMIn2Event.razor.cs +++ b/SMGen/Pages/SMIn2Event.razor.cs @@ -1,9 +1,7 @@ using EgwCoreLib.Razor; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Forms; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.ObjectPool; -using Org.BouncyCastle.Utilities; +using NLog; using SMGen.Data; using SMGen.Data.DbModels; using SMGen.Data.Services; @@ -13,11 +11,23 @@ namespace SMGen.Pages { public partial class SMIn2Event { + #region Protected Fields + protected SelectSMIn2EvParams currFilter = new SelectSMIn2EvParams(); protected DataPager? pagerSMIn2Ev = null!; + + #endregion Protected Fields + + #region Protected Properties + protected bool b_rules_definition { get; set; } = false; + protected string bitCsvPath + { + get => conf.GetValue("ServerConf:BitCsvPath"); + } + protected List Bits { get; set; } = new List(); [Inject] @@ -26,32 +36,14 @@ namespace SMGen.Pages [Inject] protected IWebHostEnvironment env { get; set; } = null!; - [Inject] - protected SMGDataService SMGDService { get; set; } = null!; - protected List Events_to_send { get; set; } = new List(); + protected List events2Add { get; set; } = new List(); protected List fileLines { get; set; } = new List(); - //protected Dictionary files2Download { get; set; } = new Dictionary(); - - //protected Dictionary filesStatus { get; set; } = new Dictionary(); - private Dictionary filesStatus - { - get => currFilter.FilesStatus; - set => currFilter.FilesStatus = value; - } - private Dictionary files2Download - { - get => currFilter.Files2Download; - set => currFilter.Files2Download = value; - } - protected Dictionary files2Read { get; set; } = new Dictionary(); - protected List TranInList2add { get; set; } = new List(); - protected int n_bits { get; set; } = 0; protected string n_state_machine_index { get; set; } = ""; @@ -66,18 +58,29 @@ namespace SMGen.Pages { get => conf.GetValue("ServerConf:ProcCsvRootPath"); } - protected string bitCsvPath - { - get => conf.GetValue("ServerConf:BitCsvPath"); - } protected List Rules { get; set; } = new List(); + + [Inject] + protected SMGDataService SMGDService { get; set; } = null!; + + //protected Dictionary files2Download { get; set; } = new Dictionary(); + protected List States { get; set; } = new List(); + //protected string sz_file2Read { get; set; } = "D:\\Repo\\Mapo-IOB\\StateMachine\\_DEFAULT\\60_STD_MACHINE.rul"; protected string sz_file2Read { get; set; } = ""; protected string sz_file2Write { get; set; } = "prova.csv"; + protected string sz_state_machine_name { get; set; } = ""; + + protected List TranInList2add { get; set; } = new List(); + + #endregion Protected Properties + + #region Protected Methods + protected bool checkDirExist(string dir) { bool answ = false; @@ -102,122 +105,10 @@ namespace SMGen.Pages return answ; } - - - protected async Task Read_rule_file_transitions() + protected async Task evaluate_transitions(string sz_file2Write, string origFileName) { - foreach (var item in files2Read) - { - //await Task.Delay(10); - sz_state_machine_name = ""; - n_state_machine_index = ""; - n_states = 0; - n_bits = 0; - States.Clear(); - Bits.Clear(); - Events_to_send.Clear(); - Rules.Clear(); - sz_file2Read = item.Value; + await Task.Delay(1); - using (StreamReader sr = new StreamReader(sz_file2Read)) - { - string line = ""; - while ((line = await sr.ReadLineAsync().ConfigureAwait(false)) != null) - { - if (!line.StartsWith("#") && !string.IsNullOrEmpty(line)) - { - var sz_tokens = line.Split(":"); - - var sz_temp = sz_tokens[0].Trim(); - switch (sz_temp) - { - case "$DEFINITIONS": - b_rules_definition = false; - break; - - case "$NAME": - sz_state_machine_name = sz_tokens[1].Trim(); - break; - - case "$IDX": - n_state_machine_index = sz_tokens[1].Trim(); - break; - - case "$N_STATES": - n_states = int.Parse(sz_tokens[1].Trim()); - break; - - case "$N_BITS": - n_bits = int.Parse(sz_tokens[1].Trim()); - break; - - case "$BIT": - Bits.Add(sz_tokens[2].Trim().ToUpper()); - break; - - case "$STATE": - States.Add(sz_tokens[2].Trim().ToUpper()); - break; - - case "$EVENT": - Events_to_send.Add(sz_tokens[2].Trim().ToUpper()); - var newEvent = new AnagEventiModelTemp() - { - IdxTipo = int.Parse(sz_tokens[1].Trim().ToUpper()), - Nome = sz_tokens[2].Trim().ToUpper() - }; - - events2Add.Add(newEvent); - break; - - case "$RULES": - b_rules_definition = true; - break; - - case "$DO": - b_rules_definition = false; - var isOk = checkDirExist(procRootDir); - if (isOk) - { - var fileName = $"{item.Key.Split(".")[0]}.csv"; - evaluate_transitions($"{Path.Combine(procRootDir, bitCsvPath, fileName)}", item.Key); - await SMGDService.AnagEventinInsert(events2Add); - await Task.Delay(1); - filesStatus[item.Key] = await SMGDService.TranInInsert(TranInList2add, int.Parse(n_state_machine_index)); - - - if (!files2Download.ContainsKey(item.Key)) - { - files2Download.Add(item.Key, sz_file2Write); - } - await InvokeAsync(() => StateHasChanged()); - } - break; - - default: - if (b_rules_definition) - { - var temp_rule = new RuleClass() - { - state = sz_temp.Trim().ToUpper(), - expression = sz_tokens[1].Trim().ToUpper(), - next_state = sz_tokens[2].Trim().ToUpper(), - event_to_send = sz_tokens[3].Trim().ToUpper() - }; - - Rules.Add(temp_rule); - } - break; - } - - //fileLines.Add(lineSplit[0]); - } - } - } - } - } - protected async void evaluate_transitions(string sz_file2Write, string origFileName) - { TranInList2add.Clear(); //events2Add.Clear(); @@ -228,7 +119,6 @@ namespace SMGen.Pages StringBuilder sb = new StringBuilder(); - sb.AppendLine("IdxFamigliaIngresso;IdxMicroStato;ValoreIngresso;IdxTipoEvento;next_IdxMicroStato"); string sz_actual_state = ""; string sz_actual_bit = ""; @@ -334,7 +224,7 @@ namespace SMGen.Pages using (StreamWriter sw = new StreamWriter(sz_file2Write)) { sw.Write(sb.ToString()); - } + } } catch { @@ -342,9 +232,196 @@ namespace SMGen.Pages } } + protected void ForceReload(int newNum) + { + numRecord = newNum; + } + + protected void ForceReloadPage(int newNum) + { + currPage = newNum; + } + + protected async Task pgResetReq(bool doReset) + { + if (doReset) + { + await Task.Delay(1); + if (pagerSMIn2Ev != null) + { + pagerSMIn2Ev.resetCurrPage(); + } + } + } + + protected async Task Read_rule_file_transitions() + { + foreach (var item in files2Read) + { + //await Task.Delay(10); + sz_state_machine_name = ""; + n_state_machine_index = ""; + n_states = 0; + n_bits = 0; + States.Clear(); + Bits.Clear(); + Events_to_send.Clear(); + Rules.Clear(); + sz_file2Read = item.Value; + + using (StreamReader sr = new StreamReader(sz_file2Read)) + { + string line = ""; + while ((line = await sr.ReadLineAsync().ConfigureAwait(false)) != null) + { + if (!line.StartsWith("#") && !string.IsNullOrEmpty(line)) + { + var sz_tokens = line.Split(":"); + + var sz_temp = sz_tokens[0].Trim(); + switch (sz_temp) + { + case "$DEFINITIONS": + b_rules_definition = false; + break; + + case "$NAME": + sz_state_machine_name = sz_tokens[1].Trim(); + break; + + case "$IDX": + n_state_machine_index = sz_tokens[1].Trim(); + break; + + case "$N_STATES": + n_states = int.Parse(sz_tokens[1].Trim()); + break; + + case "$N_BITS": + n_bits = int.Parse(sz_tokens[1].Trim()); + break; + + case "$BIT": + Bits.Add(sz_tokens[2].Trim().ToUpper()); + break; + + case "$STATE": + States.Add(sz_tokens[2].Trim().ToUpper()); + break; + + case "$EVENT": + Events_to_send.Add(sz_tokens[2].Trim().ToUpper()); + var newEvent = new AnagEventiModelTemp() + { + IdxTipo = int.Parse(sz_tokens[1].Trim().ToUpper()), + Nome = sz_tokens[2].Trim().ToUpper() + }; + + events2Add.Add(newEvent); + break; + + case "$RULES": + b_rules_definition = true; + break; + + case "$DO": + b_rules_definition = false; + var isOk = checkDirExist(procRootDir); + if (isOk) + { + var fileName = $"{item.Key.Split(".")[0]}.csv"; + evaluate_transitions($"{Path.Combine(procRootDir, bitCsvPath, fileName)}", item.Key); + await SMGDService.AnagEventinInsert(events2Add); + await Task.Delay(1); + filesStatus[item.Key] = await SMGDService.TranInInsert(TranInList2add, int.Parse(n_state_machine_index)); + + if (!files2Download.ContainsKey(item.Key)) + { + files2Download.Add(item.Key, sz_file2Write); + } + await InvokeAsync(() => StateHasChanged()); + } + break; + + default: + if (b_rules_definition) + { + var temp_rule = new RuleClass() + { + state = sz_temp.Trim().ToUpper(), + expression = sz_tokens[1].Trim().ToUpper(), + next_state = sz_tokens[2].Trim().ToUpper(), + event_to_send = sz_tokens[3].Trim().ToUpper() + }; + + Rules.Add(temp_rule); + } + break; + } + + //fileLines.Add(lineSplit[0]); + } + } + } + } + } + + 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 Dictionary files2Download + { + get => currFilter.Files2Download; + set => currFilter.Files2Download = value; + } + + //protected Dictionary filesStatus { get; set; } = new Dictionary(); + private Dictionary filesStatus + { + get => currFilter.FilesStatus; + set => currFilter.FilesStatus = 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 /// - /// Procedee a bonificare la cartella di upload dei files + vecchi di 3 mesi + /// Procedee a bonificare la cartella di upload dei files + vecchi di 3 mesi /// private void deleteOldFiles(string dirPath) { @@ -360,46 +437,6 @@ namespace SMGen.Pages } } } - private int totalCount - { - get => currFilter.TotCount; - set => currFilter.TotCount = value; - } - private int numRecord - { - get => currFilter.NumRec; - set => currFilter.NumRec = value; - } - private int currPage - { - get => currFilter.CurrPage; - set => currFilter.CurrPage = value; - } - protected void UpdateTotCount(int newTotCount) - { - totalCount = newTotCount; - } - 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 async Task pgResetReq(bool doReset) - { - if (doReset) - { - await Task.Delay(1); - if (pagerSMIn2Ev != null) - { - pagerSMIn2Ev.resetCurrPage(); - } - } - } //// va dopo //private StreamWriter objWriter { get; set; }; @@ -434,16 +471,18 @@ namespace SMGen.Pages if (!Directory.Exists(pathDir)) { Directory.CreateDirectory(pathDir); - } - else - { + Log.Info($"Creato directory {pathDir}"); } //creo file - await using FileStream fs = new(pathFile, FileMode.Create); + 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}"); + } - //copio il contenuto del file - await file.OpenReadStream(maxFileSize).CopyToAsync(fs); if (file.Name.Contains(".rul")) { files2Read.Add(file.Name, pathFile); @@ -455,14 +494,8 @@ namespace SMGen.Pages } } } - protected void ForceReload(int newNum) - { - numRecord = newNum; - } + protected static Logger Log = LogManager.GetCurrentClassLogger(); - protected void ForceReloadPage(int newNum) - { - currPage = newNum; - } + #endregion Private Methods } } \ No newline at end of file diff --git a/SMGen/SMGen.csproj b/SMGen/SMGen.csproj index 9d6262f..5242bd3 100644 --- a/SMGen/SMGen.csproj +++ b/SMGen/SMGen.csproj @@ -43,4 +43,10 @@ + + + Always + + + diff --git a/SMGen/logs/.placeholder b/SMGen/logs/.placeholder new file mode 100644 index 0000000..e69de29 From ac825efca66d252e006ed62f331370079b550ba0 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 28 Jul 2023 17:28:19 +0200 Subject: [PATCH 2/2] fix using --- SMGen/Pages/SMEvent2State.razor.cs | 9 +++++---- SMGen/Pages/SMIn2Event.razor.cs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/SMGen/Pages/SMEvent2State.razor.cs b/SMGen/Pages/SMEvent2State.razor.cs index 40064d9..10c7d4d 100644 --- a/SMGen/Pages/SMEvent2State.razor.cs +++ b/SMGen/Pages/SMEvent2State.razor.cs @@ -428,10 +428,11 @@ namespace SMGen.Pages } //creo file - await using FileStream fs = new(pathFile, FileMode.Create); - - //copio il contenuto del file - await file.OpenReadStream(maxFileSize).CopyToAsync(fs); + using (FileStream fs = new(pathFile, FileMode.Create)) + { + //copio il contenuto del file + await file.OpenReadStream(maxFileSize).CopyToAsync(fs); + } if (file.Name.Contains(".rul")) { files2Read.Add(file.Name, pathFile); diff --git a/SMGen/Pages/SMIn2Event.razor.cs b/SMGen/Pages/SMIn2Event.razor.cs index 8b29b22..3fe0e25 100644 --- a/SMGen/Pages/SMIn2Event.razor.cs +++ b/SMGen/Pages/SMIn2Event.razor.cs @@ -474,7 +474,7 @@ namespace SMGen.Pages Log.Info($"Creato directory {pathDir}"); } - //creo file + // creo file using (FileStream fs = new(pathFile, FileMode.Create)) { // copio il contenuto del file