120 lines
4.2 KiB
C#
120 lines
4.2 KiB
C#
using EgwCoreLib.Lux.Core.RestPayload;
|
|
using EgwCoreLib.Lux.Data.Services;
|
|
using EgwMultiEngineManager.Data;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using NLog;
|
|
using System.Diagnostics;
|
|
|
|
namespace Lux.API.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class GenericController : ControllerBase
|
|
{
|
|
#region Public Constructors
|
|
|
|
public GenericController(IConfiguration config, IRedisService redisService, ImageCacheService imgServ)
|
|
{
|
|
_config = config;
|
|
_redisService = redisService;
|
|
_imgService = imgServ;
|
|
pubChannel = _config.GetValue<string>("ServerConf:PubChannel") ?? "";
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Chiamata POST: specificando il tipo di richiesta + dizionario parametri esegue chiamata
|
|
/// PUT: api/generic/calc/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] CalcRequestDTO currReq)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string retVal = "";
|
|
|
|
// ...se ricevo percorso --> leggo jwd/svg cablato
|
|
if (currReq != null)
|
|
{
|
|
Dictionary<string, string> DictExec = currReq.DictExec;
|
|
// controllo se mancassero parametri...
|
|
if (!DictExec.ContainsKey("Mode"))
|
|
{
|
|
DictExec.Add("Mode", "1");
|
|
}
|
|
if (!DictExec.ContainsKey("UID"))
|
|
{
|
|
DictExec.Add("UID", id);
|
|
}
|
|
int nId = 1;
|
|
// da modificare con tipo richiesta...
|
|
QuestionDTO currArgs = new QuestionDTO(nId, currReq.EnvType, DictExec);
|
|
|
|
await _redisService.PublishAsync(pubChannel, currArgs.sProcessArgs);
|
|
retVal = "DONE";
|
|
}
|
|
sw.Stop();
|
|
Log.Info($"calcSvg | {sw.Elapsed.TotalMilliseconds:N3} ms");
|
|
return Ok(retVal);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiamata POST: riceve Json in formato JWD serializzato, invia richiesta calcolo modo 2 (BOM)
|
|
/// PUT: api/window/bom/00000000-0000-0000-0000-000000000000
|
|
/// </summary>
|
|
/// <param name="id">id oggetto</param>
|
|
/// <returns></returns>
|
|
[HttpPost("bom/{id}")]
|
|
public async Task<ActionResult<string>> getBom(string id, [FromBody] string currSer)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string retVal = "";
|
|
|
|
// se messaggio vuoto --> uso default!
|
|
currSer = string.IsNullOrEmpty(currSer) ? "" : currSer;
|
|
|
|
// ...se ricevo percorso --> leggo jwd/svg cablato
|
|
if (!string.IsNullOrEmpty(currSer))
|
|
{
|
|
Dictionary<string, string> DictExec = new Dictionary<string, string>();
|
|
// cablata la BOM
|
|
DictExec.Add("Mode", "2");
|
|
// UID cablato x ora...
|
|
DictExec.Add("UID", id);
|
|
DictExec.Add("Jwd", currSer);
|
|
int nId = 1;
|
|
// da modificare con tipo richiesta...
|
|
QuestionDTO currArgs = new QuestionDTO(nId, EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW, DictExec);
|
|
|
|
await _redisService.PublishAsync(pubChannel, currArgs.sProcessArgs);
|
|
retVal = "DONE";
|
|
}
|
|
sw.Stop();
|
|
Log.Info($"getBom | {sw.Elapsed.TotalMilliseconds:N3} ms");
|
|
return Ok(retVal);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
private readonly IRedisService _redisService;
|
|
private readonly string pubChannel = "";
|
|
private IConfiguration _config;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private ImageCacheService _imgService { get; set; }
|
|
|
|
#endregion Private Properties
|
|
}
|
|
} |