Update API x metodo mode 2 (BOM)

This commit is contained in:
Samuele Locatelli
2025-08-04 10:44:26 +02:00
parent c3e44acf23
commit eabc1997d3
8 changed files with 139 additions and 64 deletions
@@ -95,7 +95,7 @@ namespace EgwCoreLib.Lux.Data.Services
public async Task<bool> 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;
}
/// <summary>
/// Salva e invia su channel img redis SVG per il doc richiesto
/// </summary>
/// <param name="imgId"></param>
/// <param name="bomContent"></param>
public async Task<bool> 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
}
+108 -57
View File
@@ -24,14 +24,117 @@ namespace Lux.API.Controllers
#region Public Methods
[Obsolete("Please use svg-preview")]
[HttpPost("calc/{id}")]
public async Task<ActionResult<string>> calc(string id, [FromBody] string currJwd)
{
return await svgPreview(id, currJwd);
}
/// <summary>
/// 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
/// </summary>
/// <param name="id">id oggetto</param>
/// <returns></returns>
[HttpPost("calc/{id}")]
public async Task<ActionResult<string>> calc(string id, [FromBody] string currJwd)
[HttpPost("bom/{id}")]
public async Task<ActionResult<string>> 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<string, string> DictExec = new Dictionary<string, string>();
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);
}
/// <summary>
/// Chiamata POST: riceve Json in formato JWD serializzato, lo ripete come risposta
/// PUT: api/svgPreview/svg/00000000-0000-0000-0000-000000000000
/// </summary>
/// <param name="id">id oggetto</param>
/// <returns></returns>
[HttpGet("svg/{id}")]
public async Task<ActionResult<string>> 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);
}
/// <summary>
/// Chiamata POST: riceve Json in formato JWD serializzato, lo ripete come risposta
/// PUT: api/svgPreview/svg/00000000-0000-0000-0000-000000000000
/// </summary>
/// <param name="id">id oggetto</param>
/// <returns></returns>
[HttpGet("svgFile/{id}")]
public async Task<ActionResult<string>> 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");
}
/// <summary>
/// Chiamata POST: riceve Json in formato JWD serializzato, lo ripete come risposta
/// PUT: api/svg-preview/svg/00000000-0000-0000-0000-000000000000
/// </summary>
/// <param name="id">id oggetto</param>
/// <returns></returns>
[HttpPost("svg-preview/{id}")]
public async Task<ActionResult<string>> 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);
}
/// <summary>
/// Chiamata POST: riceve Json in formato JWD serializzato, lo ripete come risposta
/// PUT: api/calc/svg/00000000-0000-0000-0000-000000000000
/// </summary>
/// <param name="id">id oggetto</param>
/// <returns></returns>
[HttpGet("svg/{id}")]
public async Task<ActionResult<string>> 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);
}
/// <summary>
/// Chiamata POST: riceve Json in formato JWD serializzato, lo ripete come risposta
/// PUT: api/calc/svg/00000000-0000-0000-0000-000000000000
/// </summary>
/// <param name="id">id oggetto</param>
/// <returns></returns>
[HttpGet("svgFile/{id}")]
public async Task<ActionResult<string>> 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
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>0.9.2507.2308</Version>
<Version>0.9.2508.0410</Version>
</PropertyGroup>
<ItemGroup>
@@ -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);
}
}
}
}
+1 -1
View File
@@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-Lux.UI-a758c101-a2f4-4e38-977d-1c4887dbbd50</UserSecretsId>
<Version>0.9.2507.2308</Version>
<Version>0.9.2508.0410</Version>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>LUX - Web Windows MES</i>
<h4>Versione: 0.9.2507.2308</h4>
<h4>Versione: 0.9.2508.0410</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
0.9.2507.2308
0.9.2508.0410
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>0.9.2507.2308</version>
<version>0.9.2508.0410</version>
<url>http://nexus.steamware.net/repository/SWS/GPW/stable/GPW.UI.zip</url>
<changelog>http://nexus.steamware.net/repository/SWS/GPW/stable/ChangeLog.html</changelog>
<mandatory>false</mandatory>