From eabc1997d359f7e3c089a13ac4ce24abb5c51e9d Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 4 Aug 2025 10:44:26 +0200 Subject: [PATCH] Update API x metodo mode 2 (BOM) --- .../Services/ImageCacheService.cs | 21 ++- Lux.API/Controllers/WindowController.cs | 165 ++++++++++++------ Lux.API/Lux.API.csproj | 2 +- Lux.API/Services/ExternalMessageProcessor.cs | 7 + Lux.UI/Lux.UI.csproj | 2 +- Resources/ChangeLog.html | 2 +- Resources/VersNum.txt | 2 +- Resources/manifest.xml | 2 +- 8 files changed, 139 insertions(+), 64 deletions(-) diff --git a/EgwCoreLib.Lux.Data/Services/ImageCacheService.cs b/EgwCoreLib.Lux.Data/Services/ImageCacheService.cs index 1c5e1bdf..b5bc7beb 100644 --- a/EgwCoreLib.Lux.Data/Services/ImageCacheService.cs +++ b/EgwCoreLib.Lux.Data/Services/ImageCacheService.cs @@ -95,7 +95,7 @@ namespace EgwCoreLib.Lux.Data.Services public async Task SaveSvgAsync(string imgId, string svgContent) { // salvo img in cache - string currKey = $"{redisBaseKey}:{imgId.Replace("/", ":")}"; + string currKey = $"{redisBaseKey}:Images:{imgId.Replace("/", ":")}"; var done = await _redisService.SetAsync(currKey, svgContent); // invio notifica nuova svg generata sul canale... viene inviato solo svg con ID nel canale string notifyChannel = $"{svgChannel}:{imgId}"; @@ -103,6 +103,22 @@ namespace EgwCoreLib.Lux.Data.Services return done; } + /// + /// Salva e invia su channel img redis SVG per il doc richiesto + /// + /// + /// + public async Task SaveBomAsync(string imgId, string bomContent) + { + // salvo img in cache + string currKey = $"{redisBaseKey}:BOM:{imgId.Replace("/", ":")}"; + var done = await _redisService.SetAsync(currKey, bomContent); + // invio notifica nuova svg generata sul canale... viene inviato solo svg con ID nel canale + string notifyChannel = $"{bomChannel}:{imgId}"; + long numSent = await _redisService.PublishAsync(notifyChannel, bomContent); + return done; + } + #endregion Public Methods #region Private Fields @@ -112,9 +128,10 @@ namespace EgwCoreLib.Lux.Data.Services private readonly string cacheTag = "svgfile"; private readonly string liveTag = "svg"; private readonly string svgChannel = "svg:img"; + private readonly string bomChannel = "bom:item"; private IConfiguration _config; private string imageBaseUrl = ""; - private string redisBaseKey = "Lux:Images"; + private string redisBaseKey = "Lux"; #endregion Private Fields } diff --git a/Lux.API/Controllers/WindowController.cs b/Lux.API/Controllers/WindowController.cs index 453cc62e..f2bd8dc2 100644 --- a/Lux.API/Controllers/WindowController.cs +++ b/Lux.API/Controllers/WindowController.cs @@ -24,14 +24,117 @@ namespace Lux.API.Controllers #region Public Methods + [Obsolete("Please use svg-preview")] + [HttpPost("calc/{id}")] + public async Task> calc(string id, [FromBody] string currJwd) + { + return await svgPreview(id, currJwd); + } + /// - /// Chiamata POST: riceve Json in formato JWD serializzato, lo ripete come risposta - /// PUT: api/calc/svg/00000000-0000-0000-0000-000000000000 + /// Chiamata POST: riceve Json in formato JWD serializzato, invia richeista calcolo modo 2 (BOM) + /// PUT: api/svgPreview/svg/00000000-0000-0000-0000-000000000000 /// /// id oggetto /// - [HttpPost("calc/{id}")] - public async Task> calc(string id, [FromBody] string currJwd) + [HttpPost("bom/{id}")] + public async Task> getBom(string id, [FromBody] string currJwd) + { + Stopwatch sw = new Stopwatch(); + sw.Start(); + string svgContent = ""; + + // se contiene ".svg" lo levo... + if (id.EndsWith(".svg")) + { + id = id.Replace(".svg", ""); + } + + // se messaggio vuoto --> uso default! + currJwd = string.IsNullOrEmpty(currJwd) ? demoJwd : currJwd; + + // ...se ricevo percorso --> leggo jwd/svg cablato + if (!string.IsNullOrEmpty(currJwd)) + { + if (true) + { + Dictionary DictExec = new Dictionary(); + DictExec.Add("Mode", "2"); + // UID cablato x ora... + DictExec.Add("UID", id); + DictExec.Add("Jwd", currJwd); + int nId = 1; + ProcessArgs currArgs = new ProcessArgs(nId, DictExec); + + await _redisService.PublishAsync(pubChannel, currArgs.sProcessArgs); + svgContent = "DONE"; + } + } + sw.Stop(); + Log.Info($"getBom | {sw.Elapsed.TotalMilliseconds:N3} ms"); + return Ok(svgContent); + } + + /// + /// Chiamata POST: riceve Json in formato JWD serializzato, lo ripete come risposta + /// PUT: api/svgPreview/svg/00000000-0000-0000-0000-000000000000 + /// + /// id oggetto + /// + [HttpGet("svg/{id}")] + public async Task> svg(string id) + { + Stopwatch sw = new Stopwatch(); + sw.Start(); + string svgContent = ""; + // ...se ricevo percorso --> leggo jwd/svg cablato + if (!string.IsNullOrEmpty(id)) + { + svgContent = _imgService.LoadSvg(id); + } + sw.Stop(); + Log.Info($"svgString | {sw.Elapsed.TotalMilliseconds:N3} ms"); + return Ok(svgContent); + } + + /// + /// Chiamata POST: riceve Json in formato JWD serializzato, lo ripete come risposta + /// PUT: api/svgPreview/svg/00000000-0000-0000-0000-000000000000 + /// + /// id oggetto + /// + [HttpGet("svgFile/{id}")] + public async Task> svgFile(string id) + { + Stopwatch sw = new Stopwatch(); + sw.Start(); + + if (string.IsNullOrEmpty(id)) + return NotFound(); + + // se contiene ".svg" lo levo... + if (id.EndsWith(".svg")) + { + id = id.Replace(".svg", ""); + } + + string svgContent = await _imgService.LoadSvgAsync(id); + byte[] bytes = System.Text.Encoding.UTF8.GetBytes(svgContent); + + sw.Stop(); + Log.Info($"svgString | {sw.Elapsed.TotalMilliseconds:N3} ms"); + + return File(bytes, "image/svg+xml"); + } + + /// + /// Chiamata POST: riceve Json in formato JWD serializzato, lo ripete come risposta + /// PUT: api/svg-preview/svg/00000000-0000-0000-0000-000000000000 + /// + /// id oggetto + /// + [HttpPost("svg-preview/{id}")] + public async Task> svgPreview(string id, [FromBody] string currJwd) { Stopwatch sw = new Stopwatch(); sw.Start(); @@ -64,62 +167,10 @@ namespace Lux.API.Controllers } } sw.Stop(); - Log.Info($"svgString | {sw.Elapsed.TotalMilliseconds:N3} ms"); + Log.Info($"calcSvg | {sw.Elapsed.TotalMilliseconds:N3} ms"); return Ok(svgContent); } - /// - /// Chiamata POST: riceve Json in formato JWD serializzato, lo ripete come risposta - /// PUT: api/calc/svg/00000000-0000-0000-0000-000000000000 - /// - /// id oggetto - /// - [HttpGet("svg/{id}")] - public async Task> svg(string id) - { - Stopwatch sw = new Stopwatch(); - sw.Start(); - string svgContent = ""; - // ...se ricevo percorso --> leggo jwd/svg cablato - if (!string.IsNullOrEmpty(id)) - { - svgContent = _imgService.LoadSvg(id); - } - sw.Stop(); - Log.Info($"svgString | {sw.Elapsed.TotalMilliseconds:N3} ms"); - return Ok(svgContent); - } - - /// - /// Chiamata POST: riceve Json in formato JWD serializzato, lo ripete come risposta - /// PUT: api/calc/svg/00000000-0000-0000-0000-000000000000 - /// - /// id oggetto - /// - [HttpGet("svgFile/{id}")] - public async Task> svgFile(string id) - { - Stopwatch sw = new Stopwatch(); - sw.Start(); - - if (string.IsNullOrEmpty(id)) - return NotFound(); - - // se contiene ".svg" lo levo... - if (id.EndsWith(".svg")) - { - id = id.Replace(".svg", ""); - } - - string svgContent = await _imgService.LoadSvgAsync(id); - byte[] bytes = System.Text.Encoding.UTF8.GetBytes(svgContent); - - sw.Stop(); - Log.Info($"svgString | {sw.Elapsed.TotalMilliseconds:N3} ms"); - - return File(bytes, "image/svg+xml"); - } - #endregion Public Methods #region Private Fields diff --git a/Lux.API/Lux.API.csproj b/Lux.API/Lux.API.csproj index 8eade94d..90453c2c 100644 --- a/Lux.API/Lux.API.csproj +++ b/Lux.API/Lux.API.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 0.9.2507.2308 + 0.9.2508.0410 diff --git a/Lux.API/Services/ExternalMessageProcessor.cs b/Lux.API/Services/ExternalMessageProcessor.cs index 013201a4..bfa5c545 100644 --- a/Lux.API/Services/ExternalMessageProcessor.cs +++ b/Lux.API/Services/ExternalMessageProcessor.cs @@ -45,6 +45,13 @@ namespace Lux.API.Services string UID = retData.Args["UID"]; await _cacheService.SaveSvgAsync(UID, newSvg); } + else if(retData.Args.ContainsKey("BOM")) + { + // salvo BOM ricevuta + string newBom = retData.Args["BOM"]; + string UID = retData.Args["UID"]; + await _cacheService.SaveBomAsync(UID, newBom); + } } } } diff --git a/Lux.UI/Lux.UI.csproj b/Lux.UI/Lux.UI.csproj index f17c1076..11022196 100644 --- a/Lux.UI/Lux.UI.csproj +++ b/Lux.UI/Lux.UI.csproj @@ -5,7 +5,7 @@ enable enable aspnet-Lux.UI-a758c101-a2f4-4e38-977d-1c4887dbbd50 - 0.9.2507.2308 + 0.9.2508.0410 diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html index 6d6a1cbe..1235b04f 100644 --- a/Resources/ChangeLog.html +++ b/Resources/ChangeLog.html @@ -1,6 +1,6 @@ LUX - Web Windows MES -

Versione: 0.9.2507.2308

+

Versione: 0.9.2508.0410


Note di rilascio:
  • diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt index 1b67a035..17ed0c3d 100644 --- a/Resources/VersNum.txt +++ b/Resources/VersNum.txt @@ -1 +1 @@ -0.9.2507.2308 +0.9.2508.0410 diff --git a/Resources/manifest.xml b/Resources/manifest.xml index ce04b36b..aa54b2f0 100644 --- a/Resources/manifest.xml +++ b/Resources/manifest.xml @@ -1,6 +1,6 @@ - 0.9.2507.2308 + 0.9.2508.0410 http://nexus.steamware.net/repository/SWS/GPW/stable/GPW.UI.zip http://nexus.steamware.net/repository/SWS/GPW/stable/ChangeLog.html false