Merge branch 'release/AddImagePngService'

This commit is contained in:
Samuele Locatelli
2023-05-22 18:00:22 +02:00
7 changed files with 136 additions and 9 deletions
@@ -0,0 +1,86 @@
using Microsoft.AspNetCore.Mvc;
using NLog;
using Svg;
using System.Drawing;
using WebDoorCreator.Data.Services;
namespace WebDoorCreator.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class DoorImageController : ControllerBase
{
#region Public Constructors
public DoorImageController(IConfiguration configuration, QueueDataService DataService)
{
Log.Info("Starting DoorImageController");
_configuration = configuration;
QDataServ = DataService;
Log.Info("Avviato DoorImageController");
}
#endregion Public Constructors
#region Public Methods
// GET: api/Alive
[HttpGet]
public string Get()
{
return "OK";
}
[HttpGet("GetImage.png")]
public async Task<IActionResult> GetImagePng(int DoorId)
{
byte[] result = new byte[0];
string svgContent = await QDataServ.DoorGetLastSvg(DoorId);
if (!string.IsNullOrEmpty(svgContent))
{
var mySvg = SvgDocument.FromSvg<SvgDocument>(svgContent);
//result = System.Text.Encoding.UTF8.GetBytes(svgContent);
var myBmp = mySvg.Draw();
result = ImageToByte2(myBmp);
}
return File(result, "image/png");
}
[HttpGet("GetImage.svg")]
public async Task<IActionResult> GetImageSvg(int DoorId)
{
string svgContent = await QDataServ.DoorGetLastSvg(DoorId);
var result = System.Text.Encoding.UTF8.GetBytes(svgContent);
return File(result, "image/svg+xml");
}
#endregion Public Methods
#region Private Fields
private static IConfiguration _configuration = null!;
private static Logger Log = LogManager.GetCurrentClassLogger();
#endregion Private Fields
#region Private Properties
private QueueDataService QDataServ { get; set; } = null!;
#endregion Private Properties
#region Private Methods
private byte[] ImageToByte2(Image img)
{
using (var stream = new MemoryStream())
{
img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
return stream.ToArray();
}
}
#endregion Private Methods
}
}
+21
View File
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
namespace WebDoorCreator.Core
{
public class Utils
{
public static byte[] ImageToByte2(Image img)
{
using (var stream = new MemoryStream())
{
img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
return stream.ToArray();
}
}
}
}
@@ -24,6 +24,7 @@
<PackageReference Include="StackExchange.Redis.Extensions.AspNetCore" Version="9.1.0" />
<PackageReference Include="StackExchange.Redis.Extensions.Core" Version="9.1.0" />
<PackageReference Include="StackExchange.Redis.Extensions.Newtonsoft" Version="9.1.0" />
<PackageReference Include="Svg" Version="3.4.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
@@ -12,7 +12,9 @@ else
<div>Pending changes: <b>@DoorOp2Save.Count()</b></div>
}
</div>
<div class="col-4"></div>
<div class="col-4">
<ButtonsDoorDef></ButtonsDoorDef>
</div>
@if (paramsChanged)
{
@@ -19,6 +19,23 @@ namespace WebDoorCreator.UI.Controllers
return File(result, "image/svg+xml");
}
#if false
[HttpGet("GetImage.png")]
public async Task<IActionResult> GetImagePng(int DoorId)
{
byte[] result = new byte[0];
string svgContent = await QDataServ.DoorGetLastSvg(DoorId);
if (!string.IsNullOrEmpty(svgContent))
{
var mySvg = SvgDocument.FromSvg<SvgDocument>(svgContent);
//result = System.Text.Encoding.UTF8.GetBytes(svgContent);
var myBmp = mySvg.Draw();
result = Utils.ImageToByte2(myBmp);
}
return File(result, "image/png");
}
#endif
// GET: api/Alive
[HttpGet]
public string Get()
+1 -1
View File
@@ -31,7 +31,7 @@
@*<DoorDefOrderTopRow currOrderStatus="@orderStatus" bgColor="#AFCFD1"></DoorDefOrderTopRow>*@
@if (orderStatus != null)
{
<ButtonsDoorDef idOrd="@orderStatus.OrderId"></ButtonsDoorDef>
@*<ButtonsDoorDef idOrd="@orderStatus.OrderId"></ButtonsDoorDef>*@
}
@if (currDefStep == 10)
{
+7 -7
View File
@@ -30,16 +30,16 @@
{
<div class="d-flex justify-content-around">
<div class="cardOrders01 wRed01">
<div class="px-5 d-flex justify-content-between flex-wrap align-items-center mb-3" style="--bgStepColor: @stepColor">
<div class="d-flex justify-content-between flex-nowrap align-items-center mb-3" style="--bgStepColor: @stepColor">
<div class="fw-bold fs-2 text-start">
ORDER LIST
</div>
<div class=" px-3 d-flex justify-content-between small">
<div class=" px-3 d-flex justify-content-between small" style="font-size: 0.6rem">
<div>Order Date:</div>
<div>&nbsp;</div>
<div class=" fw-bold">@ord2Show.DateIns</div>
</div>
<div class=" px-3 d-flex justify-content-between small">
<div class=" px-3 d-flex justify-content-between small" style="font-size: 0.6rem">
<div>Order Number:</div>
<div>&nbsp;</div>
<div class="fw-bold">@ord2Show.OrderExtCode</div>
@@ -49,12 +49,12 @@
<div>&nbsp;</div>
<div class="fw-bold">@ord2Show.OrderDescript</div>
</div>
<div class=" px-3 d-flex justify-content-between small">
<div class=" px-3 d-flex justify-content-between small" style="font-size: 0.6rem">
<div>Models Number:</div>
<div>&nbsp;</div>
<div class="fw-bold">@ord2Show.NumType</div>
</div>
<div class=" px-3 d-flex justify-content-between small">
<div class=" px-3 d-flex justify-content-between small" style="font-size: 0.6rem">
<div class="text-center">Quantity:</div>
<div>&nbsp;</div>
<div class="fw-bold">@ord2Show.NumDoors</div>
@@ -83,7 +83,7 @@
@if (ord2Show != null)
{
<div class="cardOrders01 wRed02">
<div class="px-5 d-flex justify-content-between flex-wrap align-items-center mb-3">
<div class="d-flex justify-content-between flex-nowrap align-items-center mb-3">
<div class="fw-bold fs-2 text-start">
ORDER LIST
</div>
@@ -129,7 +129,7 @@
</div>
<div class="d-flex justify-content-around">
<div class="cardOrders02 wRed01">
<div class="px-5 d-flex justify-content-between flex-wrap align-items-center mb-3">
<div class="d-flex justify-content-between flex-nowrap align-items-center mb-3">
<div class="fw-bold fs-2 text-start">
DOORS LIST
</div>