diff --git a/Lux.API/Controllers/JwdController.cs b/Lux.API/Controllers/JwdController.cs index b70fddcd..2739e3a0 100644 --- a/Lux.API/Controllers/JwdController.cs +++ b/Lux.API/Controllers/JwdController.cs @@ -1,4 +1,5 @@ -using Lux.Core.RestPayload; +using EgwMultiEngineManager; +using Lux.Core.RestPayload; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; @@ -11,15 +12,36 @@ namespace Lux.API.Controllers { #region Public Constructors - public JwdController(ILogger logger) + public JwdController(ILogger logger, ExecProcessManager EgwProcManager) { _logger = logger; + ProcessMan = EgwProcManager; } #endregion Public Constructors #region Public Methods + + /// + /// Chiamata GETT: riceve Json in formato JwdDto, restituisce svg file + /// GET: api/Jwd/svg/00000000-0000-0000-0000-000000000000 + /// + /// id univoco img + /// + [HttpGet("svg/{id}")] + public async Task svgFileGet(string id) + { + Stopwatch sw = new Stopwatch(); + sw.Start(); + string filePath = Path.Combine("DemoImg", "AntaDoppia.svg"); + var svgContent = await System.IO.File.ReadAllTextAsync(filePath); + var bytes = System.Text.Encoding.UTF8.GetBytes(svgContent); + sw.Stop(); + _logger.LogInformation($"svgString | {sw.Elapsed.TotalMilliseconds:N3} ms"); + return File(bytes, "image/svg+xml"); + } + /// /// Chiamata POST: riceve Json in formato JwdDto, restituisce jpeg file /// PUT: api/Jwd/svg/00000000-0000-0000-0000-000000000000 @@ -54,41 +76,6 @@ namespace Lux.API.Controllers return File(imageBytes, "image/png"); } - /// - /// Chiamata POST: riceve Json in formato JwdDto, restituisce svg file - /// PUT: api/Jwd/svg/00000000-0000-0000-0000-000000000000 - /// - /// token comunicazione - /// - [HttpPost("svgfile/{id}")] - public async Task svgFile(string id, [FromBody] Core.RestPayload.JwdDTO currJwd) - { - // finta attesa/elaborazione - await Task.Delay(waitDelay); - // path immagine finto... - string fakeImagePath = "DemoImg/Window01.svg"; - var svgContent = await System.IO.File.ReadAllTextAsync(fakeImagePath); - var bytes = System.Text.Encoding.UTF8.GetBytes(svgContent); - return File(bytes, "image/svg+xml"); - } - - /// - /// Chiamata POST: riceve Json in formato JwdDto, restituisce svg come string - /// PUT: api/Jwd/svg/00000000-0000-0000-0000-000000000000 - /// - /// token comunicazione - /// - [HttpPost("svg/{id}")] - public async Task> svgString(string id, [FromBody] Core.RestPayload.JwdDTO currJwd) - { - // finta attesa/elaborazione - await Task.Delay(waitDelay); - // path immagine finto... - string fakeImagePath = "DemoImg/Window01.svg"; - var svgContent = await System.IO.File.ReadAllTextAsync(fakeImagePath); - return Ok(svgContent); - } - /// /// Chiamata POST: riceve Json in formato JwdDto, restituisce una BOM completa /// PUT: api/Jwd/svg/00000000-0000-0000-0000-000000000000 @@ -117,7 +104,6 @@ namespace Lux.API.Controllers listItems.Add(item); } - BomDTO answ = new BomDTO() { UID = $"{DateTime.Now:yyyyMMdd-HHmmss}", @@ -128,13 +114,103 @@ namespace Lux.API.Controllers return Ok(answ); } + /// + /// Chiamata POST: riceve Json in formato JwdDto, restituisce svg file + /// PUT: api/Jwd/svg/00000000-0000-0000-0000-000000000000 + /// + /// token comunicazione + /// + [HttpPost("svgfile/{id}")] + public async Task svgFile(string id, [FromBody] Core.RestPayload.JwdDTO currJwd) + { + // finta attesa/elaborazione + await Task.Delay(waitDelay); + // path immagine finto... + string fakeImagePath = "DemoImg/Window01.svg"; + var svgContent = await System.IO.File.ReadAllTextAsync(fakeImagePath); + var bytes = System.Text.Encoding.UTF8.GetBytes(svgContent); + return File(bytes, "image/svg+xml"); + } + + /// + /// Chiamata POST: riceve Json in formato JwdDto, restituisce svg come string + /// PUT: api/Jwd/svg/00000000-0000-0000-0000-000000000000 + /// + /// token comunicazione + /// + [HttpPost("svg/{id}")] + public async Task> svgString(string id, [FromBody] Core.RestPayload.JwdDTO currJwd) + { + Stopwatch sw = new Stopwatch(); + sw.Start(); + string filePath = Path.Combine("DemoData", "AntaDoppia.jwd"); + string svgName = ""; + string rawData = ""; + string svgContent = ""; + // ...se ricevo percorso --> leggo jwd/svg cablato + if (!string.IsNullOrEmpty(currJwd.nameUrl)) + { + filePath = Path.Combine("DemoData", $"{currJwd.nameUrl}.jwd"); + svgName = Path.Combine("DemoImg", $"{currJwd.nameUrl}.svg"); + } + if (!string.IsNullOrEmpty(svgName)) + { + string fakeImagePath = $"DemoImg/{currJwd.nameUrl}.svg"; + svgContent = await System.IO.File.ReadAllTextAsync(fakeImagePath); + } + else + { + if (System.IO.File.Exists(filePath)) + { + rawData = System.IO.File.ReadAllText(filePath); + } + Dictionary DictExec = new Dictionary(); + DictExec.Add("Mode", "1"); + DictExec.Add("Jwd", rawData); + ProcessArgs currArgs = new ProcessArgs(1, DictExec); + bool done = ProcessMan.ArgumentsEnqueue(currArgs); + var res = ProcessMan.ArgumentsResultDequeue(); + int numWait = 50; + while (numWait > 0 && (res == null || res.nResult == 0)) + { + numWait--; + await Task.Delay(waitDelay); + res = ProcessMan.ArgumentsResultDequeue(); + } + // se ho risultato mostro... + if (res != null) + { + //svgContent = res. + } + else + { + // path immagine finto... + string fakeImagePath = "DemoImg/Window01.svg"; + svgContent = await System.IO.File.ReadAllTextAsync(fakeImagePath); + } + } + sw.Stop(); + _logger.LogInformation($"svgString | {sw.Elapsed.TotalMilliseconds:N3} ms"); + return Ok(svgContent); + } + #endregion Public Methods #region Private Fields private readonly ILogger _logger; + private int waitDelay = 250; #endregion Private Fields + + #region Private Properties + + /// + /// Esecutore di processi generico + /// + private ExecProcessManager ProcessMan { get; set; } + + #endregion Private Properties } } \ No newline at end of file diff --git a/Lux.API/DemoData/AntaDoppia.jwd b/Lux.API/DemoData/AntaDoppia.jwd new file mode 100644 index 00000000..fe1c70c2 --- /dev/null +++ b/Lux.API/DemoData/AntaDoppia.jwd @@ -0,0 +1,101 @@ +{ + "ProfilePath": "Profilo78", + "AreaList": [ + { + "Shape": "RECTANGLE", + "DimensionList": [ + { + "nIndex": 1, + "sName": "Width", + "dValue": 1200.0 + }, + { + "nIndex": 2, + "sName": "Height", + "dValue": 1500.0 + } + ], + "JointList": [ + { + "nIndex": 1, + "JointType": "FULL_V" + }, + { + "nIndex": 2, + "JointType": "FULL_V" + }, + { + "nIndex": 3, + "JointType": "FULL_V" + }, + { + "nIndex": 4, + "JointType": "FULL_V" + } + ], + "BottomRail": false, + "BottomRailQty": 0, + "AreaList": [ + { + "bIsSashVertical": true, + "SashList": [ + { + "OpeningType": "TURNONLY_LEFT", + "bHasHandle": false, + "dDimension": 50.0 + }, + { + "OpeningType": "TILTTURN_RIGHT", + "bHasHandle": true, + "dDimension": 50.0 + } + ], + "SashType": "NULL", + "JointList": [ + { + "nIndex": 1, + "JointType": "FULL_V" + }, + { + "nIndex": 2, + "JointType": "FULL_V" + }, + { + "nIndex": 3, + "JointType": "FULL_V" + }, + { + "nIndex": 4, + "JointType": "FULL_V" + } + ], + "Hardware": "000000", + "AreaList": [ + { + "AreaList": [ + { + "FillType": "GLASS", + "AreaList": [], + "AreaType": "FILL" + } + ], + "AreaType": "SPLITTED" + }, + { + "AreaList": [ + { + "FillType": "GLASS", + "AreaList": [], + "AreaType": "FILL" + } + ], + "AreaType": "SPLITTED" + } + ], + "AreaType": "SASH" + } + ], + "AreaType": "FRAME" + } + ] +} \ No newline at end of file diff --git a/Lux.API/DemoData/AntaSingola.jwd b/Lux.API/DemoData/AntaSingola.jwd new file mode 100644 index 00000000..3a189341 --- /dev/null +++ b/Lux.API/DemoData/AntaSingola.jwd @@ -0,0 +1,81 @@ +{ + "ProfilePath": "Profilo78", + "AreaList": [ + { + "Shape": "RECTANGLE", + "DimensionList": [ + { + "nIndex": 1, + "sName": "Width", + "dValue": 800.0 + }, + { + "nIndex": 2, + "sName": "Height", + "dValue": 1200.0 + } + ], + "JointList": [ + { + "nIndex": 1, + "JointType": "FULL_H" + }, + { + "nIndex": 2, + "JointType": "FULL_H" + }, + { + "nIndex": 3, + "JointType": "FULL_H" + }, + { + "nIndex": 4, + "JointType": "FULL_H" + } + ], + "BottomRail": false, + "BottomRailQty": 0, + "AreaList": [ + { + "bIsSashVertical": true, + "SashList": [ + { + "OpeningType": "TILTTURN_LEFT", + "bHasHandle": true, + "dDimension": 100.0 + } + ], + "SashType": "NULL", + "JointList": [ + { + "nIndex": 1, + "JointType": "FULL_H" + }, + { + "nIndex": 2, + "JointType": "FULL_H" + }, + { + "nIndex": 3, + "JointType": "FULL_H" + }, + { + "nIndex": 4, + "JointType": "FULL_H" + } + ], + "Hardware": "000000", + "AreaList": [ + { + "FillType": "GLASS", + "AreaList": [], + "AreaType": "FILL" + } + ], + "AreaType": "SASH" + } + ], + "AreaType": "FRAME" + } + ] +} \ No newline at end of file diff --git a/Lux.API/DemoData/FinDueAnteBottomFisso.jwd b/Lux.API/DemoData/FinDueAnteBottomFisso.jwd new file mode 100644 index 00000000..36f99525 --- /dev/null +++ b/Lux.API/DemoData/FinDueAnteBottomFisso.jwd @@ -0,0 +1,132 @@ +{ + "ProfilePath": "Profilo78", + "AreaList": [ + { + "Shape": "RECTANGLE", + "DimensionList": [ + { + "nIndex": 1, + "sName": "Width", + "dValue": 1500.0 + }, + { + "nIndex": 2, + "sName": "Height", + "dValue": 2100.0 + } + ], + "JointList": [ + { + "nIndex": 1, + "JointType": "FULL_H" + }, + { + "nIndex": 2, + "JointType": "FULL_H" + }, + { + "nIndex": 3, + "JointType": "FULL_H" + }, + { + "nIndex": 4, + "JointType": "FULL_H" + } + ], + "BottomRail": false, + "BottomRailQty": 0, + "AreaList": [ + { + "SplitShape": "HORIZONTAL", + "SplitPositionList": [ + { + "bIsRelative": true, + "dDimension": 40.0 + }, + { + "bIsRelative": true, + "dDimension": 60.0 + } + ], + "AreaList": [ + { + "AreaList": [ + { + "FillType": "GLASS", + "AreaList": [], + "AreaType": "FILL" + } + ], + "AreaType": "SPLITTED" + }, + { + "AreaList": [ + { + "bIsSashVertical": true, + "SashList": [ + { + "OpeningType": "TURNONLY_LEFT", + "bHasHandle": false, + "dDimension": 50.0 + }, + { + "OpeningType": "TILTTURN_RIGHT", + "bHasHandle": true, + "dDimension": 50.0 + } + ], + "SashType": "NULL", + "JointList": [ + { + "nIndex": 1, + "JointType": "FULL_H" + }, + { + "nIndex": 2, + "JointType": "FULL_H" + }, + { + "nIndex": 3, + "JointType": "FULL_H" + }, + { + "nIndex": 4, + "JointType": "FULL_H" + } + ], + "Hardware": "000000", + "AreaList": [ + { + "AreaList": [ + { + "FillType": "GLASS", + "AreaList": [], + "AreaType": "FILL" + } + ], + "AreaType": "SPLITTED" + }, + { + "AreaList": [ + { + "FillType": "GLASS", + "AreaList": [], + "AreaType": "FILL" + } + ], + "AreaType": "SPLITTED" + } + ], + "AreaType": "SASH" + } + ], + "AreaType": "SPLITTED" + } + ], + "AreaType": "SPLIT" + } + ], + "AreaType": "FRAME" + } + ] +} \ No newline at end of file diff --git a/Lux.API/DemoData/FinestraSplitVert.jwd b/Lux.API/DemoData/FinestraSplitVert.jwd new file mode 100644 index 00000000..b8dc2849 --- /dev/null +++ b/Lux.API/DemoData/FinestraSplitVert.jwd @@ -0,0 +1,79 @@ +{ + "ProfilePath": "Profilo78", + "AreaList": [ + { + "Shape": "RECTANGLE", + "DimensionList": [ + { + "nIndex": 1, + "sName": "Width", + "dValue": 1500.0 + }, + { + "nIndex": 2, + "sName": "Height", + "dValue": 1800.0 + } + ], + "JointList": [ + { + "nIndex": 1, + "JointType": "FULL_H" + }, + { + "nIndex": 2, + "JointType": "FULL_H" + }, + { + "nIndex": 3, + "JointType": "FULL_H" + }, + { + "nIndex": 4, + "JointType": "FULL_H" + } + ], + "BottomRail": false, + "BottomRailQty": 0, + "AreaList": [ + { + "SplitShape": "VERTICAL", + "SplitPositionList": [ + { + "bIsRelative": true, + "dDimension": 50.0 + }, + { + "bIsRelative": true, + "dDimension": 50.0 + } + ], + "AreaList": [ + { + "AreaList": [ + { + "FillType": "GLASS", + "AreaList": [], + "AreaType": "FILL" + } + ], + "AreaType": "SPLITTED" + }, + { + "AreaList": [ + { + "FillType": "GLASS", + "AreaList": [], + "AreaType": "FILL" + } + ], + "AreaType": "SPLITTED" + } + ], + "AreaType": "SPLIT" + } + ], + "AreaType": "FRAME" + } + ] +} \ No newline at end of file diff --git a/Lux.API/DemoData/FinestraSplitVertOriz.jwd b/Lux.API/DemoData/FinestraSplitVertOriz.jwd new file mode 100644 index 00000000..e8380b30 --- /dev/null +++ b/Lux.API/DemoData/FinestraSplitVertOriz.jwd @@ -0,0 +1,141 @@ +{ + "ProfilePath": "Profilo78", + "AreaList": [ + { + "Shape": "RECTANGLE", + "DimensionList": [ + { + "nIndex": 1, + "sName": "Width", + "dValue": 1500.0 + }, + { + "nIndex": 2, + "sName": "Height", + "dValue": 1800.0 + } + ], + "JointList": [ + { + "nIndex": 1, + "JointType": "FULL_H" + }, + { + "nIndex": 2, + "JointType": "FULL_H" + }, + { + "nIndex": 3, + "JointType": "FULL_H" + }, + { + "nIndex": 4, + "JointType": "FULL_H" + } + ], + "BottomRail": false, + "BottomRailQty": 0, + "AreaList": [ + { + "SplitShape": "VERTICAL", + "SplitPositionList": [ + { + "bIsRelative": true, + "dDimension": 50.0 + }, + { + "bIsRelative": true, + "dDimension": 50.0 + } + ], + "AreaList": [ + { + "AreaList": [ + { + "SplitShape": "HORIZONTAL", + "SplitPositionList": [ + { + "bIsRelative": true, + "dDimension": 40.0 + }, + { + "bIsRelative": true, + "dDimension": 60.0 + } + ], + "AreaList": [ + { + "AreaList": [ + { + "FillType": "GLASS", + "AreaList": [], + "AreaType": "FILL" + } + ], + "AreaType": "SPLITTED" + }, + { + "AreaList": [ + { + "FillType": "GLASS", + "AreaList": [], + "AreaType": "FILL" + } + ], + "AreaType": "SPLITTED" + } + ], + "AreaType": "SPLIT" + } + ], + "AreaType": "SPLITTED" + }, + { + "AreaList": [ + { + "SplitShape": "HORIZONTAL", + "SplitPositionList": [ + { + "bIsRelative": true, + "dDimension": 40.0 + }, + { + "bIsRelative": true, + "dDimension": 60.0 + } + ], + "AreaList": [ + { + "AreaList": [ + { + "FillType": "GLASS", + "AreaList": [], + "AreaType": "FILL" + } + ], + "AreaType": "SPLITTED" + }, + { + "AreaList": [ + { + "FillType": "GLASS", + "AreaList": [], + "AreaType": "FILL" + } + ], + "AreaType": "SPLITTED" + } + ], + "AreaType": "SPLIT" + } + ], + "AreaType": "SPLITTED" + } + ], + "AreaType": "SPLIT" + } + ], + "AreaType": "FRAME" + } + ] +} \ No newline at end of file diff --git a/Lux.API/DemoImg/AntaDoppia.svg b/Lux.API/DemoImg/AntaDoppia.svg new file mode 100644 index 00000000..b5c13ac0 --- /dev/null +++ b/Lux.API/DemoImg/AntaDoppia.svg @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Lux.API/DemoImg/AntaSingola.svg b/Lux.API/DemoImg/AntaSingola.svg new file mode 100644 index 00000000..7f736b0c --- /dev/null +++ b/Lux.API/DemoImg/AntaSingola.svg @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Lux.API/ExtLib/EgwMultiEngineManager.dll b/Lux.API/ExtLib/EgwMultiEngineManager.dll new file mode 100644 index 00000000..d7a3e93e Binary files /dev/null and b/Lux.API/ExtLib/EgwMultiEngineManager.dll differ diff --git a/Lux.API/Lux.API.csproj b/Lux.API/Lux.API.csproj index 2adcb589..c6496b2c 100644 --- a/Lux.API/Lux.API.csproj +++ b/Lux.API/Lux.API.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -15,4 +15,10 @@ + + + ExtLib\EgwMultiEngineManager.dll + + + diff --git a/Lux.API/Program.cs b/Lux.API/Program.cs index 48863a6d..22bfd557 100644 --- a/Lux.API/Program.cs +++ b/Lux.API/Program.cs @@ -1,3 +1,5 @@ +using EgwMultiEngineManager; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -7,6 +9,15 @@ builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); +// aggiungo rif libreria EgwManager + +string sCamExePath = @"c:\EgtProg\EgtEngine\EgtEngineR32.exe"; +string sMainLuaPath = @"c:\Temp\EgwMultiEngineManager\Pipe.lua"; +ExecProcessManager myExecProcessManager = new ExecProcessManager(sCamExePath, $"\"{sMainLuaPath}\""); +myExecProcessManager.SetMaxCamInstances(1); +myExecProcessManager.StartExecutionThread(); +builder.Services.AddSingleton(myExecProcessManager); + var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/Lux.Core/RestPayload/JwdDTO.cs b/Lux.Core/RestPayload/JwdDTO.cs index a6f4e7c7..7a30d787 100644 --- a/Lux.Core/RestPayload/JwdDTO.cs +++ b/Lux.Core/RestPayload/JwdDTO.cs @@ -18,6 +18,11 @@ namespace Lux.Core.RestPayload public double Width { get; set; } = 800; public double Height { get; set; } = 800; + + /// + /// FAKE: nome del file svg da leggere direttamente... + /// + public string nameUrl { get; set; } = ""; } }