diff --git a/Lux.API/Controllers/JwdController.cs b/Lux.API/Controllers/JwdController.cs index 1f52642d..5ece8ee0 100644 --- a/Lux.API/Controllers/JwdController.cs +++ b/Lux.API/Controllers/JwdController.cs @@ -1,5 +1,6 @@ using EgwMultiEngineManager; using Lux.Core.RestPayload; +using Lux.Data; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; @@ -12,74 +13,23 @@ namespace Lux.API.Controllers { #region Public Constructors -#if true - public JwdController(ILogger logger, ExecProcessManager EgwProcManager) + public JwdController(IConfigurationManager config, ILogger logger, ExecProcessManager EgwProcManager) { _logger = logger; - ProcessMan = EgwProcManager; - ProcessMan.m_AnswerReceived += ProcessMan_m_AnswerReceived; - } -#else - public JwdController(ILogger logger) - { - _logger = logger; - } -#endif - - private bool waitResult = false; - //private Dictionary listSvg = new Dictionary(); - private string lastSvg = ""; - - /// - /// Restituisce una risposta all'esecuzione - /// - /// - private void ProcessMan_m_AnswerReceived(ProcessArgsResult result) - { - // verifico che sia la mia richeista con nId cablato a 1 - if (result.nId == 1) + _config = config; + // verifico se usare engine + enableEgwEng = _config.GetValue("ServerConf:EgwEngineEnab"); + if (enableEgwEng) { + ProcessMan = EgwProcManager; + ProcessMan.m_AnswerReceived += ProcessMan_m_AnswerReceived; } - // salvo il risultato... - if (result.Args != null && result.Args.Count > 0) - { - if (result.Args.ContainsKey("Svg")) - { - // salvo SVG - string newSvg = result.Args["Svg"]; - // salvo nel dizionario - lastSvg= newSvg; - waitResult = false; - } - } } #endregion Public Constructors #region Public Methods - -#if false - /// - /// 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"); - } -#endif - /// /// Chiamata POST: riceve Json in formato JwdDto, restituisce jpeg file /// PUT: api/Jwd/svg/00000000-0000-0000-0000-000000000000 @@ -199,25 +149,27 @@ namespace Lux.API.Controllers } else { - if (System.IO.File.Exists(filePath)) + if (enableEgwEng && ProcessMan != null) { - rawData = System.IO.File.ReadAllText(filePath); - } - Dictionary DictExec = new Dictionary(); - DictExec.Add("Mode", "1"); - DictExec.Add("Jwd", rawData); - int nId = 1; - ProcessArgs currArgs = new ProcessArgs(nId, DictExec); - bool done = ProcessMan.ArgumentsEnqueue(currArgs); -#if false -#endif - waitResult = true; + if (System.IO.File.Exists(filePath)) + { + rawData = System.IO.File.ReadAllText(filePath); + } + Dictionary DictExec = new Dictionary(); + DictExec.Add("Mode", "1"); + DictExec.Add("Jwd", rawData); + int nId = 1; + ProcessArgs currArgs = new ProcessArgs(nId, DictExec); + bool done = ProcessMan.ArgumentsEnqueue(currArgs); - int numWait = 40; - while (numWait > 0 && waitResult) - { - numWait--; - await Task.Delay(waitDelay); + waitResult = true; + + int numWait = 40; + while (numWait > 0 && waitResult) + { + numWait--; + await Task.Delay(waitDelay); + } } // se ho risultato mostro... if (!string.IsNullOrEmpty(lastSvg)) @@ -241,8 +193,14 @@ namespace Lux.API.Controllers #region Private Fields private readonly ILogger _logger; + private IConfigurationManager _config; + private bool enableEgwEng = true; + + //private Dictionary listSvg = new Dictionary(); + private string lastSvg = ""; private int waitDelay = 250; + private bool waitResult = false; #endregion Private Fields @@ -251,10 +209,57 @@ namespace Lux.API.Controllers /// /// Esecutore di processi generico /// - private ExecProcessManager ProcessMan { get; set; } -#if false -#endif + private ExecProcessManager? ProcessMan { get; set; } #endregion Private Properties + + #region Private Methods + + /// + /// Restituisce una risposta all'esecuzione + /// + /// + private void ProcessMan_m_AnswerReceived(ProcessArgsResult result) + { + // verifico che sia la mia richeista con nId cablato a 1 + if (result.nId == 1) + { + } + // salvo il risultato... + if (result.Args != null && result.Args.Count > 0) + { + if (result.Args.ContainsKey("Svg")) + { + // salvo SVG + string newSvg = result.Args["Svg"]; + // salvo nel dizionario + lastSvg = newSvg; + waitResult = false; + } + } + } + + #endregion Private Methods + +#if false + /// + /// 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"); + } +#endif } } \ No newline at end of file diff --git a/Lux.API/Controllers/WindowController.cs b/Lux.API/Controllers/WindowController.cs index 85fbbb83..894f4a37 100644 --- a/Lux.API/Controllers/WindowController.cs +++ b/Lux.API/Controllers/WindowController.cs @@ -1,4 +1,5 @@ using EgwMultiEngineManager; +using Lux.Data; using Lux.Data.Services; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -12,11 +13,17 @@ namespace Lux.API.Controllers { #region Public Constructors - public WindowController(ILogger logger, ExecProcessManager EgwProcManager, ImageCacheService imgServ) + public WindowController(IConfigurationManager config, ILogger logger, ExecProcessManager EgwProcManager, ImageCacheService imgServ) { _logger = logger; - ProcessMan = EgwProcManager; - ProcessMan.m_AnswerReceived += ProcessMan_m_AnswerReceived; + _config = config; + // verifico se usare engine + enableEgwEng = _config.GetValue("ServerConf:EgwEngineEnab"); + if (enableEgwEng) + { + ProcessMan = EgwProcManager; + ProcessMan.m_AnswerReceived += ProcessMan_m_AnswerReceived; + } ImgService = imgServ; } @@ -40,19 +47,22 @@ namespace Lux.API.Controllers // ...se ricevo percorso --> leggo jwd/svg cablato if (!string.IsNullOrEmpty(currJwd)) { - Dictionary DictExec = new Dictionary(); - DictExec.Add("Mode", "1"); - DictExec.Add("Jwd", currJwd); - int nId = 1; - ProcessArgs currArgs = new ProcessArgs(nId, DictExec); - bool done = ProcessMan.ArgumentsEnqueue(currArgs); - waitResult = true; - - int numWait = 200; - while (numWait > 0 && waitResult) + if (enableEgwEng && ProcessMan != null) { - numWait--; - await Task.Delay(waitDelay); + Dictionary DictExec = new Dictionary(); + DictExec.Add("Mode", "1"); + DictExec.Add("Jwd", currJwd); + int nId = 1; + ProcessArgs currArgs = new ProcessArgs(nId, DictExec); + bool done = ProcessMan.ArgumentsEnqueue(currArgs); + waitResult = true; + + int numWait = 200; + while (numWait > 0 && waitResult) + { + numWait--; + await Task.Delay(waitDelay); + } } // se ho risultato mostro... if (!string.IsNullOrEmpty(lastSvg)) @@ -98,6 +108,8 @@ namespace Lux.API.Controllers #region Private Fields private readonly ILogger _logger; + private IConfigurationManager _config; + private bool enableEgwEng = true; //private Dictionary listSvg = new Dictionary(); private string lastSvg = ""; @@ -115,7 +127,7 @@ namespace Lux.API.Controllers /// /// Esecutore di processi generico /// - private ExecProcessManager ProcessMan { get; set; } + private ExecProcessManager? ProcessMan { get; set; } #endregion Private Properties @@ -127,10 +139,7 @@ namespace Lux.API.Controllers /// private void ProcessMan_m_AnswerReceived(ProcessArgsResult result) { - // verifico che sia la mia richeista con nId cablato a 1 - if (result.nId == 1) - { - } + // verifico che sia la mia richeista con id immagine... FARE!!! // salvo il risultato... if (result.Args != null && result.Args.Count > 0) { diff --git a/Lux.API/Program.cs b/Lux.API/Program.cs index e47e25f8..c5ab87f7 100644 --- a/Lux.API/Program.cs +++ b/Lux.API/Program.cs @@ -11,6 +11,9 @@ var logger = LogManager.Setup() ConfigurationManager configuration = builder.Configuration; logger.Info("Program.cs: startup"); + +bool enableEgwEng = configuration.GetValue("ServerConf:EgwEngineEnab"); + // Add services to the container. builder.Services.AddControllers(); @@ -18,11 +21,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, 1, ExecProcessManager.ReturnModes.EVENT_); -builder.Services.AddSingleton(myExecProcessManager); +// solo se abilitato da conf +if (enableEgwEng) +{ + // aggiungo rif libreria EgwManager + string sCamExePath = @"c:\EgtProg\EgtEngine\EgtEngineR32.exe"; + string sMainLuaPath = @"c:\Temp\EgwMultiEngineManager\Pipe.lua"; + ExecProcessManager myExecProcessManager = new ExecProcessManager(sCamExePath, sMainLuaPath, 1, ExecProcessManager.ReturnModes.EVENT_); + builder.Services.AddSingleton(myExecProcessManager); +} builder.Services.AddSingleton(); var app = builder.Build(); diff --git a/Lux.API/appsettings.Staging.json b/Lux.API/appsettings.Staging.json index 30d20c54..3045c651 100644 --- a/Lux.API/appsettings.Staging.json +++ b/Lux.API/appsettings.Staging.json @@ -6,7 +6,7 @@ } }, "ServerConf": { - "UseEgwEngine": false, + "EgwEngineEnab": false, "BaseUrl": "/Lux/srv/" } } diff --git a/Lux.API/appsettings.json b/Lux.API/appsettings.json index a2b1a1ed..2843b501 100644 --- a/Lux.API/appsettings.json +++ b/Lux.API/appsettings.json @@ -57,6 +57,7 @@ "Redis": "redis.ufficio:26379, serviceName=devel, DefaultDatabase=6, keepAlive=180, connectTimeout=15000, syncTimeout=15000, asyncTimeout=15000, abortConnect=false, ssl=false, allowAdmin=true" }, "ServerConf": { + "EgwEngineEnab": true, "BaseUrl": "/Lux/srv/" } }