151 lines
5.5 KiB
C#
151 lines
5.5 KiB
C#
using Egw.Window.Data;
|
|
using EgwCoreLib.Lux.Core.RestPayload;
|
|
|
|
namespace Lux.API.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class GenericController : ControllerBase
|
|
{
|
|
#region Public Constructors
|
|
|
|
public GenericController(IConfiguration config, IRedisService redisService, IImageCacheService imgServ, ICalcRuidService crService)
|
|
{
|
|
_config = config;
|
|
_redisService = redisService;
|
|
_imgService = imgServ;
|
|
chPub = _config.GetValue<string>("ServerConf:ChannelPub") ?? "";
|
|
_calcRuidService = crService;
|
|
}
|
|
|
|
#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)
|
|
{
|
|
// preparo variabili di base
|
|
Dictionary<string, string> DictExec = currReq.DictExec;
|
|
string envir = $"{currReq.EnvType}";
|
|
string type = "ND";
|
|
// controllo se mancassero parametri...
|
|
if (!DictExec.ContainsKey("Mode"))
|
|
{
|
|
DictExec.Add("Mode", $"{(int)Enums.QuestionModes.PREVIEW}");
|
|
}
|
|
if (!DictExec.ContainsKey("SubMode"))
|
|
{
|
|
DictExec.Add("SubMode", $"{(int)Enums.QuestionConfSubModes.NULL}");
|
|
}
|
|
if (!DictExec.ContainsKey("UID"))
|
|
{
|
|
DictExec.Add("UID", id);
|
|
}
|
|
if (!DictExec.ContainsKey("RUID"))
|
|
{
|
|
var mode = DictExec["Mode"];
|
|
var sub = DictExec["SubMode"];
|
|
type = string.IsNullOrEmpty(sub) ? mode : $"{mode}-{sub}";
|
|
// creo registrazione richiesta...
|
|
var ruid = await _calcRuidService.AddRequestAsync(envir, type, id);
|
|
// aggiungo RUID effettivo
|
|
DictExec.Add("RUID", ruid);
|
|
}
|
|
int nId = 1;
|
|
// da modificare con tipo richiesta...
|
|
QuestionDTO currArgs = new QuestionDTO(nId, currReq.EnvType, DictExec);
|
|
|
|
await _redisService.PublishAsync(chPub, 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;
|
|
var bomEnvir = Constants.EXECENVIRONMENTS.WINDOW;
|
|
|
|
// ...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", $"{(int)Enums.QuestionModes.BOM}");
|
|
// UID cablato x ora...
|
|
DictExec.Add("UID", id);
|
|
|
|
string envir = $"{bomEnvir}";
|
|
string type = $"{Enums.QuestionModes.BOM}";
|
|
var ruid = await _calcRuidService.AddRequestAsync(envir, type, id);
|
|
// Aggiungo RUID effettivo
|
|
DictExec.Add("RUID", ruid);
|
|
// valore serializzato x BOM
|
|
DictExec.Add("SerializedData", currSer);
|
|
int nId = 1;
|
|
// da modificare con tipo richiesta...
|
|
QuestionDTO currArgs = new QuestionDTO(nId, bomEnvir, DictExec);
|
|
|
|
await _redisService.PublishAsync(chPub, currArgs.sProcessArgs);
|
|
retVal = "DONE";
|
|
}
|
|
sw.Stop();
|
|
Log.Info($"getBom | {sw.Elapsed.TotalMilliseconds:N3} ms");
|
|
return Ok(retVal);
|
|
}
|
|
|
|
[HttpGet("version")]
|
|
public string version()
|
|
{
|
|
var version = Assembly
|
|
.GetExecutingAssembly()
|
|
.GetName()
|
|
.Version?
|
|
.ToString() ?? "unknown";
|
|
|
|
return version;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
private readonly ICalcRuidService _calcRuidService;
|
|
private readonly IImageCacheService _imgService;
|
|
private readonly IRedisService _redisService;
|
|
private readonly string chPub = "";
|
|
|
|
private IConfiguration _config;
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |