diff --git a/SMGen.Data/Services/SMGDataService.cs b/SMGen.Data/Services/SMGDataService.cs index c499371..ef6864d 100644 --- a/SMGen.Data/Services/SMGDataService.cs +++ b/SMGen.Data/Services/SMGDataService.cs @@ -65,6 +65,51 @@ namespace SMGen.Data.Services #region Public Methods + public async Task> AnagEventiGetAll() + { + string source = "DB"; + Dictionary dbResult = new Dictionary(); + try + { + // cerco da cache + string currKey = $"{Constants.rKeyEventi}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new Dictionary(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.AnagEventiGetAll(); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); + } + if (dbResult == null) + { + dbResult = new Dictionary(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"AnagEventiGetAll | {source} in: {ts.TotalMilliseconds} ms"); + } + catch (Exception exc) + { + Log.Error($"Exception during AnagEventiGetAll: {exc}{Environment.NewLine}"); + } + return dbResult; + } + public async Task AnagEventinInsert(List newEvList) { var dbResult = await dbController.AnagEventinInsert(newEvList); @@ -96,6 +141,96 @@ namespace SMGen.Data.Services return answ; } + public async Task> FamIngressiGetAll() + { + string source = "DB"; + List dbResult = new List(); + try + { + // cerco da cache + string currKey = $"{Constants.rKeyFamIng}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.FamIngressiGetAll(); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"FamIngressiGetAll | {source} in: {ts.TotalMilliseconds} ms"); + } + catch (Exception exc) + { + Log.Error($"Exception during FamIngressiGetAll: {exc}{Environment.NewLine}"); + } + return dbResult; + } + + public async Task> FamStatiGetAll() + { + string source = "DB"; + List dbResult = new List(); + try + { + // cerco da cache + string currKey = $"{Constants.rKeyFamStati}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.FamStatiGetAll(); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"FamStatiGetAll | {source} in: {ts.TotalMilliseconds} ms"); + } + catch (Exception exc) + { + Log.Error($"Exception during FamStatiGetAll: {exc}{Environment.NewLine}"); + } + return dbResult; + } + public async Task> FilesGetAll() { Dictionary dbResult = new Dictionary(); @@ -141,143 +276,6 @@ namespace SMGen.Data.Services return fatto; } - - - public async Task> FamStatiGetAll() - { - string source = "DB"; - List dbResult = new List(); - try - { - // cerco da cache - string currKey = $"{Constants.rKeyFamStati}"; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - string? rawData = await redisDb.StringGetAsync(currKey); - if (!string.IsNullOrEmpty(rawData)) - { - source = "REDIS"; - var tempResult = JsonConvert.DeserializeObject>(rawData); - if (tempResult == null) - { - dbResult = new List(); - } - else - { - dbResult = tempResult; - } - } - else - { - dbResult = dbController.FamStatiGetAll(); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); - } - if (dbResult == null) - { - dbResult = new List(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"FamStatiGetAll | {source} in: {ts.TotalMilliseconds} ms"); - } - catch (Exception exc) - { - Log.Error($"Exception during FamStatiGetAll: {exc}{Environment.NewLine}"); - } - return dbResult; - } - - public async Task> FamIngressiGetAll() - { - string source = "DB"; - List dbResult = new List(); - try - { - // cerco da cache - string currKey = $"{Constants.rKeyFamIng}"; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - string? rawData = await redisDb.StringGetAsync(currKey); - if (!string.IsNullOrEmpty(rawData)) - { - source = "REDIS"; - var tempResult = JsonConvert.DeserializeObject>(rawData); - if (tempResult == null) - { - dbResult = new List(); - } - else - { - dbResult = tempResult; - } - } - else - { - dbResult = dbController.FamIngressiGetAll(); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); - } - if (dbResult == null) - { - dbResult = new List(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"FamIngressiGetAll | {source} in: {ts.TotalMilliseconds} ms"); - } - catch (Exception exc) - { - Log.Error($"Exception during FamIngressiGetAll: {exc}{Environment.NewLine}"); - } - return dbResult; - } - public async Task> AnagEventiGetAll() - { - string source = "DB"; - Dictionary dbResult = new Dictionary(); - try - { - // cerco da cache - string currKey = $"{Constants.rKeyEventi}"; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - string? rawData = await redisDb.StringGetAsync(currKey); - if (!string.IsNullOrEmpty(rawData)) - { - source = "REDIS"; - var tempResult = JsonConvert.DeserializeObject>(rawData); - if (tempResult == null) - { - dbResult = new Dictionary(); - } - else - { - dbResult = tempResult; - } - } - else - { - dbResult = dbController.AnagEventiGetAll(); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); - } - if (dbResult == null) - { - dbResult = new Dictionary(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"AnagEventiGetAll | {source} in: {ts.TotalMilliseconds} ms"); - } - catch (Exception exc) - { - Log.Error($"Exception during AnagEventiGetAll: {exc}{Environment.NewLine}"); - } - return dbResult; - } - - public async Task TranInInsert(List newTIList, int currIdxFamiglia) { var dbResult = await dbController.TranInInsert(newTIList, currIdxFamiglia); @@ -286,28 +284,23 @@ namespace SMGen.Data.Services #endregion Public Methods + public Dictionary eventsFromDb = new Dictionary(); private bool b_rules_definition = false; + List csvLines = new List(); + List linesList = new List(); private int n_bits = 0; private string n_state_machine_index = ""; private int n_states = 0; private string sz_state_machine_name = ""; + public List events2Add { get; set; } = new List(); + + public List eventsAll { get; set; } = new List(); + protected string bitCsvPath { get => _configuration.GetValue("ServerConf:BitCsvPath"); } -#if false - protected bool calcEmptyState - { - get => _configuration.GetValue("SetupOptions:DoCalcEmptyState"); - } - - protected bool calcItself - { - get => _configuration.GetValue("SetupOptions:DoCalcItself"); - } -#endif - protected string procRootDir { get => _configuration.GetValue("ServerConf:ProcCsvRootPath"); @@ -321,19 +314,17 @@ namespace SMGen.Data.Services get => _configuration.GetValue("ServerConf:StatiCsvPath"); } + private List actStates2Chk { get; set; } = new List(); private List Bits { get; set; } = new List(); private Dictionary Events_to_send { get; set; } = new Dictionary(); private Dictionary evOk { get; set; } = new Dictionary(); - public List events2Add { get; set; } = new List(); - public List eventsAll { get; set; } = new List(); - private List Rules { get; set; } = new List(); - 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(); - + private List nextStates2Chk { get; set; } = new List(); + private List Rules { get; set; } = new List(); + private List States { get; set; } = new List(); + private List TranInList2add { get; set; } = new List(); public async Task DoCheckUnusedEvSt(FilesClass currFile) { States.Clear(); @@ -342,6 +333,7 @@ namespace SMGen.Data.Services Rules.Clear(); eventsAll.Clear(); evOk.Clear(); + StatesAll.Clear(); string lineOk = ""; // recupero nome file x partire string filePath = currFile.tempFileName; @@ -477,6 +469,7 @@ namespace SMGen.Data.Services Rules.Clear(); eventsAll.Clear(); evOk.Clear(); + StatesAll.Clear(); string line = ""; // recupero nome file x partire string filePath = currFile.tempFileName; @@ -530,6 +523,7 @@ namespace SMGen.Data.Services break; case "$STATE": + //States.Add(sz_tokens[2].Trim().ToUpper()); if (!StatesAll.ContainsKey(sz_tokens[2].Trim().ToUpper())) { @@ -665,6 +659,7 @@ namespace SMGen.Data.Services Bits.Clear(); Events_to_send.Clear(); Rules.Clear(); + StatesAll.Clear(); // recupero nome file x partire string filePath = currFile.tempFileName; string line = ""; @@ -843,10 +838,6 @@ namespace SMGen.Data.Services return currFile; } - - private List actStates2Chk { get; set; } = new List(); - private List nextStates2Chk { get; set; } = new List(); - /// /// Valutazione schema macchina a stati x Ingressi --> Eventi /// @@ -984,10 +975,6 @@ namespace SMGen.Data.Services } return currFile; } - - List linesList = new List(); - List csvLines = new List(); - /// /// Valutazione schema macchina a stati x Ingressi --> stati ///