using EgwCoreLib.Lux.Data.Services; using EgwMultiEngineManager; using Microsoft.AspNetCore.Mvc; using NLog; using System.Diagnostics; namespace Lux.API.Controllers { [Route("api/[controller]")] [ApiController] public class WindowController : ControllerBase { #region Public Constructors public WindowController(IConfiguration config, ImageCacheService imgServ, IRedisService redisService) { _config = config; _redisService = redisService; _imgService = imgServ; pubChannel = _config.GetValue("ServerConf:PubChannel") ?? ""; } #endregion Public Constructors #region Public Methods /// /// Chiamata POST: riceve Json in formato JWD serializzato, lo ripete come risposta /// PUT: api/calc/svg/00000000-0000-0000-0000-000000000000 /// /// id oggetto /// [HttpPost("calc/{id}")] public async Task> calc(string id, [FromBody] string currJwd) { Stopwatch sw = new Stopwatch(); sw.Start(); string svgContent = ""; // 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", "1"); // 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($"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("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(); 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 private static Logger Log = LogManager.GetCurrentClassLogger(); private readonly IRedisService _redisService; private readonly string pubChannel = ""; private IConfiguration _config; /// /// Demorichiesta jwd x fare test richiesta calcolo /// private string demoJwd = "{\r\n\"ProfilePath\":\"Profilo78\",\r\n\"AreaList\":[\r\n{\r\n\"Shape\":\"RECTANGLE\",\r\n\"DimensionList\":[\r\n{\r\n\"nIndex\":1,\r\n\"sName\":\"Width\",\r\n\"dValue\":1200.0\r\n},\r\n{\r\n\"nIndex\":2,\r\n\"sName\":\"Height\",\r\n\"dValue\":1500.0\r\n}\r\n],\r\n\"JointList\":[\r\n{\r\n\"nIndex\":1,\r\n\"JointType\":\"FULL_V\"\r\n},\r\n{\r\n\"nIndex\":2,\r\n\"JointType\":\"FULL_V\"\r\n},\r\n{\r\n\"nIndex\":3,\r\n\"JointType\":\"FULL_V\"\r\n},\r\n{\r\n\"nIndex\":4,\r\n\"JointType\":\"FULL_V\"\r\n}\r\n],\r\n\"BottomRail\":false,\r\n\"BottomRailQty\":0,\r\n\"AreaList\":[\r\n{\r\n\"bIsSashVertical\":true,\r\n\"SashList\":[\r\n{\r\n\"OpeningType\":\"TURNONLY_LEFT\",\r\n\"bHasHandle\":false,\r\n\"dDimension\":50.0\r\n},\r\n{\r\n\"OpeningType\":\"TILTTURN_RIGHT\",\r\n\"bHasHandle\":true,\r\n\"dDimension\":50.0\r\n}\r\n],\r\n\"SashType\":\"NULL\",\r\n\"JointList\":[\r\n{\r\n\"nIndex\":1,\r\n\"JointType\":\"FULL_V\"\r\n},\r\n{\r\n\"nIndex\":2,\r\n\"JointType\":\"FULL_V\"\r\n},\r\n{\r\n\"nIndex\":3,\r\n\"JointType\":\"FULL_V\"\r\n},\r\n{\r\n\"nIndex\":4,\r\n\"JointType\":\"FULL_V\"\r\n}\r\n],\r\n\"Hardware\":\"000000\",\r\n\"AreaList\":[\r\n{\r\n\"AreaList\":[\r\n{\r\n\"FillType\":\"GLASS\",\r\n\"AreaList\":[],\r\n\"AreaType\":\"FILL\"\r\n}\r\n],\r\n\"AreaType\":\"SPLITTED\"\r\n},\r\n{\r\n\"AreaList\":[\r\n{\r\n\"FillType\":\"GLASS\",\r\n\"AreaList\":[],\r\n\"AreaType\":\"FILL\"\r\n}\r\n],\r\n\"AreaType\":\"SPLITTED\"\r\n}\r\n],\r\n\"AreaType\":\"SASH\"\r\n}\r\n],\r\n\"AreaType\":\"FRAME\"\r\n}\r\n]\r\n}"; #endregion Private Fields #region Private Properties private ImageCacheService _imgService { get; set; } #endregion Private Properties } }