Bozza modifiche x richeista ricalcolo porta (se missing)

This commit is contained in:
Samuele Locatelli
2024-02-16 17:09:58 +01:00
parent 145a0f5c7e
commit 70cd621f80
8 changed files with 216 additions and 63 deletions
@@ -5,9 +5,10 @@ using Svg;
using Svg.Skia;
using System.Drawing;
using WebDoorCreator.Data.Services;
#if false
using SkiaSharp;
using Svg.Skia;
using Svg.Skia;
#endif
namespace WebDoorCreator.API.Controllers
@@ -18,11 +19,12 @@ namespace WebDoorCreator.API.Controllers
{
#region Public Constructors
public DoorImageController(IConfiguration configuration, QueueDataService DataService)
public DoorImageController(IConfiguration configuration, QueueDataService cQDService, WebDoorCreatorService cWDCService)
{
Log.Info("Starting DoorImageController");
_configuration = configuration;
QDataServ = DataService;
QDService = cQDService;
WDService = cWDCService;
Log.Info("Avviato DoorImageController");
}
@@ -37,12 +39,20 @@ namespace WebDoorCreator.API.Controllers
return "OK";
}
[HttpGet("GetImage.png")]
public async Task<IActionResult> GetImagePng(int DoorId)
{
byte[] result = new byte[0];
string svgContent = await QDataServ.DoorGetLastSvg(DoorId);
string svgContent = await QDService.DoorGetLastSvg(DoorId);
// se fosse vuoto...
if (string.IsNullOrEmpty(svgContent))
{
// richiede ricalcolo img
await SendRecalcReq(DoorId);
// legge img vuota
svgContent = QDService.DoorGetMissingSvg();
}
// ora prosegue con conversione...
if (!string.IsNullOrEmpty(svgContent))
{
using (var svg = new SKSvg())
@@ -73,7 +83,15 @@ namespace WebDoorCreator.API.Controllers
[HttpGet("GetImage.svg")]
public async Task<IActionResult> GetImageSvg(int DoorId)
{
string svgContent = await QDataServ.DoorGetLastSvg(DoorId);
string svgContent = await QDService.DoorGetLastSvg(DoorId);
// se fosse vuoto...
if (string.IsNullOrEmpty(svgContent))
{
// richiede ricalcolo img
await SendRecalcReq(DoorId);
// legge img vuota
svgContent = QDService.DoorGetMissingSvg();
}
var result = System.Text.Encoding.UTF8.GetBytes(svgContent);
return File(result, "image/svg+xml");
}
@@ -90,14 +108,35 @@ namespace WebDoorCreator.API.Controllers
#region Private Properties
private QueueDataService QDataServ { get; set; } = null!;
private QueueDataService QDService { get; set; } = null!;
private WebDoorCreatorService WDService { get; set; } = null!;
#endregion Private Properties
#region Private Methods
/// <summary>
/// Invio richiesta ricalcolo porta
/// </summary>
/// <param name="DoorId"></param>
/// <returns></returns>
private async Task SendRecalcReq(int DoorId)
{
// richiede ricalcolo img
List<string> doorIdList = new List<string>() { $"{DoorId}" };
// chiamo reset richieste
var list2Proc = await QDService.ResetQueueByDoorList(doorIdList);
// recupero DDF ed invio x processing
if (DoorId > 0)
{
string currDDF = await WDService.DoorOpGetDDF(DoorId);
// versione corrente del DDF generato
int currVers = await QDService.SendCalcReq(DoorId, currDDF);
}
}
#endregion Private Methods
}
}