From 4d3eafc7e79248beff8f54ca786e25babd180a3a Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 19 May 2023 16:01:53 +0200 Subject: [PATCH 1/4] Aggiunta DTO Preliminari --- WebDoorCreator.Data/DTO/CostingDTO.cs | 21 ++++++++ WebDoorCreator.Data/DTO/CustomerDTO.cs | 59 ++++++++++++++++++++++ WebDoorCreator.Data/DTO/DoorCostingDTO.cs | 25 +++++++++ WebDoorCreator.Data/DTO/OrderDetailsDTO.cs | 40 +++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 WebDoorCreator.Data/DTO/CostingDTO.cs create mode 100644 WebDoorCreator.Data/DTO/CustomerDTO.cs create mode 100644 WebDoorCreator.Data/DTO/DoorCostingDTO.cs create mode 100644 WebDoorCreator.Data/DTO/OrderDetailsDTO.cs diff --git a/WebDoorCreator.Data/DTO/CostingDTO.cs b/WebDoorCreator.Data/DTO/CostingDTO.cs new file mode 100644 index 0000000..bce2d82 --- /dev/null +++ b/WebDoorCreator.Data/DTO/CostingDTO.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WebDoorCreator.Data.DTO +{ + public class CostingDTO + { + /// + /// Order's UID + /// + public int OrderId { get; set; } + + /// + /// Dictionary of evaluated unit cost for each Door in Order + /// + public Dictionary DoorUnitCost { get; set; } = new Dictionary(); + } +} diff --git a/WebDoorCreator.Data/DTO/CustomerDTO.cs b/WebDoorCreator.Data/DTO/CustomerDTO.cs new file mode 100644 index 0000000..9292117 --- /dev/null +++ b/WebDoorCreator.Data/DTO/CustomerDTO.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WebDoorCreator.Data.DTO +{ + /// + /// COmpany data DTO + /// + [Serializable] + public class CustomerDTO + { + public int CompanyId { get; set; } + + /// + /// Codice esterno x riferimento (es ERP) + /// + [MaxLength(250)] + public string CompanyExtCode { get; set; } = ""; + + /// + /// Nome / ragione Sociale + /// + [MaxLength(500)] + public string CompanyName { get; set; } = ""; + + /// + /// indirizzo + /// + [MaxLength(250)] + public string Address { get; set; } = ""; + + /// + /// CAP + /// + public int ZipCode { get; set; } = 0; + + /// + /// Citta + /// + [MaxLength(50)] + public string City { get; set; } = ""; + + /// + /// Stato + /// + [MaxLength(50)] + public string State { get; set; } = ""; + + /// + /// VAT / P.Iva + /// + [MaxLength(50)] + public string VAT { get; set; } = ""; + } +} diff --git a/WebDoorCreator.Data/DTO/DoorCostingDTO.cs b/WebDoorCreator.Data/DTO/DoorCostingDTO.cs new file mode 100644 index 0000000..d9b3475 --- /dev/null +++ b/WebDoorCreator.Data/DTO/DoorCostingDTO.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WebDoorCreator.Data.DTO +{ + /// + /// Serialized door data for cost evaluation + /// + [Serializable] + public class DoorCostingDTO + { + public int DoorId { get; set; } = 0; + + public double SizeX { get; set; } = 0; + public double SizeY { get; set; } = 0; + public double SizeZ { get; set; } = 0; + + public double EstimatedWorkTime { get; set; } = 0; + + public Dictionary BOMList { get; set; }= new Dictionary(); + } +} diff --git a/WebDoorCreator.Data/DTO/OrderDetailsDTO.cs b/WebDoorCreator.Data/DTO/OrderDetailsDTO.cs new file mode 100644 index 0000000..a9b463e --- /dev/null +++ b/WebDoorCreator.Data/DTO/OrderDetailsDTO.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WebDoorCreator.Data.DTO +{ + /// + /// Serialized order data + /// + [Serializable] + public class OrderDetailsDTO + { + /// + /// Order UID (DB) + /// + public int OrderId { get; set; } + + /// + /// Customer Info + /// + public CustomerDTO CustomerInfo { get; set; } = new CustomerDTO(); + + /// + /// Order reference / Ext code + /// + public string OrderExtCode { get; set; } = ""; + + /// + /// Order description + /// + public string OrderDescript { get; set; } = ""; + + /// + /// Door list for current order + /// + public List DoorsList { get; set; } = new List(); + } +} From dc7ee1eb005570ca97f9e64f040e1a2827b8a7c8 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 19 May 2023 16:02:09 +0200 Subject: [PATCH 2/4] Inizio setup controller API --- .../Controllers/OrderController.cs | 43 +++++++++++++++++++ .../Controllers/QueueController.cs | 2 + 2 files changed, 45 insertions(+) create mode 100644 WebDoorCreator.API/Controllers/OrderController.cs diff --git a/WebDoorCreator.API/Controllers/OrderController.cs b/WebDoorCreator.API/Controllers/OrderController.cs new file mode 100644 index 0000000..5bd8ac4 --- /dev/null +++ b/WebDoorCreator.API/Controllers/OrderController.cs @@ -0,0 +1,43 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using NLog; +using WebDoorCreator.Data.DTO; +using WebDoorCreator.Data.Services; + +namespace WebDoorCreator.API.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class OrderController : ControllerBase + { + public OrderController(IConfiguration configuration, QueueDataService DataService) + { + Log.Info("Starting OrderController"); + _configuration = configuration; + QDataServ = DataService; + Log.Info("Avviato OrderController"); + } + // GET: api/Alive + [HttpGet] + public string Get() + { + return "OK"; + } + /// + /// Order detail for cost evaluation + /// + /// + /// + [HttpGet("OrderDetail")] + public async Task OrderDetail(int OrderId) + { + OrderDetailsDTO answ = new OrderDetailsDTO(); + return answ; + } + + private static IConfiguration _configuration = null!; + + private static Logger Log = LogManager.GetCurrentClassLogger(); + private QueueDataService QDataServ { get; set; } = null!; + } +} diff --git a/WebDoorCreator.API/Controllers/QueueController.cs b/WebDoorCreator.API/Controllers/QueueController.cs index 3cf4e79..b1c00dd 100644 --- a/WebDoorCreator.API/Controllers/QueueController.cs +++ b/WebDoorCreator.API/Controllers/QueueController.cs @@ -130,6 +130,8 @@ namespace WebDoorCreator.API.Controllers return actQueue; } + + #endregion Public Methods #region Private Fields From 8287ff68ef2e49699bf058806b5f38f5cb9471ab Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 19 May 2023 16:02:24 +0200 Subject: [PATCH 3/4] Spostamento DoorService in DATA (inizio) --- .../Services/WebDoorCreatorService.cs | 2163 +++++++++++++++++ 1 file changed, 2163 insertions(+) create mode 100644 WebDoorCreator.Data/Services/WebDoorCreatorService.cs diff --git a/WebDoorCreator.Data/Services/WebDoorCreatorService.cs b/WebDoorCreator.Data/Services/WebDoorCreatorService.cs new file mode 100644 index 0000000..c3d8338 --- /dev/null +++ b/WebDoorCreator.Data/Services/WebDoorCreatorService.cs @@ -0,0 +1,2163 @@ +using Microsoft.AspNetCore.Identity.UI.Services; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Newtonsoft.Json; +using NLog; +using StackExchange.Redis; +using System.Diagnostics; +using System.Text; +using WebDoorCreator.Core; +using WebDoorCreator.Data.Controllers; +using WebDoorCreator.Data.DbModels; + +namespace WebDoorCreator.Data.Services +{ + public class WebDoorCreatorService + { + #region Public Fields + + public static WebDoorCreatorController dbController = null!; + + #endregion Public Fields + + #region Public Constructors + + public WebDoorCreatorService(IConfiguration configuration, IConnectionMultiplexer redisConnMult, IEmailSender emailSender) + { + _configuration = configuration; + _emailSender = emailSender; + // Conf cache + redisConn = redisConnMult; + redisDb = this.redisConn.GetDatabase(); + + // json serializer... FIX errore loop circolare https://www.ryadel.com/en/jsonserializationexception-self-referencing-loop-detected-error-fix-entity-framework-asp-net-core/ + JSSettings = new JsonSerializerSettings() + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore + }; + + // cod app + CodApp = _configuration["CodApp"]; + // Conf DB + string connStr = _configuration.GetConnectionString("WDC.DB"); + if (string.IsNullOrEmpty(connStr)) + { + Log.Info("ConnString empty!"); + } + else + { + dbController = new WebDoorCreatorController(configuration); + } + Log.Info("Avviata classe WebDoorCreatorService"); + } + + #endregion Public Constructors + + #region Public Properties + + public string CodApp { get; set; } = ""; + + #endregion Public Properties + + #region Public Methods + + /// + /// Update company + /// + /// + /// + public async Task CompanyAddMod(CompanyModel currRec) + { + var dbResult = await dbController.CompanyAddMod(currRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{Constants.rKeyCompany}"); + bool answ = await ExecFlushRedisPattern(pattern); + await Task.Delay(1); + return dbResult; + } + + /// + /// Company list filtered by company id + /// + /// Id to filter (0=ALL) + /// + public async Task> CompanyGetByKey(int id) + { + string source = "DB"; + + List dbResult = new List(); + // cerco da cache + string currKey = $"{Constants.rKeyCompany}:{id}"; + 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.CompanyGetByKey(id); + 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($"CompanyGetAll | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /*----------------------------------------------------------------------------------------------------------------------*/ + + /// + /// Getting a list of all the active components + /// + /// Path to start + /// + public async Task> CompoGetAllActive(string rootPath) + { + await Task.Delay(1); + List listActiveCompo = new List(); + + //estraggo la lista di componenti che sono attive per il cliente + IniFile fIni = new IniFile(rootPath); + string compoDDF = fIni.ReadString("CompoOrder", "CompoDDFOrder", "CONFIG"); + var compoDDFList = compoDDF.Split(","); + foreach (string compo in compoDDFList) + { + listActiveCompo.Add(compo.Trim()); + } + + return listActiveCompo; + } + + /// + /// Setting all the component list + /// + /// Path to start + /// + public async Task CompoListSetAll(string rootPath) + { + bool fatto = false; + string compoName = ""; + string sizeVal = ""; + List listGraphicParams = new List(); + List listValues = new List(); + ListValuesTempModel Values = new ListValuesTempModel(); + + dbController.TestTablesTruncate(); + + List listActiveCompo = await CompoGetAllActive(Path.Combine(rootPath, @"Default.ini")); + List listCompoS = new List(); + //estraggo tutte le sotto directory della cartella \EgtData\Doors\EgtCompoBase\Compo + string[] dirs = Directory.GetDirectories(rootPath, "*", SearchOption.TopDirectoryOnly); + + // elenco obj da inserire + List ListObjDOT = new List(); + + string[] DefaultFile = Directory.GetFiles(rootPath, "Default.ini"); + + IniFile fIniDef = new IniFile(DefaultFile[0]); + + ListValuesTempModel listValObj = new ListValuesTempModel() + { + TableName = "Properties", + FieldName = "DoorDef", + Value = "Properties", + Label = "Properties", + Ordinal = 1, + DefaultVal = "Maple, Oak, Pine, Birch, Walnut", + InputType = "" + }; + listValues.Add(listValObj); + + listValObj = new ListValuesTempModel() + { + TableName = "Finishing", + FieldName = "DoorDef", + Value = "Finishing", + Label = "Finishing", + Ordinal = 1, + DefaultVal = "Varnishing, Veneer", + InputType = "" + }; + listValues.Add(listValObj); + + listValObj = new ListValuesTempModel() + { + TableName = "All", + FieldName = "OrderStep", + Value = "10", + Label = "Door Draft", + Ordinal = 10, + DefaultVal = "#EF6C00", + InputType = "" + }; + listValues.Add(listValObj); + listValObj = new ListValuesTempModel() + { + TableName = "All", + FieldName = "OrderStep", + Value = "20", + Label = "Sent to DCA", + Ordinal = 20, + DefaultVal = "#FBC02D", + InputType = "" + }; + listValues.Add(listValObj); + listValObj = new ListValuesTempModel() + { + TableName = "All", + FieldName = "OrderStep", + Value = "30", + Label = "Approved By Maker", + Ordinal = 30, + DefaultVal = "#2962FF", + InputType = "" + }; + listValues.Add(listValObj); + listValObj = new ListValuesTempModel() + { + TableName = "All", + FieldName = "OrderStep", + Value = "40", + Label = "Approved By Customer", + Ordinal = 40, + DefaultVal = "#673AB7", + InputType = "" + }; + listValues.Add(listValObj); + listValObj = new ListValuesTempModel() + { + TableName = "All", + FieldName = "OrderStep", + Value = "50", + Label = "Planned", + Ordinal = 50, + DefaultVal = "#00B8D4", + InputType = "" + }; + listValues.Add(listValObj); + listValObj = new ListValuesTempModel() + { + TableName = "All", + FieldName = "OrderStep", + Value = "60", + Label = "In Production", + Ordinal = 60, + DefaultVal = "#43A047", + InputType = "" + }; + listValues.Add(listValObj); + listValObj = new ListValuesTempModel() + { + TableName = "All", + FieldName = "OrderStep", + Value = "70", + Label = "Delivered", + Ordinal = 70, + DefaultVal = "#AEEA00", + InputType = "" + }; + + listValues.Add(listValObj); + listValObj = new ListValuesTempModel() + { + TableName = "All", + FieldName = "DoorDefStep", + Value = "10", + Label = "Door", + Ordinal = 10, + DefaultVal = "#448AFF", + InputType = "" + }; + listValues.Add(listValObj); + listValObj = new ListValuesTempModel() + { + TableName = "All", + FieldName = "DoorDefStep", + Value = "20", + Label = "Hardware", + Ordinal = 20, + DefaultVal = "#448AFF", + InputType = "" + }; + listValues.Add(listValObj); + listValObj = new ListValuesTempModel() + { + TableName = "All", + FieldName = "DoorDefStep", + Value = "30", + Label = "Report", + Ordinal = 30, + DefaultVal = "#448AFF", + InputType = "" + }; + listValues.Add(listValObj); + + // parto con obj base + sizeVal = fIniDef.ReadString("Size", "Width", "0.0"); + + listValObj = new ListValuesTempModel() + { + TableName = "Size", + FieldName = "DoorDef", + Value = "Width", + Label = "50001", + Ordinal = 1, + DefaultVal = sizeVal, + InputType = "TextBox", + isSerializable = true + }; + listValues.Add(listValObj); + sizeVal = fIniDef.ReadString("Size", "Height", "0.0"); + listValObj = new ListValuesTempModel() + { + TableName = "Size", + FieldName = "DoorDef", + Value = "Height", + Label = "50002", + Ordinal = 2, + DefaultVal = sizeVal, + InputType = "TextBox", + isSerializable = true + }; + listValues.Add(listValObj); + sizeVal = fIniDef.ReadString("Size", "Thickness", "0.0"); + listValObj = new ListValuesTempModel() + { + TableName = "Size", + FieldName = "DoorDef", + Value = "Thickness", + Label = "50003", + Ordinal = 3, + DefaultVal = sizeVal, + InputType = "TextBox", + isSerializable = true + }; + listValues.Add(listValObj); + sizeVal = fIniDef.ReadString("Size", "SwingList", "UNDEF"); + listValObj = new ListValuesTempModel() + { + TableName = "Swing", + FieldName = "DoorDef", + Value = "Swing", + Label = "50004", + Ordinal = 1, + DefaultVal = sizeVal, + InputType = "TextBox", + isSerializable = true + }; + listValues.Add(listValObj); + //sizeVal = fIniDef.ReadString("Edge", "EdgeTypeList", "UNDEF"); + StringBuilder edgesList = new StringBuilder(); + for (int x = 1; x <= 11; x++) + { + var edge = fIniDef.ReadString("Edge", $"EdgeType{x}", "UNDEF"); + if (x != 11) + { + edgesList.Append($"{edge.Split("/")[0]},"); + } + else + { + edgesList.Append($"{edge.Split("/")[0]}"); + } + } + listValObj = new ListValuesTempModel() + { + TableName = "Profiles", + FieldName = "DoorDef", + Value = "lockedge", + Label = "50005", + Ordinal = 1, + DefaultVal = "", + InputType = "", + isSerializable = true + }; + listValues.Add(listValObj); + listValObj = new ListValuesTempModel() + { + TableName = "Profiles", + FieldName = "DoorDef", + Value = "hingeedge", + Label = "50006", + Ordinal = 2, + DefaultVal = "", + InputType = "", + isSerializable = true + }; + listValues.Add(listValObj); + listValObj = new ListValuesTempModel() + { + TableName = "Profiles", + FieldName = "DoorDef", + Value = "top", + Label = "50007", + Ordinal = 3, + DefaultVal = "", + InputType = "", + isSerializable = true + }; + listValues.Add(listValObj); + listValObj = new ListValuesTempModel() + { + TableName = "Profiles", + FieldName = "DoorDef", + Value = "bottom", + Label = "50008", + Ordinal = 4, + DefaultVal = "", + InputType = "", + isSerializable = true + }; + listValues.Add(listValObj); + listValObj = new ListValuesTempModel() + { + TableName = "Profiles", + FieldName = "DoorDef", + Value = "type", + Label = "50424", + Ordinal = 5, + DefaultVal = edgesList.ToString(), + InputType = "ComboBox", + isSerializable = true + }; + listValues.Add(listValObj); + listValObj = new ListValuesTempModel() + { + TableName = "Profiles", + FieldName = "DoorDef", + Value = "machining", + Label = "90312", + Ordinal = 6, + DefaultVal = "ON,OFF", + InputType = "ComboBox", + isSerializable = true + }; + listValues.Add(listValObj); + listValObj = new ListValuesTempModel() + { + TableName = "Profiles", + FieldName = "DoorDef", + Value = "overmaterial", + Label = "90312", + Ordinal = 7, + DefaultVal = "0.1", + InputType = "ComboBox", + isSerializable = true + }; + listValues.Add(listValObj); + int i = 0; + + + foreach (string dir in dirs) + { + int numPar = 1; + int numHead = 1; + // scansione della directory... + string[] files = Directory.GetFiles(dir, "Config.ini"); + + compoName = ""; + //iterazione per cercare tutti numPar file "Config.ini" nelle sotto directory + foreach (string file in files) + { + //leggo tutte le linee del file + List lines = File.ReadAllLines(file).ToList(); + IniFile fIni = new IniFile(file); + Guid opCode = Guid.NewGuid(); + //cerco la sezione del file ed estraggo il nome del componente + compoName = fIni.ReadString("Compo", "Name", "COMPONAME"); + //cerco la sezione del file ed estraggo se numPar template sono attivi per il seguente componente + var isActive = fIni.ReadString("Template", "IsActive", "1"); + string layerName = fIni.ReadString("Layer", "LayerName", "LAYER"); + // lo slash indica l'alias + var compoNameSplit = compoName.Split("/"); + + var compoAcArray = listActiveCompo.ToArray(); + var x = Array.FindIndex(compoAcArray, row => row == compoNameSplit[0]); + + if (listActiveCompo.Contains(compoNameSplit[0].ToString())) + { + //creo il componente (padre) + listValObj = new ListValuesTempModel() + { + TableName = $"{compoNameSplit[0]}".Trim(), + FieldName = "Hardware", + Value = $"{compoNameSplit[0]}", + Label = $"{compoNameSplit[1]}", + Ordinal = x, + DefaultVal = " ", + InputType = " " + }; + //HardwareModel compoConfig = new HardwareModel() { compoName = $"{compoNameSplit[0]}", compoAlias = compoNameSplit[1].ToString(), compoLayerName = layerName, compoTemplateIsActive = compoTemplateIsActive }; + //await dbController.CompoAdd(compoConfig); + //listCompoS.Add(compoConfig); + listValues.Add(listValObj); + i++; + //cerco all'interno del file tutte le sezioni che contengono "[Graphic" così da poter prendere il nome della sezione ES: [Graphic parameters1] = Graphic parameters1 + var lineToSearch = lines.Where(x => x.Contains("[Graphic")).ToList(); + numHead = 1; + foreach (var match in lineToSearch) + { + var listV = await GraphicParamsGetAll(file, match, numHead, numPar, $"{compoNameSplit[0]}"); + + foreach (var item in listV) + { + listValues.Add(item); + } + + numHead++; + } + numPar++; + } + } + } + + fatto = await dbController.ListValuesAdd(listValues); + + return fatto; + } + + public string DecriptData(string encData) + { + return SteamCrypto.DecryptString(encData, Constants.passPhrase); + } + + /// + /// CElimina record posta + /// + /// + /// + public async Task DoorDelete(DoorModel currRec) + { + int DoorId = currRec.DoorId; + int OrderId = currRec.OrderId; + // elimino sul DB + bool answ = await dbController.DoorDelete(DoorId); + // svuoto cache + await DoorFlushCache(DoorId); + await DoorOpFlushCache(DoorId); + await OrderDetailFlushCache(OrderId); + await OrdersFlushCache(); + return answ; + } + + /// + /// Clean redis DOORS cache + /// + /// 0 = all + /// + public async Task DoorFlushCache(int DoorId) + { + RedisValue pattern = new RedisValue($"{Constants.rKeyDoor}:*"); + if (DoorId > 0) + { + pattern = new RedisValue($"{Constants.rKeyDoor}:{DoorId}:*"); + } + bool answ = await ExecFlushRedisPattern(pattern); + return answ; + } + + /// + /// Doors list, last in desc order + /// + public async Task?> DoorGetLast(int numRec) + { + string source = "DB"; + List? dbResult = new List(); + // cerco da cache + string currKey = $"{Constants.rKeyDoorLast}:{numRec}"; + 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.DoorsGetLast(numRec); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, FastCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"DoorGetLast | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + /// + /// Doors list by numRec + /// + public async Task?> DoorGetByOrderId(int orderId) + { + string source = "DB"; + List? dbResult = new List(); + // cerco da cache + string currKey = $"{Constants.rKeyOrderDetail}:{orderId}"; + 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.DoorsGetByOrderId(orderId); + 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($"DoorGetByOrderId | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Add door + /// + /// + /// + public async Task DoorInsert(DoorModel newRec) + { + var dbResult = await dbController.DoorInsert(newRec); + // elimino cache redis dati ordine... + await OrderDetailFlushCache(newRec.OrderId); + await OrdersFlushCache(); + return dbResult; + } + + /// + /// Adding or removing a single door + /// + /// Record id to edit or add + /// States if it has to be added or removing a door + /// + public async Task DoorModQty(int NewQty, int OrderId, int DoorId, bool isAdd) + { + var dbResult = await dbController.DoorModQty(NewQty, DoorId, isAdd); + // svuoto cache + await DoorFlushCache(DoorId); + await DoorOpFlushCache(DoorId); + await OrderDetailFlushCache(OrderId); + 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; + } + + /// + /// Clean redis DOORS OP cache + /// + /// 0 = all + /// + public async Task DoorOpFlushCache(int DoorId) + { + RedisValue pattern = new RedisValue($"{Constants.rKeyDoorOp}*"); + if (DoorId > 0) + { + pattern = new RedisValue($"{Constants.rKeyDoorOp}:{DoorId}*"); + } + bool answ = await ExecFlushRedisPattern(pattern); + return answ; + } + + /// + /// Doors list by numRec + /// + public async Task> DoorOpGetByDoorId(int doorId) + { + string source = "DB"; + List? dbResult = new List(); + // cerco da cache + string currKey = $"{Constants.rKeyDoorOp}:{doorId}"; + 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.DoorOpGetByDoorId(doorId); + 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($"DoorOpGetByDoorId | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + /// + /// Doors list by numRec + /// + public async Task DoorOpGetById(int doorOpId) + { + await Task.Delay(1); + string source = "DB"; + DoorOpModel? dbResult = new DoorOpModel(); + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + dbResult = dbController.DoorOpGetById(doorOpId); + if (dbResult == null) + { + dbResult = new DoorOpModel(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"DoorOpGetById | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// lista DoorOpList necessarie all'init + /// + /// + public async Task> DoorOpGetDefault() + { + List? dbResult = new List(); + string source = "DB"; + // cerco da cache + string currKey = $"{Constants.rKeyDoorOpType}:DEFAULT"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + dbResult = await dbController.DoorOpTypeGetDefault(); + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"DoorOpGetDefault | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Restitusice i CurrVals + GraphParams aggiornati dati valori Folder/template + /// + /// Obj x cui è richiesto il ricalcolo parametri + /// Dizionario dei valori attuali + /// Dizionario di obj x GraphParams + /// + public async Task<(Dictionary, Dictionary>)> DoorOpGetUpdatedVals(string ObjectId, Dictionary currVal, Dictionary> currParams, string currTemplShape) + { + await Task.Delay(1); + // duplico oggetti da tornare + Dictionary currValUpd = new Dictionary(); + Dictionary> currParamsUpd = new Dictionary>(); + string default2Design = ""; + // cerco il setup del template selezionato + var listRecordTmp = await ListValuesGetAll(ObjectId, currTemplShape); + if (listRecordTmp != null && currVal.ContainsKey("Folder") && currVal.ContainsKey(currTemplShape)) + { + string actKey = currVal[currTemplShape]; + var firstTemplate = listRecordTmp.Where(x => x.Value == actKey).FirstOrDefault(); + if (firstTemplate != null) + { + if (firstTemplate.DefaultVal != "") + { + default2Design = firstTemplate.DefaultVal; + } + else + { + default2Design = "1"; + } + } + // elimino dai valori di setup e attuali quanto non sia template/folder... + currValUpd = currVal.Where(x => x.Key == "Folder" || x.Key == currTemplShape).ToDictionary(x => x.Key, x => x.Value); + // preparo setup valori + List listDefVal = new List(); + var listRecordGP = await ListValuesGetAll(ObjectId, $"Graphic Parameters{default2Design}"); + if (listRecordGP != null) + { + foreach (var item in listRecordGP) + { + if (item.isSerializable && item.DefaultVal.Contains(",")) + { + listDefVal = item.DefaultVal.Trim().Split(",").ToList(); + currValUpd.Add(item.Value.Trim(), item.DefaultVal.Trim().Split(",")[0].Split("/")[0]); + } + else + { + if (item.DefaultVal.Contains("/")) + { + listDefVal = new List() { item.DefaultVal.Trim().Split("/")[0] }; + currValUpd.Add(item.Value.Trim(), item.DefaultVal.Trim().Split("/")[0]); + } + else + { + listDefVal = new List() { item.DefaultVal.Trim() }; + currValUpd.Add(item.Value.Trim(), item.DefaultVal.Trim()); + } + } + //defaultParamsList.Add(listDefVal); + currParamsUpd.Add(item.Value.Trim(), listDefVal); + } + } + } + return (currValUpd, currParamsUpd); + } + + /// + /// Add doorOP list + /// + /// + /// + /// + public async Task DoorOpInsert(int DoorId, List newOpList) + { + var dbResult = await dbController.DoorOpInsert(newOpList); + // elimino cache redis dati porta... + bool answ = await DoorOpFlushCache(DoorId); + answ = answ && await DoorFlushCache(DoorId); + // elimino cache redis dati ordine... + answ = answ && await OrdersFlushCache(); + return dbResult; + } + + /// + /// Effettua il setup dei Graph parameters date info template selezionato + /// + /// + /// + public async Task DoorOpSetupGraphParams(DoorOpModel currDoorOp) + { + string default2Design = ""; + Dictionary? actDict = new Dictionary(); + Dictionary? actDictNew = new Dictionary(); + Dictionary>? defaultDictNew = new Dictionary>(); + // per prima cosa deserializzo i valori attuali dal record... + if (!string.IsNullOrEmpty(currDoorOp.JsoncActVal)) + { + actDict = JsonConvert.DeserializeObject>(currDoorOp.JsoncActVal); + // verifico di avere valori validi + if (actDict != null) + { + // cerco il setup del template selezionato + var listRecordTmp = await ListValuesGetAll(currDoorOp.ObjectId, "template"); + if (listRecordTmp != null && actDict.ContainsKey("Folder") && (actDict.ContainsKey("template") || actDict.ContainsKey("shape"))) + { + string actKey = actDict["template"];// Path.Combine(actDict["Folder"], actDict["template"]); + var firstTemplate = listRecordTmp.Where(x => x.Value == actKey).FirstOrDefault(); + if (firstTemplate != null) + { + if (firstTemplate.DefaultVal != "") + { + default2Design = firstTemplate.DefaultVal; + } + else + { + default2Design = "1"; + } + } + // elimino dai valori di setup e attuali quanto non sia template/folder... + actDictNew = actDict.Where(x => x.Key == "Folder" || x.Key == "template").ToDictionary(x => x.Key, x => x.Value); + // preparo setup valori + List listDefVal = new List(); + var listRecordGP = await ListValuesGetAll(currDoorOp.ObjectId, $"Graphic Parameters{default2Design}"); + if (listRecordGP != null) + { + foreach (var item in listRecordGP) + { + if (item.isSerializable && item.DefaultVal.Contains(",")) + { + listDefVal = item.DefaultVal.Trim().Split(",").ToList(); + actDictNew.Add(item.Value.Trim(), item.DefaultVal.Trim().Split(",")[0].Split("/")[0]); + } + else + { + if (item.DefaultVal.Contains("/")) + { + listDefVal = new List() { item.DefaultVal.Trim().Split("/")[0] }; + actDictNew.Add(item.Value.Trim(), item.DefaultVal.Trim().Split("/")[0]); + } + else + { + listDefVal = new List() { item.DefaultVal.Trim() }; + actDictNew.Add(item.Value.Trim(), item.DefaultVal.Trim()); + } + } + //defaultParamsList.Add(listDefVal); + defaultDictNew.Add(item.Value.Trim(), listDefVal); + } + } + // ri-serializzo e salvo! + currDoorOp.JsoncActVal = JsonConvert.SerializeObject(actDictNew); + currDoorOp.JsoncConfigVal = JsonConvert.SerializeObject(defaultDictNew); + } + } + } + return currDoorOp; + } + + /// + /// Doors list by numRec + /// + public async Task?> DoorOpTypeGetAll() + { + await Task.Delay(1); + string source = "DB"; + List? dbResult = new List(); + // cerco da cache + string currKey = $"{Constants.rKeyDoorOpType}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + 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 + /// + /// + /// + public async Task DoorOpUpdate(List currDoorOps) + { + var dbResult = await dbController.DoorOpUpdate(currDoorOps); + // elimino cache redis dati porta... + bool answ = await DoorOpFlushCache(currDoorOps.FirstOrDefault()!.DoorId); + answ = answ && await DoorFlushCache(currDoorOps.FirstOrDefault()!.DoorId); + // elimino cache redis dati ordine... + answ = answ && await OrdersFlushCache(); + return dbResult; + } + + /// + /// Update or add door + /// + /// + /// + public async Task DoorUpsert(DoorModel currRec) + { + var dbResult = await dbController.DoorUpsert(currRec); + // elimino cache redis dati porta... + bool answ = await DoorFlushCache(currRec.DoorId); + // elimino cache redis dati ordine... + answ = answ && await OrdersFlushCache(); + return dbResult; + } + + public string EncriptData(string rawData) + { + return SteamCrypto.EncryptString(rawData, Constants.passPhrase); + } + + public async Task FlushRedisCache() + { + await Task.Delay(1); + RedisValue pattern = new RedisValue($"{Constants.redisBaseAddr}*"); + bool answ = await ExecFlushRedisPattern(pattern); + return answ; + } + + public async Task> GraphicParamsGetAll(string file, string match, int n, int i, string HwCode) + { + await Task.Delay(1); + 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)); + //controllo se tra numPar numeri di graphic params vi è un buco ES: Graphic parameters1 Graphic parameters3 se il buco c'è salto tutti numPar parametri che stanno dopo il buco ==> tengo conto solo di Graphic parameters1 + if (int.Parse(match.Substring(match.Length - 2, 1)) == n) + { + int ordinal = 1; + foreach (string param in graphicParamsName) + { + string compoParams = fIni.ReadString(match.Substring(1, match.Length - 2), $"{param.Split("=")[0]}", "CONFIG"); //cerco il parametro nella sezione + var compoParamsSplit = compoParams.Split(";"); + + string CompoParamName = ""; + string CompoParamAlias = ""; + if (param.Split("=")[0].StartsWith("Param")) + { + if (compoParamsSplit[1].Contains("/")) + { + CompoParamName = compoParamsSplit[1].Split("/")[0]; + CompoParamAlias = compoParamsSplit[1].Split("/")[1]; + } + else if (compoParamsSplit[1].Contains(" ")) + { + CompoParamName = compoParamsSplit[1].Split(" ")[1]; + //CompoParamAlias = compoParamsSplit[1].Split(" ")[1]; + } + + //creo nuovo oggetto parametro che conterrà anche il nome del componente per creare relazione + + listValObj = new ListValuesTempModel() + { + TableName = $"{HwCode}".Trim(), + FieldName = match.Substring(1, match.Length - 2), + Value = CompoParamName, + Label = CompoParamAlias, + Ordinal = ordinal, + DefaultVal = param.Split("=")[1].Split(";")[2], + InputType = param.Split("=")[1].Split(";")[0], + isSerializable = true + }; + + if (listValuesTemp.Where(x => x.TableName == listValObj.TableName && x.FieldName == listValObj.FieldName && x.Value == listValObj.Value).Count() == 0 && listValObj.TableName != null && listValObj.FieldName != null && listValObj.Value != null) + { + listValuesTemp.Add(listValObj); + ordinal++; + } + else + { + Log.Error($"GraphicParamsGetAll | Duplicated key: {listValObj.TableName} {listValObj.FieldName} {listValObj.Value} "); + } + } + else + { + } + } + } + + 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 + /// + public async Task?> ListValuesGetAll(string tableName, string fieldName) + { + string source = "DB"; + + List? dbResult = new List(); + string currKey = ""; + // cerco da cache + currKey = $"{Constants.rKeyListValues}:{tableName}:{fieldName}"; + + 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.ListValuesGetAll(tableName, fieldName); + 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($"ListValuesGetAll | {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 compoTempOrShape = ""; + 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"); + var compoT = fIni.ReadString("Template", "Name", "TEMPSHAPE"); + compoCode = compoName.Split("/")[0].Trim(); + compoTempOrShape = compoT.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]}", + Label = @$"{tName[tName.Length - 1]}", + Ordinal = 0, + DefaultVal = " ", + InputType = " ", + }; + values.Add(folderNames); + } + + foreach (string templateFile in templateFiles) + { + string defGpNum = ""; + var lines = File.ReadAllLines(templateFile).ToList(); + + foreach (var line in lines) + { + if (line.StartsWith("--") && line.Contains("Default")) + { + if (line.Split("=")[1] != null) + { + defGpNum = line.Split("=")[1]; + } + else + { + defGpNum = " "; + } + } + } + + var fileName = ""; + if (Path.GetFileName(templateFile).Split(".")[1] == "lua") + { + fileName = Path.GetFileName(templateFile).Split(".")[0]; + } + else + { + fileName = Path.GetFileName(templateFile); + } + + ListValuesTempModel temp = new ListValuesTempModel() + { + TableName = $"{compoCode}".Replace(" ", "_"), + FieldName = compoTempOrShape, + Value = @$"{tName[tName.Length - 1]}\{fileName}", + Label = fileName, + Ordinal = ordin, + DefaultVal = defGpNum, + 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; + } + + /// + /// Add new order + /// + /// + /// + public async Task OrderAdd(OrderModel currRec) + { + var dbResult = await dbController.OrderAdd(currRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{Constants.rKeyOrderStatus}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + return dbResult; + } + + /// + /// Clean REDIS order detail data in cache + /// + /// 0 = all + /// + public async Task OrderDetailFlushCache(int OrderId) + { + RedisValue pattern = new RedisValue($"{Constants.rKeyOrderDetail}:*"); + if (OrderId > 0) + { + pattern = new RedisValue($"{Constants.rKeyOrderDetail}:{OrderId}"); + } + bool answ = await ExecFlushRedisPattern(pattern); + return answ; + } + + /// + /// Remove order + /// + /// + /// + public async Task OrderRem(int OrdId) + { + var dbResult = await dbController.OrderRem(OrdId); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{Constants.rKeyOrderStatus}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + return dbResult; + } + + /// + /// Clean redis ORDERS cache + /// + /// + /// + public async Task OrdersFlushCache() + { + RedisValue pattern = new RedisValue($"{Constants.rKeyOrderStatus}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + return answ; + } + + public async Task?> OrderStatusGetFilt(int companyId, int orderStatus, DateTime dataFrom, DateTime dataTo) + { + string source = "DB"; + + List? dbResult = new List(); + // cerco da cache + string currKey = $"{Constants.rKeyOrderStatus}:{companyId}:{orderStatus}:{dataFrom:yyyyMMdd}:{dataTo:yyyyMMdd}"; + 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 + { + var rawResult = dbController.OrderStatusGetAll(companyId, orderStatus, dataFrom, dataTo); + // ordino desc in ram... + dbResult = rawResult.OrderByDescending(x => x.OrderId).ToList(); + 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($"OrderStatusGetFilt | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Updating an order status + /// + /// + /// + /// + public async Task OrderUpdate(int orderId, int newStatus) + { + var dbResult = await dbController.OrderUpdate(orderId, newStatus); + // elimino cache redis... + //bool answ = await DoorFlushCache(currRec.doorId); + // elimino cache redis dati ordine... + bool answ = await FlushRedisCache(); + return dbResult; + } + + /// + /// Graphic parameters list by hw id + /// + public async Task?> ParamGetByHwId(int hwId) + { + string source = "DB"; + + List? dbResult = new List(); + // cerco da cache + string currKey = $"{Constants.rKeyGraphicParameters}:{hwId}"; + 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.ParamGetByHwId(hwId); + 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($"ParamGetByHwId | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// roles list + /// + public async Task?> RolesGetAll() + { + string source = "DB"; + + List? dbResult = new List(); + // cerco da cache + string currKey = Constants.rKeyRoles; + 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.RolesGetAll(); + 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($"RolesGetAll | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Users roles list + /// + public async Task?> UsersGetAll() + { + string source = "DB"; + + List? dbResult = new List(); + // cerco da cache + string currKey = Constants.rKeyUsers; + 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.UsersGetAll(); + 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($"UsersGetAll | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Users roles list + /// + public async Task UsersGetById(string userId) + { + string source = "DB"; + + AspNetUsers dbResult = new AspNetUsers(); + // cerco da cache + string currKey = $"{Constants.rKeyUsers}:{userId}"; + 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 AspNetUsers(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.UsersGetById(userId); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); + } + if (dbResult == null) + { + dbResult = new AspNetUsers(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"UsersGetById | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Users roles list + /// + public async Task?> UserViewGetAll() + { + string source = "DB"; + + List? dbResult = new List(); + // cerco da cache + string currKey = Constants.rKeyUsersView; + 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.UserViewGetAll(); + 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($"UserViewGetAll | {source} in: {ts.TotalMilliseconds} ms"); + 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; + } + + public async Task createDoor(int idOrd, string userId, string currMeaUnit) + { + int answ = 0; + + // conto le porte x questo ordine e uso x chiamata successiva... + var door4ord = await DoorGetByOrderId(idOrd); + int numDoors = door4ord?.Count + 1 ?? 1; + List listOp = new List(); + DateTime adesso = DateTime.Now; + // creo una nuova porta... + DoorModel newDoor = new DoorModel() + { + OrderId = idOrd, + MeasureUnit = currMeaUnit, + UserIdIns = userId, + UserIdMod = userId, + UserIdLock = userId, + DateIns = adesso, + DateMod = adesso, + DateLockExpiry = adesso.AddHours(1), + DoorDescript = $"ORD {idOrd} | Door {numDoors:00}", + DoorExtCode = $"ORD {idOrd} | Ext Code --", + Quantity = 1, + UnitCost = 0, + TypeId = 1 + }; + // chiamo metodo x insert... + var doorId = await DoorInsert(newDoor); + // aggiungo le lavorazioni standard... + var doorOpList = await DoorOpGetDefault(); + var listRecordEdge = await ListValuesGetAll("Profiles", "DoorDef"); + var listRecordSizing = await ListValuesGetAll("Size", "DoorDef"); + var listRecordSwing = await ListValuesGetAll("Swing", "DoorDef"); + var listRecordProperties = await ListValuesGetAll("Properties", "DoorDef"); + var listRecordFinishing = await ListValuesGetAll("Finishing", "DoorDef"); + ListValuesModel? profCurrType = null; + ListValuesModel? profCurrMach = null; + ListValuesModel? profCurrOverMat = null; + if (listRecordEdge != null) + { + profCurrType = listRecordEdge.Where(x => x.Value == "type").FirstOrDefault(); + profCurrMach = listRecordEdge.Where(x => x.Value == "machining").FirstOrDefault(); + profCurrOverMat = listRecordEdge.Where(x => x.Value == "overmaterial").FirstOrDefault(); + } + Dictionary>> itemsDictDef = new Dictionary>>(); + Dictionary> itemsDictAct = new Dictionary>(); + Dictionary> paramsDict = new Dictionary>(); + Dictionary actDict = new Dictionary(); + List listDefVal = new List(); + List listDefValCurrMach = new List(); + List listDefValOverMat = new List(); + List defaultParamsList = new List(); + + #region Gestione Properties + + if (listRecordProperties != null) + { + foreach (var item in listRecordProperties) + { + foreach (var param in item.DefaultVal.Split(",")) + { + listDefVal.Add(param.Trim()); + if (!actDict.ContainsKey(item.Value)) + { + actDict.Add(item.Value, item.DefaultVal.Trim().Split(",")[0]); + paramsDict.Add(item.Value, listDefVal); + } + //itemsDict.Add(item.Value, paramsDict); + //paramsDict.Clear(); + + } + + //listDefVal = new List() { item.DefaultVal.Trim() }; + + } + itemsDictDef.Add("Properties", paramsDict); + itemsDictAct.Add("Properties", actDict); + //defaultParamsList.Add(listDefVal); + } + var jsonDef = JsonConvert.SerializeObject(itemsDictDef); + var jsonAct = JsonConvert.SerializeObject(itemsDictAct); + + DoorOpModel doorOpToAdd = new DoorOpModel() + { + DateIns = adesso, + DateMod = adesso, + UserIdIns = userId, + UserIdMod = userId, + ObjectId = "Properties", + DoorId = doorId, + JsoncConfigVal = jsonDef, + JsoncActVal = jsonAct, + userConfirm = userId, + DtConfirm = adesso + }; + listOp.Add(doorOpToAdd); + + #endregion Gestione Properties + + paramsDict.Clear(); + actDict.Clear(); + itemsDictDef.Clear(); + itemsDictAct.Clear(); + listDefVal.Clear(); + + #region Gestione Finishing + + if (listRecordFinishing != null) + { + foreach (var item in listRecordFinishing) + { + foreach (var param in item.DefaultVal.Split(",")) + { + listDefVal.Add(param.Trim()); + if (!actDict.ContainsKey(item.Value)) + { + actDict.Add(item.Value, item.DefaultVal.Trim().Split(",")[0]); + paramsDict.Add(item.Value, listDefVal); + } + //itemsDict.Add(item.Value, paramsDict); + //paramsDict.Clear(); + + } + + //listDefVal = new List() { item.DefaultVal.Trim() }; + + } + itemsDictDef.Add("Finishing", paramsDict); + itemsDictAct.Add("Finishing", actDict); + //defaultParamsList.Add(listDefVal); + } + jsonDef = JsonConvert.SerializeObject(itemsDictDef); + jsonAct = JsonConvert.SerializeObject(itemsDictAct); + + doorOpToAdd = new DoorOpModel() + { + DateIns = adesso, + DateMod = adesso, + UserIdIns = userId, + UserIdMod = userId, + ObjectId = "Finishing", + DoorId = doorId, + JsoncConfigVal = jsonDef, + JsoncActVal = jsonAct, + userConfirm = userId, + DtConfirm = adesso + }; + listOp.Add(doorOpToAdd); + + #endregion Gestione Finishing + + paramsDict.Clear(); + actDict.Clear(); + itemsDictDef.Clear(); + itemsDictAct.Clear(); + listDefVal.Clear(); + + #region Gestione sizing + + if (listRecordSizing != null) + { + foreach (var item in listRecordSizing) + { + listDefVal = new List() { item.DefaultVal.Trim() }; + if (!actDict.ContainsKey(item.Value)) + { + actDict.Add(item.Value, item.DefaultVal.Trim()); + paramsDict.Add(item.Value, listDefVal); + } + } + itemsDictDef.Add("Size", paramsDict); + itemsDictAct.Add("Size", actDict); + //defaultParamsList.Add(listDefVal); + } + jsonDef = JsonConvert.SerializeObject(itemsDictDef); + jsonAct = JsonConvert.SerializeObject(itemsDictAct); + + doorOpToAdd = new DoorOpModel() + { + DateIns = adesso, + DateMod = adesso, + UserIdIns = userId, + UserIdMod = userId, + ObjectId = "Size", + DoorId = doorId, + JsoncConfigVal = jsonDef, + JsoncActVal = jsonAct, + userConfirm = userId, + DtConfirm = adesso + }; + listOp.Add(doorOpToAdd); + + #endregion Gestione sizing + + paramsDict.Clear(); + actDict.Clear(); + itemsDictDef.Clear(); + itemsDictAct.Clear(); + listDefVal.Clear(); + + #region Gestione Swing + + if (listRecordSwing != null) + { + foreach (var item in listRecordSwing) + { + foreach (var param in item.DefaultVal.Split(",")) + { + listDefVal.Add(param.Trim()); + if (!actDict.ContainsKey(item.Value)) + { + actDict.Add(item.Value, item.DefaultVal.Trim().Split(",")[0]); + paramsDict.Add(item.Value, listDefVal); + } + //itemsDict.Add(item.Value, paramsDict); + //paramsDict.Clear(); + + } + + //listDefVal = new List() { item.DefaultVal.Trim() }; + + } + itemsDictDef.Add("Swing", paramsDict); + itemsDictAct.Add("Swing", actDict); + //defaultParamsList.Add(listDefVal); + } + jsonDef = JsonConvert.SerializeObject(itemsDictDef); + jsonAct = JsonConvert.SerializeObject(itemsDictAct); + + doorOpToAdd = new DoorOpModel() + { + DateIns = adesso, + DateMod = adesso, + UserIdIns = userId, + UserIdMod = userId, + ObjectId = "Swing", + DoorId = doorId, + JsoncConfigVal = jsonDef, + JsoncActVal = jsonAct, + userConfirm = userId, + DtConfirm = adesso + }; + listOp.Add(doorOpToAdd); + + #endregion Gestione Swing + + paramsDict.Clear(); + actDict.Clear(); + itemsDictDef.Clear(); + itemsDictAct.Clear(); + listDefVal.Clear(); + + + + #region Gestione Profiles + + if (listRecordEdge != null) + { + listDefVal.Clear(); + if (profCurrType != null) + { + foreach (var param in profCurrType.DefaultVal.Split(",")) + { + listDefVal.Add(param.Trim()); + if (!actDict.ContainsKey(profCurrType.Value)) + { + actDict.Add(profCurrType.Value, param.Trim()); + paramsDict.Add(profCurrType.Value, listDefVal); + //listDefVal.Clear(); + } + //itemsDict.Add(item.Value, paramsDict); + //paramsDict.Clear(); + } + if (profCurrMach != null) + { + //listDefVal.Clear(); + foreach (var param in profCurrMach.DefaultVal.Split(",")) + { + listDefValCurrMach.Add(param.Trim()); + if (!actDict.ContainsKey(profCurrMach.Value)) + { + paramsDict.Add(profCurrMach.Value, listDefValCurrMach); + actDict.Add(profCurrMach.Value, profCurrMach.DefaultVal.Trim().Split(",")[0]); + //listDefVal.Clear(); + } + //itemsDict.Add(item.Value, paramsDict); + //paramsDict.Clear(); + + } + } + if (profCurrOverMat != null) + { + //listDefVal.Clear(); + if (!paramsDict.ContainsKey(profCurrOverMat.Value)) + { + listDefValOverMat.Add(profCurrOverMat.DefaultVal.Trim()); + paramsDict.Add(profCurrOverMat.Value, listDefValOverMat); + actDict.Add(profCurrOverMat.Value, profCurrOverMat.DefaultVal.Trim()); + } + } + } + foreach (var item in listRecordEdge.Where(x => x.Value != "type" && x.Value != "machining" && x.Value != "overmaterial")) + { + if (!itemsDictDef.ContainsKey(item.Value)) + { + itemsDictDef.Add(item.Value, paramsDict); + } + if (!itemsDictAct.ContainsKey(item.Value)) + { + itemsDictAct.Add(item.Value, actDict); + } + //defaultParamsList.Add(listDefVal); + //defaultDict.Add(item.Label, listDefVal); + } + } + //actDict.Add(HwToShow.TableName, actParamsList); + + jsonDef = JsonConvert.SerializeObject(itemsDictDef); + jsonAct = JsonConvert.SerializeObject(itemsDictAct); + + doorOpToAdd = new DoorOpModel() + { + DateIns = adesso, + DateMod = adesso, + UserIdIns = userId, + UserIdMod = userId, + ObjectId = "Profiles", + DoorId = doorId, + JsoncConfigVal = jsonDef, + JsoncActVal = jsonAct, + userConfirm = userId, + DtConfirm = adesso + }; + listOp.Add(doorOpToAdd); + + #endregion Gestione Profiles + + // salvo Door OP associate + bool fatto = await DoorOpInsert(doorId, listOp); + + if (fatto) + { + answ = doorId; + } + + return answ; + } + #endregion Public Methods + + #region Protected Fields + + protected Random rnd = new Random(); + + #endregion Protected Fields + + #region Private Fields + + private static IConfiguration _configuration = null!; + + private static JsonSerializerSettings? JSSettings; + + private static Logger Log = LogManager.GetCurrentClassLogger(); + + private readonly IEmailSender _emailSender; + + /// + /// Durata cache lunga IN SECONDI + /// + private int cacheTtlLong = 60 * 5; + + /// + /// Durata cache breve IN SECONDI + /// + private int cacheTtlShort = 60 * 1; + + /// + /// Oggetto per connessione a REDIS + /// + private IConnectionMultiplexer redisConn; + + /// + /// Oggetto DB redis da impiegare x chiamate R/W + /// + private IDatabase redisDb = null!; + + #endregion Private Fields + + #region Private Properties + + /// + /// Durata cache lunga (+ perturbazione percentuale +/-10%) + /// + private TimeSpan FastCache + { + get => TimeSpan.FromSeconds(cacheTtlShort * rnd.Next(900, 1100) / 1000); + } + + /// + /// Durata cache lunga (+ perturbazione percentuale +/-10%) + /// + private TimeSpan LongCache + { + get => TimeSpan.FromSeconds(cacheTtlLong * rnd.Next(900, 1100) / 1000); + } + + /// + /// Durata cache lunga (+ perturbazione percentuale +/-10%) + /// + private TimeSpan UltraLongCache + { + get => TimeSpan.FromSeconds(cacheTtlLong * 10 * rnd.Next(900, 1100) / 1000); + } + + #endregion Private Properties + + #region Private Methods + + /// + /// Esegue flush memoria redis dato pattern + /// + /// + /// + private async Task ExecFlushRedisPattern(RedisValue pattern) + { + bool answ = false; + var listEndpoints = redisConn.GetEndPoints(); + foreach (var endPoint in listEndpoints) + { + //var server = redisConnAdmin.GetServer(listEndpoints[0]); + var server = redisConn.GetServer(endPoint); + if (server != null) + { + var keyList = server.Keys(redisDb.Database, pattern); + foreach (var item in keyList) + { + await redisDb.KeyDeleteAsync(item); + } + answ = true; + } + } + + return answ; + } + + public async Task FlushCustomPattern(string keyWord) + { + await Task.Delay(1); + RedisValue pattern = new RedisValue($"{Constants.redisBaseAddr}:{keyWord}"); + bool answ = await ExecFlushRedisPattern(pattern); + return answ; + } + + #endregion Private Methods + } +} \ No newline at end of file From b02481ef3353b6ca46ff76bad2cc67bfbd180b22 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 19 May 2023 16:29:52 +0200 Subject: [PATCH 4/4] Completato spostsamento servizio webdoor in DATA --- .../Services/WebDoorCreatorService.cs | 3 +- .../WebDoorCreator.Data.csproj | 1 + .../Buttons/ButtonAddRemDoor.razor.cs | 1 + .../Components/CompMan/CompanyList.razor.cs | 1 + .../Components/DoorDef/BaseParamList.razor.cs | 1 + .../DoorDef/DoorDefOrderTopRow.razor.cs | 1 + .../DoorDef/DoorDefStepList.razor.cs | 1 + .../Components/DoorMan/DoorList.razor.cs | 1 + .../Components/Filters/OrderFilter.razor.cs | 1 + .../Components/Gen/NavMenuHorizontal.razor.cs | 1 + .../Components/Hardware/HardwareList.razor.cs | 50 +- .../Hardware/HardwareNewPanel.razor.cs | 1 + .../Components/Order/OrderDets.razor.cs | 109 +- .../Components/Order/OrderList.razor.cs | 1 + .../Components/Order/OrderStatusStep.razor.cs | 1 + .../Components/Report/ReportList.razor.cs | 1 + .../Components/Users/UserList.razor.cs | 1 + .../Data/WebDoorCreatorService.cs | 2163 ----------------- WebDoorCreator.UI/Pages/HwPdfConfirm.razor.cs | 1 + .../Pages/OrdersHomePage.razor.cs | 1 + WebDoorCreator.UI/Pages/SuperAdmin.razor.cs | 1 + WebDoorCreator.UI/Pages/TestAnim.razor | 5 +- WebDoorCreator.UI/Pages/TestPage.razor | 3 +- WebDoorCreator.UI/_Imports.razor | 5 +- 24 files changed, 113 insertions(+), 2242 deletions(-) delete mode 100644 WebDoorCreator.UI/Data/WebDoorCreatorService.cs diff --git a/WebDoorCreator.Data/Services/WebDoorCreatorService.cs b/WebDoorCreator.Data/Services/WebDoorCreatorService.cs index c3d8338..a2d0580 100644 --- a/WebDoorCreator.Data/Services/WebDoorCreatorService.cs +++ b/WebDoorCreator.Data/Services/WebDoorCreatorService.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Identity.UI.Services; +using EgwCoreLib.Utils; +using Microsoft.AspNetCore.Identity.UI.Services; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; diff --git a/WebDoorCreator.Data/WebDoorCreator.Data.csproj b/WebDoorCreator.Data/WebDoorCreator.Data.csproj index c352183..92f3216 100644 --- a/WebDoorCreator.Data/WebDoorCreator.Data.csproj +++ b/WebDoorCreator.Data/WebDoorCreator.Data.csproj @@ -13,6 +13,7 @@ + diff --git a/WebDoorCreator.UI/Components/Buttons/ButtonAddRemDoor.razor.cs b/WebDoorCreator.UI/Components/Buttons/ButtonAddRemDoor.razor.cs index e8559e8..9bef52a 100644 --- a/WebDoorCreator.UI/Components/Buttons/ButtonAddRemDoor.razor.cs +++ b/WebDoorCreator.UI/Components/Buttons/ButtonAddRemDoor.razor.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Identity; using Microsoft.JSInterop; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Data; namespace WebDoorCreator.UI.Components.Buttons diff --git a/WebDoorCreator.UI/Components/CompMan/CompanyList.razor.cs b/WebDoorCreator.UI/Components/CompMan/CompanyList.razor.cs index a3a823a..189c334 100644 --- a/WebDoorCreator.UI/Components/CompMan/CompanyList.razor.cs +++ b/WebDoorCreator.UI/Components/CompMan/CompanyList.razor.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Components; using WebDoorCreator.Data.DbModels; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Data; namespace WebDoorCreator.UI.Components.CompMan diff --git a/WebDoorCreator.UI/Components/DoorDef/BaseParamList.razor.cs b/WebDoorCreator.UI/Components/DoorDef/BaseParamList.razor.cs index 1c8c558..26e3fb2 100644 --- a/WebDoorCreator.UI/Components/DoorDef/BaseParamList.razor.cs +++ b/WebDoorCreator.UI/Components/DoorDef/BaseParamList.razor.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Components; using WebDoorCreator.Data.DbModels; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Data; namespace WebDoorCreator.UI.Components.DoorDef diff --git a/WebDoorCreator.UI/Components/DoorDef/DoorDefOrderTopRow.razor.cs b/WebDoorCreator.UI/Components/DoorDef/DoorDefOrderTopRow.razor.cs index 234e4d3..1ef1b91 100644 --- a/WebDoorCreator.UI/Components/DoorDef/DoorDefOrderTopRow.razor.cs +++ b/WebDoorCreator.UI/Components/DoorDef/DoorDefOrderTopRow.razor.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using WebDoorCreator.Data.DbModels; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Data; namespace WebDoorCreator.UI.Components.DoorDef diff --git a/WebDoorCreator.UI/Components/DoorDef/DoorDefStepList.razor.cs b/WebDoorCreator.UI/Components/DoorDef/DoorDefStepList.razor.cs index ab3495c..efed53b 100644 --- a/WebDoorCreator.UI/Components/DoorDef/DoorDefStepList.razor.cs +++ b/WebDoorCreator.UI/Components/DoorDef/DoorDefStepList.razor.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage; using WebDoorCreator.Data.DbModels; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Data; namespace WebDoorCreator.UI.Components.DoorDef diff --git a/WebDoorCreator.UI/Components/DoorMan/DoorList.razor.cs b/WebDoorCreator.UI/Components/DoorMan/DoorList.razor.cs index 62b1be0..6d794c5 100644 --- a/WebDoorCreator.UI/Components/DoorMan/DoorList.razor.cs +++ b/WebDoorCreator.UI/Components/DoorMan/DoorList.razor.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using WebDoorCreator.Data.DbModels; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Components.SvgComp; using WebDoorCreator.UI.Data; diff --git a/WebDoorCreator.UI/Components/Filters/OrderFilter.razor.cs b/WebDoorCreator.UI/Components/Filters/OrderFilter.razor.cs index 652e2f7..0b6c981 100644 --- a/WebDoorCreator.UI/Components/Filters/OrderFilter.razor.cs +++ b/WebDoorCreator.UI/Components/Filters/OrderFilter.razor.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Components; using WebDoorCreator.Data.DbModels; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Data; namespace WebDoorCreator.UI.Components.Filters diff --git a/WebDoorCreator.UI/Components/Gen/NavMenuHorizontal.razor.cs b/WebDoorCreator.UI/Components/Gen/NavMenuHorizontal.razor.cs index 0a7619f..c591741 100644 --- a/WebDoorCreator.UI/Components/Gen/NavMenuHorizontal.razor.cs +++ b/WebDoorCreator.UI/Components/Gen/NavMenuHorizontal.razor.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Identity; using WebDoorCreator.Data.DbModels; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Data; namespace WebDoorCreator.UI.Components.Gen diff --git a/WebDoorCreator.UI/Components/Hardware/HardwareList.razor.cs b/WebDoorCreator.UI/Components/Hardware/HardwareList.razor.cs index 5d59ee2..6673e44 100644 --- a/WebDoorCreator.UI/Components/Hardware/HardwareList.razor.cs +++ b/WebDoorCreator.UI/Components/Hardware/HardwareList.razor.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Components; using Newtonsoft.Json; using WebDoorCreator.Data.DbModels; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Data; namespace WebDoorCreator.UI.Components.Hardware @@ -21,7 +22,6 @@ namespace WebDoorCreator.UI.Components.Hardware [CascadingParameter] public string UserId { get; set; } = ""; - #endregion Public Properties #region Protected Properties @@ -43,6 +43,21 @@ namespace WebDoorCreator.UI.Components.Hardware #region Protected Methods + protected int getInstNumber(string hwCode) + { + int answ = 0; + + if (DoorOpList != null) + { + answ = DoorOpList + .Where(x => x.ObjectId == hwCode) + .ToList() + .Count(); + } + + return answ; + } + protected async Task hwToAdd() { await Task.Delay(1); @@ -200,6 +215,15 @@ namespace WebDoorCreator.UI.Components.Hardware return answ; } + protected async Task setRefOnDelete(bool isDel) + { + if (isDel) + { + HwToShow = null; + await ReloadData(); + } + } + //CultureInfo ci = CultureInfo.InstalledUICulture; protected string translate(string lemma) { @@ -236,30 +260,6 @@ namespace WebDoorCreator.UI.Components.Hardware } } - protected async Task setRefOnDelete(bool isDel) - { - if (isDel) - { - HwToShow = null; - await ReloadData(); - } - } - - protected int getInstNumber(string hwCode) - { - int answ = 0; - - if (DoorOpList != null) - { - answ = DoorOpList - .Where(x => x.ObjectId == hwCode) - .ToList() - .Count(); - } - - return answ; - } - #endregion Private Methods } } \ No newline at end of file diff --git a/WebDoorCreator.UI/Components/Hardware/HardwareNewPanel.razor.cs b/WebDoorCreator.UI/Components/Hardware/HardwareNewPanel.razor.cs index 8fcc296..750cc8e 100644 --- a/WebDoorCreator.UI/Components/Hardware/HardwareNewPanel.razor.cs +++ b/WebDoorCreator.UI/Components/Hardware/HardwareNewPanel.razor.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Components; using Newtonsoft.Json; using WebDoorCreator.Data.DbModels; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Components.SvgComp; using WebDoorCreator.UI.Data; using static WebDoorCreator.UI.Data.WDCRefreshService; diff --git a/WebDoorCreator.UI/Components/Order/OrderDets.razor.cs b/WebDoorCreator.UI/Components/Order/OrderDets.razor.cs index 2034541..851f98c 100644 --- a/WebDoorCreator.UI/Components/Order/OrderDets.razor.cs +++ b/WebDoorCreator.UI/Components/Order/OrderDets.razor.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Components; using WebDoorCreator.Data.DbModels; using WebDoorCreator.Data.DTO; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Data; namespace WebDoorCreator.UI.Components.Order @@ -10,7 +11,14 @@ namespace WebDoorCreator.UI.Components.Order { #region Public Properties - protected DataPager? pagerDoors = null!; + [Parameter] + public EventCallback E_isEmpty { get; set; } + + [Parameter] + public EventCallback E_SendDoor { get; set; } + + [Parameter] + public OrderStatusViewModel? OrderView { get; set; } public string userId { @@ -19,23 +27,24 @@ namespace WebDoorCreator.UI.Components.Order return WDCUService.userId; } } - [Parameter] - public EventCallback E_SendDoor { get; set; } - protected async Task SetCurrDoor(DoorModel door) - { - await Task.Delay(1); - //currDoor = door; - await E_SendDoor.InvokeAsync(door); - } #endregion Public Properties + #region Protected Fields + + protected DataPager? pagerDoors = null!; + + #endregion Protected Fields + #region Protected Properties protected DoorModel? currDoor { get; set; } = null; + protected int currDoorType { get; set; } = 0; - [Parameter] - public OrderStatusViewModel? OrderView { get; set; } + + protected DDFDto CurrentConf { get; set; } = new DDFDto(); + + protected DoorsSelectFilter currFilter { get; set; } = new DoorsSelectFilter(); /// /// Unit� di misura selezionata @@ -43,15 +52,27 @@ namespace WebDoorCreator.UI.Components.Order protected string currMeaUnit { get; set; } = "mm"; protected List? DoorsList { get; set; } = null; + protected WebDoorCreator.Data.DbModels.Edges edgesFirstInst { get; set; } = new WebDoorCreator.Data.DbModels.Edges(); + protected int idOrd { get; set; } = -1; - protected int orderStat { get; set; } = -1; [Inject] protected NavigationManager NavManager { get; set; } = null!; + protected int orderStat { get; set; } = -1; + protected OrderStatusViewModel? OrderStatus { get; set; } = null; + protected string stepColor { get; set; } = ""; + + protected int totalCount { get; set; } + + protected int userCurrCompany + { + get => WDCUService.userCurrComp; + } + [Inject] protected WDCUserService WDCUService { get; set; } = null!; @@ -62,11 +83,8 @@ namespace WebDoorCreator.UI.Components.Order #region Protected Methods - protected DDFDto CurrentConf { get; set; } = new DDFDto(); - protected async Task createDoor() { - int doorId = await WDService.createDoor(idOrd, userId, currMeaUnit); if (doorId > 0) { @@ -77,20 +95,32 @@ namespace WebDoorCreator.UI.Components.Order NavManager.NavigateTo($"DoorDefinition?idOrd={idOrd}&idDoor={doorId}"); } - - - protected int userCurrCompany + protected void ForceReload(int newNum) { - get => WDCUService.userCurrComp; + numRecord = newNum; } - - protected async override Task OnParametersSetAsync() + protected void ForceReloadPage(int newNum) { - await Task.Delay(1); + currPage = newNum; } - protected string stepColor { get; set; } = ""; + protected override async Task OnParametersSetAsync() + { + await Task.Delay(1); + } + + protected async Task SetCurrDoor(DoorModel door) + { + await Task.Delay(1); + //currDoor = door; + await E_SendDoor.InvokeAsync(door); + } + + protected async Task setEmpty() + { + await E_isEmpty.InvokeAsync(true); + } protected async Task setStepColor(string StepColor) { @@ -99,22 +129,14 @@ namespace WebDoorCreator.UI.Components.Order StateHasChanged(); } - [Parameter] - public EventCallback E_isEmpty { get; set; } - - protected async Task setEmpty() + protected void UpdateTotCount(int newTotCount) { - await E_isEmpty.InvokeAsync(true); + totalCount = newTotCount; } #endregion Protected Methods - #region Private Fields - - - #endregion Private Fields - - protected DoorsSelectFilter currFilter { get; set; } = new DoorsSelectFilter(); + #region Private Properties private int currPage { @@ -129,27 +151,16 @@ namespace WebDoorCreator.UI.Components.Order get => currFilter.NumRec; set => currFilter.NumRec = value; } + private string searchValue { get => currFilter.searchValue; set => currFilter.searchValue = value; } - protected int totalCount { get; set; } + #endregion Private Properties - protected void ForceReload(int newNum) - { - numRecord = newNum; - } - - protected void ForceReloadPage(int newNum) - { - currPage = newNum; - } - protected void UpdateTotCount(int newTotCount) - { - totalCount = newTotCount; - } + #region Private Methods private async Task updateFilter(DoorsSelectFilter newParams) { @@ -162,5 +173,7 @@ namespace WebDoorCreator.UI.Components.Order currFilter = newParams; isLoading = false; } + + #endregion Private Methods } } \ No newline at end of file diff --git a/WebDoorCreator.UI/Components/Order/OrderList.razor.cs b/WebDoorCreator.UI/Components/Order/OrderList.razor.cs index 3d2ed69..51a9c97 100644 --- a/WebDoorCreator.UI/Components/Order/OrderList.razor.cs +++ b/WebDoorCreator.UI/Components/Order/OrderList.razor.cs @@ -10,6 +10,7 @@ using Microsoft.JSInterop; using NLog.LayoutRenderers; using System.Linq; using WebDoorCreator.Data.DbModels; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Data; using static Microsoft.AspNetCore.Razor.Language.TagHelperMetadata; using static WebDoorCreator.Core.Enum; diff --git a/WebDoorCreator.UI/Components/Order/OrderStatusStep.razor.cs b/WebDoorCreator.UI/Components/Order/OrderStatusStep.razor.cs index e8b3681..67d0361 100644 --- a/WebDoorCreator.UI/Components/Order/OrderStatusStep.razor.cs +++ b/WebDoorCreator.UI/Components/Order/OrderStatusStep.razor.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage; using WebDoorCreator.Data.DbModels; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Data; namespace WebDoorCreator.UI.Components.Order diff --git a/WebDoorCreator.UI/Components/Report/ReportList.razor.cs b/WebDoorCreator.UI/Components/Report/ReportList.razor.cs index 658280a..418952e 100644 --- a/WebDoorCreator.UI/Components/Report/ReportList.razor.cs +++ b/WebDoorCreator.UI/Components/Report/ReportList.razor.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.Build.Framework; using Microsoft.CodeAnalysis.CSharp.Syntax; using WebDoorCreator.Data.DbModels; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Data; namespace WebDoorCreator.UI.Components.Report diff --git a/WebDoorCreator.UI/Components/Users/UserList.razor.cs b/WebDoorCreator.UI/Components/Users/UserList.razor.cs index 687e9ac..b119329 100644 --- a/WebDoorCreator.UI/Components/Users/UserList.razor.cs +++ b/WebDoorCreator.UI/Components/Users/UserList.razor.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using WebDoorCreator.Data.DbModels; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Data; namespace WebDoorCreator.UI.Components.Users diff --git a/WebDoorCreator.UI/Data/WebDoorCreatorService.cs b/WebDoorCreator.UI/Data/WebDoorCreatorService.cs deleted file mode 100644 index 6cea6d7..0000000 --- a/WebDoorCreator.UI/Data/WebDoorCreatorService.cs +++ /dev/null @@ -1,2163 +0,0 @@ -using EgwCoreLib.Razor.Data; -using Microsoft.AspNetCore.Identity.UI.Services; -using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; -using NLog; -using StackExchange.Redis; -using System.Diagnostics; -using System.Text; -using WebDoorCreator.Core; -using WebDoorCreator.Data.Controllers; -using WebDoorCreator.Data.DbModels; - -namespace WebDoorCreator.UI.Data -{ - public class WebDoorCreatorService - { - #region Public Fields - - public static WebDoorCreatorController dbController = null!; - - #endregion Public Fields - - #region Public Constructors - - public WebDoorCreatorService(IConfiguration configuration, IConnectionMultiplexer redisConnMult, IEmailSender emailSender) - { - _configuration = configuration; - _emailSender = emailSender; - // Conf cache - redisConn = redisConnMult; - redisDb = this.redisConn.GetDatabase(); - - // json serializer... FIX errore loop circolare https://www.ryadel.com/en/jsonserializationexception-self-referencing-loop-detected-error-fix-entity-framework-asp-net-core/ - JSSettings = new JsonSerializerSettings() - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore - }; - - // cod app - CodApp = _configuration["CodApp"]; - // Conf DB - string connStr = _configuration.GetConnectionString("WDC.DB"); - if (string.IsNullOrEmpty(connStr)) - { - Log.Info("ConnString empty!"); - } - else - { - dbController = new WebDoorCreatorController(configuration); - } - Log.Info("Avviata classe WebDoorCreatorService"); - } - - #endregion Public Constructors - - #region Public Properties - - public string CodApp { get; set; } = ""; - - #endregion Public Properties - - #region Public Methods - - /// - /// Update company - /// - /// - /// - public async Task CompanyAddMod(CompanyModel currRec) - { - var dbResult = await dbController.CompanyAddMod(currRec); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{Constants.rKeyCompany}"); - bool answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - - /// - /// Company list filtered by company id - /// - /// Id to filter (0=ALL) - /// - public async Task> CompanyGetByKey(int id) - { - string source = "DB"; - - List dbResult = new List(); - // cerco da cache - string currKey = $"{Constants.rKeyCompany}:{id}"; - 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.CompanyGetByKey(id); - 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($"CompanyGetAll | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - - /*----------------------------------------------------------------------------------------------------------------------*/ - - /// - /// Getting a list of all the active components - /// - /// Path to start - /// - public async Task> CompoGetAllActive(string rootPath) - { - await Task.Delay(1); - List listActiveCompo = new List(); - - //estraggo la lista di componenti che sono attive per il cliente - IniFile fIni = new IniFile(rootPath); - string compoDDF = fIni.ReadString("CompoOrder", "CompoDDFOrder", "CONFIG"); - var compoDDFList = compoDDF.Split(","); - foreach (string compo in compoDDFList) - { - listActiveCompo.Add(compo.Trim()); - } - - return listActiveCompo; - } - - /// - /// Setting all the component list - /// - /// Path to start - /// - public async Task CompoListSetAll(string rootPath) - { - bool fatto = false; - string compoName = ""; - string sizeVal = ""; - List listGraphicParams = new List(); - List listValues = new List(); - ListValuesTempModel Values = new ListValuesTempModel(); - - dbController.TestTablesTruncate(); - - List listActiveCompo = await CompoGetAllActive(Path.Combine(rootPath, @"Default.ini")); - List listCompoS = new List(); - //estraggo tutte le sotto directory della cartella \EgtData\Doors\EgtCompoBase\Compo - string[] dirs = Directory.GetDirectories(rootPath, "*", SearchOption.TopDirectoryOnly); - - // elenco obj da inserire - List ListObjDOT = new List(); - - string[] DefaultFile = Directory.GetFiles(rootPath, "Default.ini"); - - IniFile fIniDef = new IniFile(DefaultFile[0]); - - ListValuesTempModel listValObj = new ListValuesTempModel() - { - TableName = "Properties", - FieldName = "DoorDef", - Value = "Properties", - Label = "Properties", - Ordinal = 1, - DefaultVal = "Maple, Oak, Pine, Birch, Walnut", - InputType = "" - }; - listValues.Add(listValObj); - - listValObj = new ListValuesTempModel() - { - TableName = "Finishing", - FieldName = "DoorDef", - Value = "Finishing", - Label = "Finishing", - Ordinal = 1, - DefaultVal = "Varnishing, Veneer", - InputType = "" - }; - listValues.Add(listValObj); - - listValObj = new ListValuesTempModel() - { - TableName = "All", - FieldName = "OrderStep", - Value = "10", - Label = "Door Draft", - Ordinal = 10, - DefaultVal = "#EF6C00", - InputType = "" - }; - listValues.Add(listValObj); - listValObj = new ListValuesTempModel() - { - TableName = "All", - FieldName = "OrderStep", - Value = "20", - Label = "Sent to DCA", - Ordinal = 20, - DefaultVal = "#FBC02D", - InputType = "" - }; - listValues.Add(listValObj); - listValObj = new ListValuesTempModel() - { - TableName = "All", - FieldName = "OrderStep", - Value = "30", - Label = "Approved By Maker", - Ordinal = 30, - DefaultVal = "#2962FF", - InputType = "" - }; - listValues.Add(listValObj); - listValObj = new ListValuesTempModel() - { - TableName = "All", - FieldName = "OrderStep", - Value = "40", - Label = "Approved By Customer", - Ordinal = 40, - DefaultVal = "#673AB7", - InputType = "" - }; - listValues.Add(listValObj); - listValObj = new ListValuesTempModel() - { - TableName = "All", - FieldName = "OrderStep", - Value = "50", - Label = "Planned", - Ordinal = 50, - DefaultVal = "#00B8D4", - InputType = "" - }; - listValues.Add(listValObj); - listValObj = new ListValuesTempModel() - { - TableName = "All", - FieldName = "OrderStep", - Value = "60", - Label = "In Production", - Ordinal = 60, - DefaultVal = "#43A047", - InputType = "" - }; - listValues.Add(listValObj); - listValObj = new ListValuesTempModel() - { - TableName = "All", - FieldName = "OrderStep", - Value = "70", - Label = "Delivered", - Ordinal = 70, - DefaultVal = "#AEEA00", - InputType = "" - }; - - listValues.Add(listValObj); - listValObj = new ListValuesTempModel() - { - TableName = "All", - FieldName = "DoorDefStep", - Value = "10", - Label = "Door", - Ordinal = 10, - DefaultVal = "#448AFF", - InputType = "" - }; - listValues.Add(listValObj); - listValObj = new ListValuesTempModel() - { - TableName = "All", - FieldName = "DoorDefStep", - Value = "20", - Label = "Hardware", - Ordinal = 20, - DefaultVal = "#448AFF", - InputType = "" - }; - listValues.Add(listValObj); - listValObj = new ListValuesTempModel() - { - TableName = "All", - FieldName = "DoorDefStep", - Value = "30", - Label = "Report", - Ordinal = 30, - DefaultVal = "#448AFF", - InputType = "" - }; - listValues.Add(listValObj); - - // parto con obj base - sizeVal = fIniDef.ReadString("Size", "Width", "0.0"); - - listValObj = new ListValuesTempModel() - { - TableName = "Size", - FieldName = "DoorDef", - Value = "Width", - Label = "50001", - Ordinal = 1, - DefaultVal = sizeVal, - InputType = "TextBox", - isSerializable = true - }; - listValues.Add(listValObj); - sizeVal = fIniDef.ReadString("Size", "Height", "0.0"); - listValObj = new ListValuesTempModel() - { - TableName = "Size", - FieldName = "DoorDef", - Value = "Height", - Label = "50002", - Ordinal = 2, - DefaultVal = sizeVal, - InputType = "TextBox", - isSerializable = true - }; - listValues.Add(listValObj); - sizeVal = fIniDef.ReadString("Size", "Thickness", "0.0"); - listValObj = new ListValuesTempModel() - { - TableName = "Size", - FieldName = "DoorDef", - Value = "Thickness", - Label = "50003", - Ordinal = 3, - DefaultVal = sizeVal, - InputType = "TextBox", - isSerializable = true - }; - listValues.Add(listValObj); - sizeVal = fIniDef.ReadString("Size", "SwingList", "UNDEF"); - listValObj = new ListValuesTempModel() - { - TableName = "Swing", - FieldName = "DoorDef", - Value = "Swing", - Label = "50004", - Ordinal = 1, - DefaultVal = sizeVal, - InputType = "TextBox", - isSerializable = true - }; - listValues.Add(listValObj); - //sizeVal = fIniDef.ReadString("Edge", "EdgeTypeList", "UNDEF"); - StringBuilder edgesList = new StringBuilder(); - for (int x = 1; x <= 11; x++) - { - var edge = fIniDef.ReadString("Edge", $"EdgeType{x}", "UNDEF"); - if (x != 11) - { - edgesList.Append($"{edge.Split("/")[0]},"); - } - else - { - edgesList.Append($"{edge.Split("/")[0]}"); - } - } - listValObj = new ListValuesTempModel() - { - TableName = "Profiles", - FieldName = "DoorDef", - Value = "lockedge", - Label = "50005", - Ordinal = 1, - DefaultVal = "", - InputType = "", - isSerializable = true - }; - listValues.Add(listValObj); - listValObj = new ListValuesTempModel() - { - TableName = "Profiles", - FieldName = "DoorDef", - Value = "hingeedge", - Label = "50006", - Ordinal = 2, - DefaultVal = "", - InputType = "", - isSerializable = true - }; - listValues.Add(listValObj); - listValObj = new ListValuesTempModel() - { - TableName = "Profiles", - FieldName = "DoorDef", - Value = "top", - Label = "50007", - Ordinal = 3, - DefaultVal = "", - InputType = "", - isSerializable = true - }; - listValues.Add(listValObj); - listValObj = new ListValuesTempModel() - { - TableName = "Profiles", - FieldName = "DoorDef", - Value = "bottom", - Label = "50008", - Ordinal = 4, - DefaultVal = "", - InputType = "", - isSerializable = true - }; - listValues.Add(listValObj); - listValObj = new ListValuesTempModel() - { - TableName = "Profiles", - FieldName = "DoorDef", - Value = "type", - Label = "50424", - Ordinal = 5, - DefaultVal = edgesList.ToString(), - InputType = "ComboBox", - isSerializable = true - }; - listValues.Add(listValObj); - listValObj = new ListValuesTempModel() - { - TableName = "Profiles", - FieldName = "DoorDef", - Value = "machining", - Label = "90312", - Ordinal = 6, - DefaultVal = "ON,OFF", - InputType = "ComboBox", - isSerializable = true - }; - listValues.Add(listValObj); - listValObj = new ListValuesTempModel() - { - TableName = "Profiles", - FieldName = "DoorDef", - Value = "overmaterial", - Label = "90312", - Ordinal = 7, - DefaultVal = "0.1", - InputType = "ComboBox", - isSerializable = true - }; - listValues.Add(listValObj); - int i = 0; - - - foreach (string dir in dirs) - { - int numPar = 1; - int numHead = 1; - // scansione della directory... - string[] files = Directory.GetFiles(dir, "Config.ini"); - - compoName = ""; - //iterazione per cercare tutti numPar file "Config.ini" nelle sotto directory - foreach (string file in files) - { - //leggo tutte le linee del file - List lines = File.ReadAllLines(file).ToList(); - IniFile fIni = new IniFile(file); - Guid opCode = Guid.NewGuid(); - //cerco la sezione del file ed estraggo il nome del componente - compoName = fIni.ReadString("Compo", "Name", "COMPONAME"); - //cerco la sezione del file ed estraggo se numPar template sono attivi per il seguente componente - var isActive = fIni.ReadString("Template", "IsActive", "1"); - string layerName = fIni.ReadString("Layer", "LayerName", "LAYER"); - // lo slash indica l'alias - var compoNameSplit = compoName.Split("/"); - - var compoAcArray = listActiveCompo.ToArray(); - var x = Array.FindIndex(compoAcArray, row => row == compoNameSplit[0]); - - if (listActiveCompo.Contains(compoNameSplit[0].ToString())) - { - //creo il componente (padre) - listValObj = new ListValuesTempModel() - { - TableName = $"{compoNameSplit[0]}".Trim(), - FieldName = "Hardware", - Value = $"{compoNameSplit[0]}", - Label = $"{compoNameSplit[1]}", - Ordinal = x, - DefaultVal = " ", - InputType = " " - }; - //HardwareModel compoConfig = new HardwareModel() { compoName = $"{compoNameSplit[0]}", compoAlias = compoNameSplit[1].ToString(), compoLayerName = layerName, compoTemplateIsActive = compoTemplateIsActive }; - //await dbController.CompoAdd(compoConfig); - //listCompoS.Add(compoConfig); - listValues.Add(listValObj); - i++; - //cerco all'interno del file tutte le sezioni che contengono "[Graphic" così da poter prendere il nome della sezione ES: [Graphic parameters1] = Graphic parameters1 - var lineToSearch = lines.Where(x => x.Contains("[Graphic")).ToList(); - numHead = 1; - foreach (var match in lineToSearch) - { - var listV = await GraphicParamsGetAll(file, match, numHead, numPar, $"{compoNameSplit[0]}"); - - foreach (var item in listV) - { - listValues.Add(item); - } - - numHead++; - } - numPar++; - } - } - } - - fatto = await dbController.ListValuesAdd(listValues); - - return fatto; - } - - public string DecriptData(string encData) - { - return SteamCrypto.DecryptString(encData, Constants.passPhrase); - } - - /// - /// CElimina record posta - /// - /// - /// - public async Task DoorDelete(DoorModel currRec) - { - int DoorId = currRec.DoorId; - int OrderId = currRec.OrderId; - // elimino sul DB - bool answ = await dbController.DoorDelete(DoorId); - // svuoto cache - await DoorFlushCache(DoorId); - await DoorOpFlushCache(DoorId); - await OrderDetailFlushCache(OrderId); - await OrdersFlushCache(); - return answ; - } - - /// - /// Clean redis DOORS cache - /// - /// 0 = all - /// - public async Task DoorFlushCache(int DoorId) - { - RedisValue pattern = new RedisValue($"{Constants.rKeyDoor}:*"); - if (DoorId > 0) - { - pattern = new RedisValue($"{Constants.rKeyDoor}:{DoorId}:*"); - } - bool answ = await ExecFlushRedisPattern(pattern); - return answ; - } - - /// - /// Doors list, last in desc order - /// - public async Task?> DoorGetLast(int numRec) - { - string source = "DB"; - List? dbResult = new List(); - // cerco da cache - string currKey = $"{Constants.rKeyDoorLast}:{numRec}"; - 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.DoorsGetLast(numRec); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - await redisDb.StringSetAsync(currKey, rawData, FastCache); - } - if (dbResult == null) - { - dbResult = new List(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"DoorGetLast | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - /// - /// Doors list by numRec - /// - public async Task?> DoorGetByOrderId(int orderId) - { - string source = "DB"; - List? dbResult = new List(); - // cerco da cache - string currKey = $"{Constants.rKeyOrderDetail}:{orderId}"; - 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.DoorsGetByOrderId(orderId); - 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($"DoorGetByOrderId | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - - /// - /// Add door - /// - /// - /// - public async Task DoorInsert(DoorModel newRec) - { - var dbResult = await dbController.DoorInsert(newRec); - // elimino cache redis dati ordine... - await OrderDetailFlushCache(newRec.OrderId); - await OrdersFlushCache(); - return dbResult; - } - - /// - /// Adding or removing a single door - /// - /// Record id to edit or add - /// States if it has to be added or removing a door - /// - public async Task DoorModQty(int NewQty, int OrderId, int DoorId, bool isAdd) - { - var dbResult = await dbController.DoorModQty(NewQty, DoorId, isAdd); - // svuoto cache - await DoorFlushCache(DoorId); - await DoorOpFlushCache(DoorId); - await OrderDetailFlushCache(OrderId); - 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; - } - - /// - /// Clean redis DOORS OP cache - /// - /// 0 = all - /// - public async Task DoorOpFlushCache(int DoorId) - { - RedisValue pattern = new RedisValue($"{Constants.rKeyDoorOp}*"); - if (DoorId > 0) - { - pattern = new RedisValue($"{Constants.rKeyDoorOp}:{DoorId}*"); - } - bool answ = await ExecFlushRedisPattern(pattern); - return answ; - } - - /// - /// Doors list by numRec - /// - public async Task> DoorOpGetByDoorId(int doorId) - { - string source = "DB"; - List? dbResult = new List(); - // cerco da cache - string currKey = $"{Constants.rKeyDoorOp}:{doorId}"; - 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.DoorOpGetByDoorId(doorId); - 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($"DoorOpGetByDoorId | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - /// - /// Doors list by numRec - /// - public async Task DoorOpGetById(int doorOpId) - { - await Task.Delay(1); - string source = "DB"; - DoorOpModel? dbResult = new DoorOpModel(); - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - dbResult = dbController.DoorOpGetById(doorOpId); - if (dbResult == null) - { - dbResult = new DoorOpModel(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"DoorOpGetById | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - - /// - /// lista DoorOpList necessarie all'init - /// - /// - public async Task> DoorOpGetDefault() - { - List? dbResult = new List(); - string source = "DB"; - // cerco da cache - string currKey = $"{Constants.rKeyDoorOpType}:DEFAULT"; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - dbResult = await dbController.DoorOpTypeGetDefault(); - if (dbResult == null) - { - dbResult = new List(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"DoorOpGetDefault | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - - /// - /// Restitusice i CurrVals + GraphParams aggiornati dati valori Folder/template - /// - /// Obj x cui è richiesto il ricalcolo parametri - /// Dizionario dei valori attuali - /// Dizionario di obj x GraphParams - /// - public async Task<(Dictionary, Dictionary>)> DoorOpGetUpdatedVals(string ObjectId, Dictionary currVal, Dictionary> currParams, string currTemplShape) - { - await Task.Delay(1); - // duplico oggetti da tornare - Dictionary currValUpd = new Dictionary(); - Dictionary> currParamsUpd = new Dictionary>(); - string default2Design = ""; - // cerco il setup del template selezionato - var listRecordTmp = await ListValuesGetAll(ObjectId, currTemplShape); - if (listRecordTmp != null && currVal.ContainsKey("Folder") && currVal.ContainsKey(currTemplShape)) - { - string actKey = currVal[currTemplShape]; - var firstTemplate = listRecordTmp.Where(x => x.Value == actKey).FirstOrDefault(); - if (firstTemplate != null) - { - if (firstTemplate.DefaultVal != "") - { - default2Design = firstTemplate.DefaultVal; - } - else - { - default2Design = "1"; - } - } - // elimino dai valori di setup e attuali quanto non sia template/folder... - currValUpd = currVal.Where(x => x.Key == "Folder" || x.Key == currTemplShape).ToDictionary(x => x.Key, x => x.Value); - // preparo setup valori - List listDefVal = new List(); - var listRecordGP = await ListValuesGetAll(ObjectId, $"Graphic Parameters{default2Design}"); - if (listRecordGP != null) - { - foreach (var item in listRecordGP) - { - if (item.isSerializable && item.DefaultVal.Contains(",")) - { - listDefVal = item.DefaultVal.Trim().Split(",").ToList(); - currValUpd.Add(item.Value.Trim(), item.DefaultVal.Trim().Split(",")[0].Split("/")[0]); - } - else - { - if (item.DefaultVal.Contains("/")) - { - listDefVal = new List() { item.DefaultVal.Trim().Split("/")[0] }; - currValUpd.Add(item.Value.Trim(), item.DefaultVal.Trim().Split("/")[0]); - } - else - { - listDefVal = new List() { item.DefaultVal.Trim() }; - currValUpd.Add(item.Value.Trim(), item.DefaultVal.Trim()); - } - } - //defaultParamsList.Add(listDefVal); - currParamsUpd.Add(item.Value.Trim(), listDefVal); - } - } - } - return (currValUpd, currParamsUpd); - } - - /// - /// Add doorOP list - /// - /// - /// - /// - public async Task DoorOpInsert(int DoorId, List newOpList) - { - var dbResult = await dbController.DoorOpInsert(newOpList); - // elimino cache redis dati porta... - bool answ = await DoorOpFlushCache(DoorId); - answ = answ && await DoorFlushCache(DoorId); - // elimino cache redis dati ordine... - answ = answ && await OrdersFlushCache(); - return dbResult; - } - - /// - /// Effettua il setup dei Graph parameters date info template selezionato - /// - /// - /// - public async Task DoorOpSetupGraphParams(DoorOpModel currDoorOp) - { - string default2Design = ""; - Dictionary? actDict = new Dictionary(); - Dictionary? actDictNew = new Dictionary(); - Dictionary>? defaultDictNew = new Dictionary>(); - // per prima cosa deserializzo i valori attuali dal record... - if (!string.IsNullOrEmpty(currDoorOp.JsoncActVal)) - { - actDict = JsonConvert.DeserializeObject>(currDoorOp.JsoncActVal); - // verifico di avere valori validi - if (actDict != null) - { - // cerco il setup del template selezionato - var listRecordTmp = await ListValuesGetAll(currDoorOp.ObjectId, "template"); - if (listRecordTmp != null && actDict.ContainsKey("Folder") && (actDict.ContainsKey("template") || actDict.ContainsKey("shape"))) - { - string actKey = actDict["template"];// Path.Combine(actDict["Folder"], actDict["template"]); - var firstTemplate = listRecordTmp.Where(x => x.Value == actKey).FirstOrDefault(); - if (firstTemplate != null) - { - if (firstTemplate.DefaultVal != "") - { - default2Design = firstTemplate.DefaultVal; - } - else - { - default2Design = "1"; - } - } - // elimino dai valori di setup e attuali quanto non sia template/folder... - actDictNew = actDict.Where(x => x.Key == "Folder" || x.Key == "template").ToDictionary(x => x.Key, x => x.Value); - // preparo setup valori - List listDefVal = new List(); - var listRecordGP = await ListValuesGetAll(currDoorOp.ObjectId, $"Graphic Parameters{default2Design}"); - if (listRecordGP != null) - { - foreach (var item in listRecordGP) - { - if (item.isSerializable && item.DefaultVal.Contains(",")) - { - listDefVal = item.DefaultVal.Trim().Split(",").ToList(); - actDictNew.Add(item.Value.Trim(), item.DefaultVal.Trim().Split(",")[0].Split("/")[0]); - } - else - { - if (item.DefaultVal.Contains("/")) - { - listDefVal = new List() { item.DefaultVal.Trim().Split("/")[0] }; - actDictNew.Add(item.Value.Trim(), item.DefaultVal.Trim().Split("/")[0]); - } - else - { - listDefVal = new List() { item.DefaultVal.Trim() }; - actDictNew.Add(item.Value.Trim(), item.DefaultVal.Trim()); - } - } - //defaultParamsList.Add(listDefVal); - defaultDictNew.Add(item.Value.Trim(), listDefVal); - } - } - // ri-serializzo e salvo! - currDoorOp.JsoncActVal = JsonConvert.SerializeObject(actDictNew); - currDoorOp.JsoncConfigVal = JsonConvert.SerializeObject(defaultDictNew); - } - } - } - return currDoorOp; - } - - /// - /// Doors list by numRec - /// - public async Task?> DoorOpTypeGetAll() - { - await Task.Delay(1); - string source = "DB"; - List? dbResult = new List(); - // cerco da cache - string currKey = $"{Constants.rKeyDoorOpType}"; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - 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 - /// - /// - /// - public async Task DoorOpUpdate(List currDoorOps) - { - var dbResult = await dbController.DoorOpUpdate(currDoorOps); - // elimino cache redis dati porta... - bool answ = await DoorOpFlushCache(currDoorOps.FirstOrDefault()!.DoorId); - answ = answ && await DoorFlushCache(currDoorOps.FirstOrDefault()!.DoorId); - // elimino cache redis dati ordine... - answ = answ && await OrdersFlushCache(); - return dbResult; - } - - /// - /// Update or add door - /// - /// - /// - public async Task DoorUpsert(DoorModel currRec) - { - var dbResult = await dbController.DoorUpsert(currRec); - // elimino cache redis dati porta... - bool answ = await DoorFlushCache(currRec.DoorId); - // elimino cache redis dati ordine... - answ = answ && await OrdersFlushCache(); - return dbResult; - } - - public string EncriptData(string rawData) - { - return SteamCrypto.EncryptString(rawData, Constants.passPhrase); - } - - public async Task FlushRedisCache() - { - await Task.Delay(1); - RedisValue pattern = new RedisValue($"{Constants.redisBaseAddr}*"); - bool answ = await ExecFlushRedisPattern(pattern); - return answ; - } - - public async Task> GraphicParamsGetAll(string file, string match, int n, int i, string HwCode) - { - await Task.Delay(1); - 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)); - //controllo se tra numPar numeri di graphic params vi è un buco ES: Graphic parameters1 Graphic parameters3 se il buco c'è salto tutti numPar parametri che stanno dopo il buco ==> tengo conto solo di Graphic parameters1 - if (int.Parse(match.Substring(match.Length - 2, 1)) == n) - { - int ordinal = 1; - foreach (string param in graphicParamsName) - { - string compoParams = fIni.ReadString(match.Substring(1, match.Length - 2), $"{param.Split("=")[0]}", "CONFIG"); //cerco il parametro nella sezione - var compoParamsSplit = compoParams.Split(";"); - - string CompoParamName = ""; - string CompoParamAlias = ""; - if (param.Split("=")[0].StartsWith("Param")) - { - if (compoParamsSplit[1].Contains("/")) - { - CompoParamName = compoParamsSplit[1].Split("/")[0]; - CompoParamAlias = compoParamsSplit[1].Split("/")[1]; - } - else if (compoParamsSplit[1].Contains(" ")) - { - CompoParamName = compoParamsSplit[1].Split(" ")[1]; - //CompoParamAlias = compoParamsSplit[1].Split(" ")[1]; - } - - //creo nuovo oggetto parametro che conterrà anche il nome del componente per creare relazione - - listValObj = new ListValuesTempModel() - { - TableName = $"{HwCode}".Trim(), - FieldName = match.Substring(1, match.Length - 2), - Value = CompoParamName, - Label = CompoParamAlias, - Ordinal = ordinal, - DefaultVal = param.Split("=")[1].Split(";")[2], - InputType = param.Split("=")[1].Split(";")[0], - isSerializable = true - }; - - if (listValuesTemp.Where(x => x.TableName == listValObj.TableName && x.FieldName == listValObj.FieldName && x.Value == listValObj.Value).Count() == 0 && listValObj.TableName != null && listValObj.FieldName != null && listValObj.Value != null) - { - listValuesTemp.Add(listValObj); - ordinal++; - } - else - { - Log.Error($"GraphicParamsGetAll | Duplicated key: {listValObj.TableName} {listValObj.FieldName} {listValObj.Value} "); - } - } - else - { - } - } - } - - 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 - /// - public async Task?> ListValuesGetAll(string tableName, string fieldName) - { - string source = "DB"; - - List? dbResult = new List(); - string currKey = ""; - // cerco da cache - currKey = $"{Constants.rKeyListValues}:{tableName}:{fieldName}"; - - 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.ListValuesGetAll(tableName, fieldName); - 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($"ListValuesGetAll | {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 compoTempOrShape = ""; - 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"); - var compoT = fIni.ReadString("Template", "Name", "TEMPSHAPE"); - compoCode = compoName.Split("/")[0].Trim(); - compoTempOrShape = compoT.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]}", - Label = @$"{tName[tName.Length - 1]}", - Ordinal = 0, - DefaultVal = " ", - InputType = " ", - }; - values.Add(folderNames); - } - - foreach (string templateFile in templateFiles) - { - string defGpNum = ""; - var lines = File.ReadAllLines(templateFile).ToList(); - - foreach (var line in lines) - { - if (line.StartsWith("--") && line.Contains("Default")) - { - if (line.Split("=")[1] != null) - { - defGpNum = line.Split("=")[1]; - } - else - { - defGpNum = " "; - } - } - } - - var fileName = ""; - if (Path.GetFileName(templateFile).Split(".")[1] == "lua") - { - fileName = Path.GetFileName(templateFile).Split(".")[0]; - } - else - { - fileName = Path.GetFileName(templateFile); - } - - ListValuesTempModel temp = new ListValuesTempModel() - { - TableName = $"{compoCode}".Replace(" ", "_"), - FieldName = compoTempOrShape, - Value = @$"{tName[tName.Length - 1]}\{fileName}", - Label = fileName, - Ordinal = ordin, - DefaultVal = defGpNum, - 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; - } - - /// - /// Add new order - /// - /// - /// - public async Task OrderAdd(OrderModel currRec) - { - var dbResult = await dbController.OrderAdd(currRec); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{Constants.rKeyOrderStatus}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - return dbResult; - } - - /// - /// Clean REDIS order detail data in cache - /// - /// 0 = all - /// - public async Task OrderDetailFlushCache(int OrderId) - { - RedisValue pattern = new RedisValue($"{Constants.rKeyOrderDetail}:*"); - if (OrderId > 0) - { - pattern = new RedisValue($"{Constants.rKeyOrderDetail}:{OrderId}"); - } - bool answ = await ExecFlushRedisPattern(pattern); - return answ; - } - - /// - /// Remove order - /// - /// - /// - public async Task OrderRem(int OrdId) - { - var dbResult = await dbController.OrderRem(OrdId); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{Constants.rKeyOrderStatus}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - return dbResult; - } - - /// - /// Clean redis ORDERS cache - /// - /// - /// - public async Task OrdersFlushCache() - { - RedisValue pattern = new RedisValue($"{Constants.rKeyOrderStatus}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - return answ; - } - - public async Task?> OrderStatusGetFilt(int companyId, int orderStatus, DateTime dataFrom, DateTime dataTo) - { - string source = "DB"; - - List? dbResult = new List(); - // cerco da cache - string currKey = $"{Constants.rKeyOrderStatus}:{companyId}:{orderStatus}:{dataFrom:yyyyMMdd}:{dataTo:yyyyMMdd}"; - 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 - { - var rawResult = dbController.OrderStatusGetAll(companyId, orderStatus, dataFrom, dataTo); - // ordino desc in ram... - dbResult = rawResult.OrderByDescending(x => x.OrderId).ToList(); - 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($"OrderStatusGetFilt | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - - /// - /// Updating an order status - /// - /// - /// - /// - public async Task OrderUpdate(int orderId, int newStatus) - { - var dbResult = await dbController.OrderUpdate(orderId, newStatus); - // elimino cache redis... - //bool answ = await DoorFlushCache(currRec.doorId); - // elimino cache redis dati ordine... - bool answ = await FlushRedisCache(); - return dbResult; - } - - /// - /// Graphic parameters list by hw id - /// - public async Task?> ParamGetByHwId(int hwId) - { - string source = "DB"; - - List? dbResult = new List(); - // cerco da cache - string currKey = $"{Constants.rKeyGraphicParameters}:{hwId}"; - 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.ParamGetByHwId(hwId); - 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($"ParamGetByHwId | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - - /// - /// roles list - /// - public async Task?> RolesGetAll() - { - string source = "DB"; - - List? dbResult = new List(); - // cerco da cache - string currKey = Constants.rKeyRoles; - 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.RolesGetAll(); - 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($"RolesGetAll | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - - /// - /// Users roles list - /// - public async Task?> UsersGetAll() - { - string source = "DB"; - - List? dbResult = new List(); - // cerco da cache - string currKey = Constants.rKeyUsers; - 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.UsersGetAll(); - 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($"UsersGetAll | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - - /// - /// Users roles list - /// - public async Task UsersGetById(string userId) - { - string source = "DB"; - - AspNetUsers dbResult = new AspNetUsers(); - // cerco da cache - string currKey = $"{Constants.rKeyUsers}:{userId}"; - 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 AspNetUsers(); - } - else - { - dbResult = tempResult; - } - } - else - { - dbResult = dbController.UsersGetById(userId); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); - } - if (dbResult == null) - { - dbResult = new AspNetUsers(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"UsersGetById | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - - /// - /// Users roles list - /// - public async Task?> UserViewGetAll() - { - string source = "DB"; - - List? dbResult = new List(); - // cerco da cache - string currKey = Constants.rKeyUsersView; - 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.UserViewGetAll(); - 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($"UserViewGetAll | {source} in: {ts.TotalMilliseconds} ms"); - 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; - } - - public async Task createDoor(int idOrd, string userId, string currMeaUnit) - { - int answ = 0; - - // conto le porte x questo ordine e uso x chiamata successiva... - var door4ord = await DoorGetByOrderId(idOrd); - int numDoors = door4ord?.Count + 1 ?? 1; - List listOp = new List(); - DateTime adesso = DateTime.Now; - // creo una nuova porta... - DoorModel newDoor = new DoorModel() - { - OrderId = idOrd, - MeasureUnit = currMeaUnit, - UserIdIns = userId, - UserIdMod = userId, - UserIdLock = userId, - DateIns = adesso, - DateMod = adesso, - DateLockExpiry = adesso.AddHours(1), - DoorDescript = $"ORD {idOrd} | Door {numDoors:00}", - DoorExtCode = $"ORD {idOrd} | Ext Code --", - Quantity = 1, - UnitCost = 0, - TypeId = 1 - }; - // chiamo metodo x insert... - var doorId = await DoorInsert(newDoor); - // aggiungo le lavorazioni standard... - var doorOpList = await DoorOpGetDefault(); - var listRecordEdge = await ListValuesGetAll("Profiles", "DoorDef"); - var listRecordSizing = await ListValuesGetAll("Size", "DoorDef"); - var listRecordSwing = await ListValuesGetAll("Swing", "DoorDef"); - var listRecordProperties = await ListValuesGetAll("Properties", "DoorDef"); - var listRecordFinishing = await ListValuesGetAll("Finishing", "DoorDef"); - ListValuesModel? profCurrType = null; - ListValuesModel? profCurrMach = null; - ListValuesModel? profCurrOverMat = null; - if (listRecordEdge != null) - { - profCurrType = listRecordEdge.Where(x => x.Value == "type").FirstOrDefault(); - profCurrMach = listRecordEdge.Where(x => x.Value == "machining").FirstOrDefault(); - profCurrOverMat = listRecordEdge.Where(x => x.Value == "overmaterial").FirstOrDefault(); - } - Dictionary>> itemsDictDef = new Dictionary>>(); - Dictionary> itemsDictAct = new Dictionary>(); - Dictionary> paramsDict = new Dictionary>(); - Dictionary actDict = new Dictionary(); - List listDefVal = new List(); - List listDefValCurrMach = new List(); - List listDefValOverMat = new List(); - List defaultParamsList = new List(); - - #region Gestione Properties - - if (listRecordProperties != null) - { - foreach (var item in listRecordProperties) - { - foreach (var param in item.DefaultVal.Split(",")) - { - listDefVal.Add(param.Trim()); - if (!actDict.ContainsKey(item.Value)) - { - actDict.Add(item.Value, item.DefaultVal.Trim().Split(",")[0]); - paramsDict.Add(item.Value, listDefVal); - } - //itemsDict.Add(item.Value, paramsDict); - //paramsDict.Clear(); - - } - - //listDefVal = new List() { item.DefaultVal.Trim() }; - - } - itemsDictDef.Add("Properties", paramsDict); - itemsDictAct.Add("Properties", actDict); - //defaultParamsList.Add(listDefVal); - } - var jsonDef = JsonConvert.SerializeObject(itemsDictDef); - var jsonAct = JsonConvert.SerializeObject(itemsDictAct); - - DoorOpModel doorOpToAdd = new DoorOpModel() - { - DateIns = adesso, - DateMod = adesso, - UserIdIns = userId, - UserIdMod = userId, - ObjectId = "Properties", - DoorId = doorId, - JsoncConfigVal = jsonDef, - JsoncActVal = jsonAct, - userConfirm = userId, - DtConfirm = adesso - }; - listOp.Add(doorOpToAdd); - - #endregion Gestione Properties - - paramsDict.Clear(); - actDict.Clear(); - itemsDictDef.Clear(); - itemsDictAct.Clear(); - listDefVal.Clear(); - - #region Gestione Finishing - - if (listRecordFinishing != null) - { - foreach (var item in listRecordFinishing) - { - foreach (var param in item.DefaultVal.Split(",")) - { - listDefVal.Add(param.Trim()); - if (!actDict.ContainsKey(item.Value)) - { - actDict.Add(item.Value, item.DefaultVal.Trim().Split(",")[0]); - paramsDict.Add(item.Value, listDefVal); - } - //itemsDict.Add(item.Value, paramsDict); - //paramsDict.Clear(); - - } - - //listDefVal = new List() { item.DefaultVal.Trim() }; - - } - itemsDictDef.Add("Finishing", paramsDict); - itemsDictAct.Add("Finishing", actDict); - //defaultParamsList.Add(listDefVal); - } - jsonDef = JsonConvert.SerializeObject(itemsDictDef); - jsonAct = JsonConvert.SerializeObject(itemsDictAct); - - doorOpToAdd = new DoorOpModel() - { - DateIns = adesso, - DateMod = adesso, - UserIdIns = userId, - UserIdMod = userId, - ObjectId = "Finishing", - DoorId = doorId, - JsoncConfigVal = jsonDef, - JsoncActVal = jsonAct, - userConfirm = userId, - DtConfirm = adesso - }; - listOp.Add(doorOpToAdd); - - #endregion Gestione Finishing - - paramsDict.Clear(); - actDict.Clear(); - itemsDictDef.Clear(); - itemsDictAct.Clear(); - listDefVal.Clear(); - - #region Gestione sizing - - if (listRecordSizing != null) - { - foreach (var item in listRecordSizing) - { - listDefVal = new List() { item.DefaultVal.Trim() }; - if (!actDict.ContainsKey(item.Value)) - { - actDict.Add(item.Value, item.DefaultVal.Trim()); - paramsDict.Add(item.Value, listDefVal); - } - } - itemsDictDef.Add("Size", paramsDict); - itemsDictAct.Add("Size", actDict); - //defaultParamsList.Add(listDefVal); - } - jsonDef = JsonConvert.SerializeObject(itemsDictDef); - jsonAct = JsonConvert.SerializeObject(itemsDictAct); - - doorOpToAdd = new DoorOpModel() - { - DateIns = adesso, - DateMod = adesso, - UserIdIns = userId, - UserIdMod = userId, - ObjectId = "Size", - DoorId = doorId, - JsoncConfigVal = jsonDef, - JsoncActVal = jsonAct, - userConfirm = userId, - DtConfirm = adesso - }; - listOp.Add(doorOpToAdd); - - #endregion Gestione sizing - - paramsDict.Clear(); - actDict.Clear(); - itemsDictDef.Clear(); - itemsDictAct.Clear(); - listDefVal.Clear(); - - #region Gestione Swing - - if (listRecordSwing != null) - { - foreach (var item in listRecordSwing) - { - foreach (var param in item.DefaultVal.Split(",")) - { - listDefVal.Add(param.Trim()); - if (!actDict.ContainsKey(item.Value)) - { - actDict.Add(item.Value, item.DefaultVal.Trim().Split(",")[0]); - paramsDict.Add(item.Value, listDefVal); - } - //itemsDict.Add(item.Value, paramsDict); - //paramsDict.Clear(); - - } - - //listDefVal = new List() { item.DefaultVal.Trim() }; - - } - itemsDictDef.Add("Swing", paramsDict); - itemsDictAct.Add("Swing", actDict); - //defaultParamsList.Add(listDefVal); - } - jsonDef = JsonConvert.SerializeObject(itemsDictDef); - jsonAct = JsonConvert.SerializeObject(itemsDictAct); - - doorOpToAdd = new DoorOpModel() - { - DateIns = adesso, - DateMod = adesso, - UserIdIns = userId, - UserIdMod = userId, - ObjectId = "Swing", - DoorId = doorId, - JsoncConfigVal = jsonDef, - JsoncActVal = jsonAct, - userConfirm = userId, - DtConfirm = adesso - }; - listOp.Add(doorOpToAdd); - - #endregion Gestione Swing - - paramsDict.Clear(); - actDict.Clear(); - itemsDictDef.Clear(); - itemsDictAct.Clear(); - listDefVal.Clear(); - - - - #region Gestione Profiles - - if (listRecordEdge != null) - { - listDefVal.Clear(); - if (profCurrType != null) - { - foreach (var param in profCurrType.DefaultVal.Split(",")) - { - listDefVal.Add(param.Trim()); - if (!actDict.ContainsKey(profCurrType.Value)) - { - actDict.Add(profCurrType.Value, param.Trim()); - paramsDict.Add(profCurrType.Value, listDefVal); - //listDefVal.Clear(); - } - //itemsDict.Add(item.Value, paramsDict); - //paramsDict.Clear(); - } - if (profCurrMach != null) - { - //listDefVal.Clear(); - foreach (var param in profCurrMach.DefaultVal.Split(",")) - { - listDefValCurrMach.Add(param.Trim()); - if (!actDict.ContainsKey(profCurrMach.Value)) - { - paramsDict.Add(profCurrMach.Value, listDefValCurrMach); - actDict.Add(profCurrMach.Value, profCurrMach.DefaultVal.Trim().Split(",")[0]); - //listDefVal.Clear(); - } - //itemsDict.Add(item.Value, paramsDict); - //paramsDict.Clear(); - - } - } - if (profCurrOverMat != null) - { - //listDefVal.Clear(); - if (!paramsDict.ContainsKey(profCurrOverMat.Value)) - { - listDefValOverMat.Add(profCurrOverMat.DefaultVal.Trim()); - paramsDict.Add(profCurrOverMat.Value, listDefValOverMat); - actDict.Add(profCurrOverMat.Value, profCurrOverMat.DefaultVal.Trim()); - } - } - } - foreach (var item in listRecordEdge.Where(x => x.Value != "type" && x.Value != "machining" && x.Value != "overmaterial")) - { - if (!itemsDictDef.ContainsKey(item.Value)) - { - itemsDictDef.Add(item.Value, paramsDict); - } - if (!itemsDictAct.ContainsKey(item.Value)) - { - itemsDictAct.Add(item.Value, actDict); - } - //defaultParamsList.Add(listDefVal); - //defaultDict.Add(item.Label, listDefVal); - } - } - //actDict.Add(HwToShow.TableName, actParamsList); - - jsonDef = JsonConvert.SerializeObject(itemsDictDef); - jsonAct = JsonConvert.SerializeObject(itemsDictAct); - - doorOpToAdd = new DoorOpModel() - { - DateIns = adesso, - DateMod = adesso, - UserIdIns = userId, - UserIdMod = userId, - ObjectId = "Profiles", - DoorId = doorId, - JsoncConfigVal = jsonDef, - JsoncActVal = jsonAct, - userConfirm = userId, - DtConfirm = adesso - }; - listOp.Add(doorOpToAdd); - - #endregion Gestione Profiles - - // salvo Door OP associate - bool fatto = await DoorOpInsert(doorId, listOp); - - if (fatto) - { - answ = doorId; - } - - return answ; - } - #endregion Public Methods - - #region Protected Fields - - protected Random rnd = new Random(); - - #endregion Protected Fields - - #region Private Fields - - private static IConfiguration _configuration = null!; - - private static JsonSerializerSettings? JSSettings; - - private static Logger Log = LogManager.GetCurrentClassLogger(); - - private readonly IEmailSender _emailSender; - - /// - /// Durata cache lunga IN SECONDI - /// - private int cacheTtlLong = 60 * 5; - - /// - /// Durata cache breve IN SECONDI - /// - private int cacheTtlShort = 60 * 1; - - /// - /// Oggetto per connessione a REDIS - /// - private IConnectionMultiplexer redisConn; - - /// - /// Oggetto DB redis da impiegare x chiamate R/W - /// - private IDatabase redisDb = null!; - - #endregion Private Fields - - #region Private Properties - - /// - /// Durata cache lunga (+ perturbazione percentuale +/-10%) - /// - private TimeSpan FastCache - { - get => TimeSpan.FromSeconds(cacheTtlShort * rnd.Next(900, 1100) / 1000); - } - - /// - /// Durata cache lunga (+ perturbazione percentuale +/-10%) - /// - private TimeSpan LongCache - { - get => TimeSpan.FromSeconds(cacheTtlLong * rnd.Next(900, 1100) / 1000); - } - - /// - /// Durata cache lunga (+ perturbazione percentuale +/-10%) - /// - private TimeSpan UltraLongCache - { - get => TimeSpan.FromSeconds(cacheTtlLong * 10 * rnd.Next(900, 1100) / 1000); - } - - #endregion Private Properties - - #region Private Methods - - /// - /// Esegue flush memoria redis dato pattern - /// - /// - /// - private async Task ExecFlushRedisPattern(RedisValue pattern) - { - bool answ = false; - var listEndpoints = redisConn.GetEndPoints(); - foreach (var endPoint in listEndpoints) - { - //var server = redisConnAdmin.GetServer(listEndpoints[0]); - var server = redisConn.GetServer(endPoint); - if (server != null) - { - var keyList = server.Keys(redisDb.Database, pattern); - foreach (var item in keyList) - { - await redisDb.KeyDeleteAsync(item); - } - answ = true; - } - } - - return answ; - } - - public async Task FlushCustomPattern(string keyWord) - { - await Task.Delay(1); - RedisValue pattern = new RedisValue($"{Constants.redisBaseAddr}:{keyWord}"); - bool answ = await ExecFlushRedisPattern(pattern); - return answ; - } - - #endregion Private Methods - } -} \ No newline at end of file diff --git a/WebDoorCreator.UI/Pages/HwPdfConfirm.razor.cs b/WebDoorCreator.UI/Pages/HwPdfConfirm.razor.cs index f06f959..37bb141 100644 --- a/WebDoorCreator.UI/Pages/HwPdfConfirm.razor.cs +++ b/WebDoorCreator.UI/Pages/HwPdfConfirm.razor.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.WebUtilities; using Newtonsoft.Json; using WebDoorCreator.Data.DbModels; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Data; namespace WebDoorCreator.UI.Pages diff --git a/WebDoorCreator.UI/Pages/OrdersHomePage.razor.cs b/WebDoorCreator.UI/Pages/OrdersHomePage.razor.cs index 8f72ed0..67821f6 100644 --- a/WebDoorCreator.UI/Pages/OrdersHomePage.razor.cs +++ b/WebDoorCreator.UI/Pages/OrdersHomePage.razor.cs @@ -5,6 +5,7 @@ using Microsoft.JSInterop; using System; using System.Runtime.InteropServices; using WebDoorCreator.Data.DbModels; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Data; namespace WebDoorCreator.UI.Pages diff --git a/WebDoorCreator.UI/Pages/SuperAdmin.razor.cs b/WebDoorCreator.UI/Pages/SuperAdmin.razor.cs index 870f590..6960840 100644 --- a/WebDoorCreator.UI/Pages/SuperAdmin.razor.cs +++ b/WebDoorCreator.UI/Pages/SuperAdmin.razor.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.WebUtilities; using System.Text; using System.Text.Encodings.Web; using WebDoorCreator.Data.DbModels; +using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Data; namespace WebDoorCreator.UI.Pages diff --git a/WebDoorCreator.UI/Pages/TestAnim.razor b/WebDoorCreator.UI/Pages/TestAnim.razor index a37830d..1c4523f 100644 --- a/WebDoorCreator.UI/Pages/TestAnim.razor +++ b/WebDoorCreator.UI/Pages/TestAnim.razor @@ -1,5 +1,6 @@ -@using WebDoorCreator.UI.Components.SvgComp -@using WebDoorCreator.UI.Data +@using WebDoorCreator.Data.Services; +@using WebDoorCreator.UI.Components.SvgComp +@using WebDoorCreator.Data @page "/TestAnim" @inject WebDoorCreatorService WDCService diff --git a/WebDoorCreator.UI/Pages/TestPage.razor b/WebDoorCreator.UI/Pages/TestPage.razor index 975ee3d..df48b0b 100644 --- a/WebDoorCreator.UI/Pages/TestPage.razor +++ b/WebDoorCreator.UI/Pages/TestPage.razor @@ -1,4 +1,5 @@ -@using WebDoorCreator.UI.Components.SvgComp +@using WebDoorCreator.Data.Services; +@using WebDoorCreator.UI.Components.SvgComp @using WebDoorCreator.UI.Data @page "/TestPage" diff --git a/WebDoorCreator.UI/_Imports.razor b/WebDoorCreator.UI/_Imports.razor index 1e50b8f..50fc7e5 100644 --- a/WebDoorCreator.UI/_Imports.razor +++ b/WebDoorCreator.UI/_Imports.razor @@ -6,6 +6,9 @@ @using Microsoft.AspNetCore.Components.Web @using Microsoft.AspNetCore.Components.Web.Virtualization @using Microsoft.JSInterop +@using EgwCoreLib.Razor +@using WebDoorCreator.Data +@using WebDoorCreator.Data.DbModels @using WebDoorCreator.UI @using WebDoorCreator.UI.Components @using WebDoorCreator.UI.Components.Buttons @@ -20,7 +23,5 @@ @using WebDoorCreator.UI.Components.Filters @using WebDoorCreator.UI.Components.Report @using WebDoorCreator.UI.Shared -@using WebDoorCreator.Data.DbModels -@using EgwCoreLib.Razor