diff --git a/WebDoorCreator.UI/Data/WebDoorCreatorService.cs b/WebDoorCreator.UI/Data/WebDoorCreatorService.cs index d8e8add..5218c10 100644 --- a/WebDoorCreator.UI/Data/WebDoorCreatorService.cs +++ b/WebDoorCreator.UI/Data/WebDoorCreatorService.cs @@ -2,13 +2,9 @@ using Microsoft.AspNetCore.Identity.UI.Services; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using NLog; -using Org.BouncyCastle.Asn1.X509; using StackExchange.Redis; using System.Diagnostics; -using System.Reflection.Emit; -using System.Security.AccessControl; using System.Text; using WebDoorCreator.Core; using WebDoorCreator.Data.Controllers; @@ -148,9 +144,6 @@ namespace WebDoorCreator.UI.Data return listActiveCompo; } - - - /// /// Setting all the component list /// @@ -178,7 +171,6 @@ namespace WebDoorCreator.UI.Data // elenco obj da inserire List ListObjDOT = new List(); - string[] DefaultFile = Directory.GetFiles(rootPath, "Default.ini"); IniFile fIniDef = new IniFile(DefaultFile[0]); @@ -385,52 +377,6 @@ namespace WebDoorCreator.UI.Data return fatto; } - public async Task VocLemmaInsert(string rootPath) - { - bool fatto = false; - - List VocLemmas = new List(); - - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - - string[] files = Directory.GetFiles(rootPath, "*"); - string lang = ""; - foreach (string file in files) - { - var fileName = file.Split("."); - - lang = fileName[0].Substring(fileName[0].Length - 2, 2); - - //leggo tutte le linee del file - List lines = File.ReadAllLines(file).ToList(); - - foreach (var line in lines) - { - if (!line.StartsWith("//") && line != "") - { - string[] lineSplit = line.Split("="); - //string trad = ""; - if (lineSplit.Length != 1) - { - VocabularyTempModel newVocLemma = new VocabularyTempModel() - { - Lingua = lang, - Lemma = lineSplit[0], - Traduzione = lineSplit[1] - }; - VocLemmas.Add(newVocLemma); - } - } - } - } - fatto = await dbController.VocLemmaInsert(VocLemmas); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"VocLemmaInsert in: {ts.TotalMilliseconds} ms"); - return fatto; - } - public string DecriptData(string encData) { return SteamCrypto.DecryptString(encData, Constants.passPhrase); @@ -543,6 +489,41 @@ namespace WebDoorCreator.UI.Data return dbResult; } + /// + /// Eliminazione DoorOP + /// + /// + /// + public async Task DoorOpDelete(DoorOpModel currDoorOp) + { + var dbResult = await dbController.DoorOpDelete(currDoorOp); + // elimino cache redis dati porta... + bool answ = await DoorOpFlushCache(currDoorOp.DoorId); + answ = answ && await DoorFlushCache(currDoorOp.DoorId); + // elimino cache redis dati ordine... + answ = answ && await OrdersFlushCache(); + return dbResult; + } + + /// + /// Eliminazione DoorOP list + /// + /// + /// + public async Task DoorOpDeleteRange(List currDoorOpList) + { + var dbResult = await dbController.DoorOpDeleteRange(currDoorOpList); + // elimino cache redis dati porta... + foreach (var item in currDoorOpList) + { + bool answ = await DoorOpFlushCache(item.DoorId); + answ = answ && await DoorFlushCache(item.DoorId); + // elimino cache redis dati ordine... + answ = answ && await OrdersFlushCache(); + } + return dbResult; + } + /// /// Clean redis DOORS OP cache /// @@ -600,164 +581,6 @@ namespace WebDoorCreator.UI.Data return dbResult; } - public async Task>?> VocLemmaGetAll() - { - string source = "DB"; - Dictionary>? dbResult = new Dictionary>(); - // cerco da cache - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - string currKey = $"{Constants.rKeyVocLemma}"; - 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.VocLemmaGetAll(); - 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($"VocLemmaGetAll | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - - public async Task ListValuesLuaNgeInsert(string rootPath) - { - List values = new List(); - string[] dirs = Directory.GetDirectories(rootPath); - foreach (string dir in dirs) - { - string compoCode = ""; - string[] templateDirectories = Directory.GetDirectories(dir); - - string[] iniFiles = Directory.GetFiles(dir, "Config.ini"); - - - int ordin = 1; - foreach (string templateDirectory in templateDirectories) - { - var tName = templateDirectory.Split("\\"); - var fName = templateDirectory.Split("\\"); - - foreach (var file in iniFiles) - { - List lines = File.ReadAllLines(file).ToList(); - IniFile fIni = new IniFile(file); - - var compoName = fIni.ReadString("Compo", "Name", "COMPONAME"); - compoCode = compoName.Split("/")[0].Trim(); - } - string[] templateFiles = Directory.GetFiles(templateDirectory); - if (templateFiles.Length > 0) - { - - ListValuesTempModel folderNames = new ListValuesTempModel() - { - TableName = $"{compoCode}".Replace(" ", "_"), - FieldName = "Folder", - Value = @$"{tName[tName.Length - 1]}".Replace(" ", "_"), - Label = @$"{tName[tName.Length - 1]}", - Ordinal = 0, - DefaultVal = " ", - InputType = " ", - }; - values.Add(folderNames); - } - - foreach (string templateFile in templateFiles) - { - ListValuesTempModel temp = new ListValuesTempModel() - { - TableName = $"{compoCode}".Replace(" ", "_"), - FieldName = "template", - Value = @$"{tName[tName.Length - 1]}\{Path.GetFileName(templateFile).Split(".")[0]}".Replace(" ", "_"), - Label = Path.GetFileName(templateFile).Split(".")[0], - Ordinal = ordin, - DefaultVal = " ", - InputType = " ", - }; - - if (values.Where(x => x.TableName == temp.TableName && x.FieldName == temp.FieldName && x.Value == temp.Value).Count() == 0 && temp.TableName != null && temp.FieldName != null && temp.Value != null) - { - values.Add(temp); - ordin++; - } - else - { - Log.Error($"GraphicParamsGetAll | Duplicated key: {temp.TableName} {temp.FieldName} {temp.Value} "); - } - - } - } - } - - bool fatto = await dbController.ListValuesAdd(values); - - return fatto; - } - - - - /// - /// Doors list by orderId - /// - public async Task?> DoorOpTypeGetAll() - { - string source = "DB"; - List? dbResult = new List(); - // cerco da cache - string currKey = $"{Constants.rKeyDoorOpType}"; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); -#if false - 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 - { - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); - } -#endif - dbResult = dbController.DoorOpTypeGetAll(); - if (dbResult == null) - { - dbResult = new List(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"DoorOpTypeGetAll | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - /// /// lista DoorOpList necessarie all'init /// @@ -821,6 +644,49 @@ namespace WebDoorCreator.UI.Data return dbResult; } + /// + /// Doors list by orderId + /// + public async Task?> DoorOpTypeGetAll() + { + string source = "DB"; + List? dbResult = new List(); + // cerco da cache + string currKey = $"{Constants.rKeyDoorOpType}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); +#if false + 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 + { + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); + } +#endif + dbResult = dbController.DoorOpTypeGetAll(); + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"DoorOpTypeGetAll | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + /// /// Aggiornamento DoorOP /// @@ -836,39 +702,6 @@ namespace WebDoorCreator.UI.Data answ = answ && await OrdersFlushCache(); return dbResult; } - /// - /// Eliminazione DoorOP - /// - /// - /// - public async Task DoorOpDelete(DoorOpModel currDoorOp) - { - var dbResult = await dbController.DoorOpDelete(currDoorOp); - // elimino cache redis dati porta... - bool answ = await DoorOpFlushCache(currDoorOp.DoorId); - answ = answ && await DoorFlushCache(currDoorOp.DoorId); - // elimino cache redis dati ordine... - answ = answ && await OrdersFlushCache(); - return dbResult; - } - /// - /// Eliminazione DoorOP list - /// - /// - /// - public async Task DoorOpDeleteRange(List currDoorOpList) - { - var dbResult = await dbController.DoorOpDeleteRange(currDoorOpList); - // elimino cache redis dati porta... - foreach (var item in currDoorOpList) - { - bool answ = await DoorOpFlushCache(item.DoorId); - answ = answ && await DoorFlushCache(item.DoorId); - // elimino cache redis dati ordine... - answ = answ && await OrdersFlushCache(); - } - return dbResult; - } /// /// Update or add door @@ -904,7 +737,6 @@ namespace WebDoorCreator.UI.Data List listValuesTemp = new List(); ListValuesTempModel listValObj = new ListValuesTempModel(); - IniFile fIni = new IniFile(file); //cerco il contenuto delle sezioni var graphicParamsName = fIni.ReadSection(match.Substring(1, match.Length - 2)); @@ -965,6 +797,49 @@ namespace WebDoorCreator.UI.Data return listValuesTemp; } + /// + /// Estraggo tutte le lingue disponibili per questa applicazione + /// + /// + public async Task?> LanguageGetAll() + { + string source = "DB"; + + List? dbResult = new List(); + // cerco da cache + string currKey = $"{Constants.rKeyLanguage}"; + 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.LanguageGetAll(); + 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($"LanguageGetAll | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + /// /// List values /// @@ -1009,47 +884,76 @@ namespace WebDoorCreator.UI.Data return dbResult; } - /// - /// Estraggo tutte le lingue disponibili per questa applicazione - /// - /// - public async Task?> LanguageGetAll() + public async Task ListValuesLuaNgeInsert(string rootPath) { - string source = "DB"; + List values = new List(); + string[] dirs = Directory.GetDirectories(rootPath); + foreach (string dir in dirs) + { + string compoCode = ""; + string[] templateDirectories = Directory.GetDirectories(dir); - List? dbResult = new List(); - // cerco da cache - string currKey = $"{Constants.rKeyLanguage}"; - 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) + string[] iniFiles = Directory.GetFiles(dir, "Config.ini"); + + int ordin = 1; + foreach (string templateDirectory in templateDirectories) { - dbResult = new List(); - } - else - { - dbResult = tempResult; + var tName = templateDirectory.Split("\\"); + var fName = templateDirectory.Split("\\"); + + foreach (var file in iniFiles) + { + List lines = File.ReadAllLines(file).ToList(); + IniFile fIni = new IniFile(file); + + var compoName = fIni.ReadString("Compo", "Name", "COMPONAME"); + compoCode = compoName.Split("/")[0].Trim(); + } + string[] templateFiles = Directory.GetFiles(templateDirectory); + if (templateFiles.Length > 0) + { + ListValuesTempModel folderNames = new ListValuesTempModel() + { + TableName = $"{compoCode}".Replace(" ", "_"), + FieldName = "Folder", + Value = @$"{tName[tName.Length - 1]}".Replace(" ", "_"), + Label = @$"{tName[tName.Length - 1]}", + Ordinal = 0, + DefaultVal = " ", + InputType = " ", + }; + values.Add(folderNames); + } + + foreach (string templateFile in templateFiles) + { + ListValuesTempModel temp = new ListValuesTempModel() + { + TableName = $"{compoCode}".Replace(" ", "_"), + FieldName = "template", + Value = @$"{tName[tName.Length - 1]}\{Path.GetFileName(templateFile).Split(".")[0]}".Replace(" ", "_"), + Label = Path.GetFileName(templateFile).Split(".")[0], + Ordinal = ordin, + DefaultVal = " ", + InputType = " ", + }; + + if (values.Where(x => x.TableName == temp.TableName && x.FieldName == temp.FieldName && x.Value == temp.Value).Count() == 0 && temp.TableName != null && temp.FieldName != null && temp.Value != null) + { + values.Add(temp); + ordin++; + } + else + { + Log.Error($"GraphicParamsGetAll | Duplicated key: {temp.TableName} {temp.FieldName} {temp.Value} "); + } + } } } - else - { - dbResult = dbController.LanguageGetAll(); - 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($"LanguageGetAll | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; + + bool fatto = await dbController.ListValuesAdd(values); + + return fatto; } /// @@ -1357,11 +1261,94 @@ namespace WebDoorCreator.UI.Data return dbResult; } + public async Task>?> VocLemmaGetAll() + { + string source = "DB"; + Dictionary>? dbResult = new Dictionary>(); + // cerco da cache + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string currKey = $"{Constants.rKeyVocLemma}"; + 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.VocLemmaGetAll(); + 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($"VocLemmaGetAll | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + public async Task VocLemmaInsert(string rootPath) + { + bool fatto = false; + + List VocLemmas = new List(); + + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + + string[] files = Directory.GetFiles(rootPath, "*"); + string lang = ""; + foreach (string file in files) + { + var fileName = file.Split("."); + + lang = fileName[0].Substring(fileName[0].Length - 2, 2); + + //leggo tutte le linee del file + List lines = File.ReadAllLines(file).ToList(); + + foreach (var line in lines) + { + if (!line.StartsWith("//") && line != "") + { + string[] lineSplit = line.Split("="); + //string trad = ""; + if (lineSplit.Length != 1) + { + VocabularyTempModel newVocLemma = new VocabularyTempModel() + { + Lingua = lang, + Lemma = lineSplit[0], + Traduzione = lineSplit[1] + }; + VocLemmas.Add(newVocLemma); + } + } + } + } + fatto = await dbController.VocLemmaInsert(VocLemmas); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"VocLemmaInsert in: {ts.TotalMilliseconds} ms"); + return fatto; + } + #endregion Public Methods #region Protected Fields - protected Random rnd = new Random(); #endregion Protected Fields