diff --git a/EgwCoreLib.Lux.Data/Controllers/LuxController.cs b/EgwCoreLib.Lux.Data/Controllers/LuxController.cs index c895865e..b00eabfc 100644 --- a/EgwCoreLib.Lux.Data/Controllers/LuxController.cs +++ b/EgwCoreLib.Lux.Data/Controllers/LuxController.cs @@ -14,8 +14,6 @@ using Newtonsoft.Json; using NLog; using StackExchange.Redis; using System.Globalization; -using System.Reflection.PortableExecutable; -using System.Security.AccessControl; using static EgwCoreLib.Lux.Core.Enums; namespace EgwCoreLib.Lux.Data.Controllers @@ -1925,6 +1923,32 @@ namespace EgwCoreLib.Lux.Data.Controllers return dbResult; } + /// + /// Recupera da DB riga offerta dato UID + /// + /// + /// + internal OfferRowModel? OfferRowGetByUID(string OfferRowUID) + { + OfferRowModel? dbResult = null; + //using (DataLayerContext dbCtx = new DataLayerContext(_config)) + using (DataLayerContext dbCtx = new DataLayerContext()) + { + try + { + dbResult = dbCtx + .DbSetOfferRow + .Include(s => s.SellingItemNav) + .FirstOrDefault(x => x.OfferRowUID == OfferRowUID); + } + catch (Exception exc) + { + Log.Error($"Eccezione durante OfferRowGetByUID{Environment.NewLine}{exc}"); + } + } + return dbResult; + } + internal async Task OffersCheckExpired() { bool answ = false; @@ -2863,6 +2887,32 @@ namespace EgwCoreLib.Lux.Data.Controllers return dbResult; } + /// + /// Riga Ordine dato suo UID + /// + /// + /// + internal OrderRowModel OrderRowGetByUID(string OrderRowUID) + { + OrderRowModel? dbResult = null; + //using (DataLayerContext dbCtx = new DataLayerContext(_config)) + using (DataLayerContext dbCtx = new DataLayerContext()) + { + try + { + dbResult = dbCtx + .DbSetOrderRow + .Include(s => s.SellingItemNav) + .FirstOrDefault(x => x.OrderRowUID == OrderRowUID); + } + catch (Exception exc) + { + Log.Error($"Eccezione durante OrderRowGetByUID{Environment.NewLine}{exc}"); + } + } + return dbResult; + } + /// /// Validazione record: /// - controllo state vs estimate diff --git a/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs b/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs index 5236c841..19797eb1 100644 --- a/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs +++ b/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs @@ -1044,6 +1044,38 @@ namespace EgwCoreLib.Lux.Data.Services return result; } + /// + /// Riga Offerta dato suo UID + /// + /// + /// + public async Task OfferRowGetByUID(string OfferRowUID) + { + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + OfferRowModel? result = null; + // cerco in redis... + string currKey = $"{redisBaseKey}:OfferRows:ByUID:{OfferRowUID}"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + //if (!string.IsNullOrEmpty($"{rawData}")) + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbController.OfferRowGetByUID(OfferRowUID); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + sw.Stop(); + Log.Debug($"OfferRowGetByUID | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + /// /// Verifica offerte scadute, con update sul DB /// @@ -1487,6 +1519,38 @@ namespace EgwCoreLib.Lux.Data.Services return result; } + /// + /// Riga Ordine dato suo UID + /// + /// + /// + public async Task OrderRowGetByUID(string OrderRowUID) + { + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + OrderRowModel? result = null; + // cerco in redis... + string currKey = $"{redisBaseKey}:OrderRows:ByUID:{OrderRowUID}"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + //if (!string.IsNullOrEmpty($"{rawData}")) + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbController.OrderRowGetByUID(OrderRowUID); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + sw.Stop(); + Log.Debug($"OrderRowGetByUID | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + /// /// Validazione record: /// - controllo state vs estimate diff --git a/Lux.API/Controllers/FileController.cs b/Lux.API/Controllers/FileController.cs new file mode 100644 index 00000000..571b4d23 --- /dev/null +++ b/Lux.API/Controllers/FileController.cs @@ -0,0 +1,184 @@ +using EgwCoreLib.Lux.Data.Services; +using EgwMultiEngineManager.Data; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using NLog; +using System; +using System.Data; +using System.Diagnostics; +using System.Text; + +namespace Lux.API.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class FileController : ControllerBase + { + #region Public Constructors + + /// + /// Controller per gestione file (es download JWD) + /// + /// + /// + public FileController(DataLayerServices DLService, ImageCacheService imgServ, ILogger logger) + { + _imgService = imgServ; + _DSService = DLService; + _logger = logger; + } + + #endregion Public Constructors + + #region Public Methods + +#if false + /// + /// Chiamata GET: restituisce file PNG (da file o da cache) + /// PUT: api/image/png/00000000-0000-0000-0000-000000000000 + /// + /// id oggetto + /// + [HttpGet("png/{id}")] + public async Task png(string id) + { + Stopwatch sw = new Stopwatch(); + sw.Start(); + string base64Encoded = ""; + byte[] decodedBytes = new byte[0]; + // ...se ricevo percorso --> leggo jwd/svg cablato + if (!string.IsNullOrEmpty(id)) + { + // bonifica nome svg da + base64Encoded = _imgService.LoadPng(id, EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.BEAM); + // converto base64 + decodedBytes = Convert.FromBase64String(base64Encoded); + } + sw.Stop(); + Log.Info($"pngString | {sw.Elapsed.TotalMilliseconds:N3} ms"); + //return Ok(decodedString); + return File(decodedBytes, "image/png"); + } + + /// + /// Chiamata GET: riceve Json in formato JwdDto, restituisce svg file + /// GET: api/Jwd/svg/00000000-0000-0000-0000-000000000000 + /// + /// id univoco img + /// + [HttpGet("svg/{id}")] + public async Task svgFileGet(string id) + { + Stopwatch sw = new Stopwatch(); + sw.Start(); + string filePath = Path.Combine("DemoImg", "AntaDoppia.svg"); + var svgContent = await System.IO.File.ReadAllTextAsync(filePath); + var bytes = System.Text.Encoding.UTF8.GetBytes(svgContent); + sw.Stop(); + _logger.LogInformation($"svgString | {sw.Elapsed.TotalMilliseconds:N3} ms"); + return File(bytes, "image/svg+xml"); + } +#endif + + /// + /// Chiamata GET: restituisce file di un determinato objType + /// GET: api/file/POR.25.0000000E?env=WINDOW&type=POR + /// GET: api/file/SOR.25.0000000E?env=WINDOW&type=SOR + /// + /// nb: al momento solo window e file jwd + /// + /// uid oggetto + /// tipologia oggetto (SOR/POR) + /// environment oggetto + /// + [HttpGet("{id}")] + public async Task porFile(string id, string objType = "SOR", Constants.EXECENVIRONMENTS env = Constants.EXECENVIRONMENTS.WINDOW) + { + Stopwatch sw = new Stopwatch(); + sw.Start(); + + if (string.IsNullOrEmpty(id)) + return NotFound(); + + // accetta SOLO env window... + if (env != Constants.EXECENVIRONMENTS.WINDOW) + { + return BadRequest("Only Window env"); + } + else + { + string mimeType = "txt"; + string fileName = id.Replace(".", "_").Replace(" ", "_").Replace(":", "_"); + byte[] bytes = new byte[0]; + // ...se ricevo percorso --> leggo jwd/svg cablato + if (!string.IsNullOrEmpty(id)) + { + // se contiene i caratteri casuali x forzare reload --> li levo + if (id.Contains("-")) + { + id = id.Substring(0, id.IndexOf("-")); + } + + // secondo del tipo + enivr decodifico valore corretto + switch (env) + { + case Constants.EXECENVIRONMENTS.NULL: + break; + case Constants.EXECENVIRONMENTS.WINDOW: + mimeType = "application/octet-stream"; + fileName = $"{fileName}.jwd"; + // recupero riga.. + string jsonContent = "";// await _imgService.LoadSvgAsync(id, env); + // a seconda del tipo leggo da 2 aree db diverse... + if (objType == "POR") + { + var currPOR = await _DSService.OrderRowGetByUID(id); + jsonContent = currPOR?.SerStruct ?? ""; + } + else if (objType == "SOR") + { + var currSOR = await _DSService.OfferRowGetByUID(id); + jsonContent = currSOR?.SerStruct ?? ""; + } + // se NON vuoto --> converto byte stream... + if (!string.IsNullOrEmpty(jsonContent)) + { + bytes = Encoding.UTF8.GetBytes(jsonContent); + } + break; + case Constants.EXECENVIRONMENTS.BEAM: + case Constants.EXECENVIRONMENTS.WALL: + case Constants.EXECENVIRONMENTS.CABINET: + default: + mimeType = "image/png"; + string base64Encoded = _imgService.LoadPng(id, EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.BEAM); + // converto base64 + bytes = Convert.FromBase64String(base64Encoded); + break; + } + } + sw.Stop(); + Log.Info($"{mimeType} | {sw.Elapsed.TotalMilliseconds:N3} ms"); + return File(bytes, mimeType, fileName); + } + } + + + + #endregion Public Methods + + #region Private Fields + + private static Logger Log = LogManager.GetCurrentClassLogger(); + private readonly ILogger _logger; + + #endregion Private Fields + + #region Private Properties + + private ImageCacheService _imgService { get; set; } + private DataLayerServices _DSService { get; set; } + + #endregion Private Properties + } +} \ No newline at end of file diff --git a/Lux.API/Lux.API.csproj b/Lux.API/Lux.API.csproj index 0052dc29..e326b6a6 100644 --- a/Lux.API/Lux.API.csproj +++ b/Lux.API/Lux.API.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 0.9.2601.1312 + 0.9.2601.1315 diff --git a/Lux.UI/Components/Compo/OfferRowMan.razor b/Lux.UI/Components/Compo/OfferRowMan.razor index c33d8e13..2fc2a462 100644 --- a/Lux.UI/Components/Compo/OfferRowMan.razor +++ b/Lux.UI/Components/Compo/OfferRowMan.razor @@ -193,14 +193,16 @@ else @fSize(item.FileSize) } - @if (PreparedFile.Contains(FixUidName(item.OfferRowUID))) + @* @if (PreparedFile.Contains(FixUidName(item.OfferRowUID))) {
  • Download
  • } else {
  • - } + } *@ + +
  • Download
  • @if (CurrEditMode == EditMode.RecData && EditRecord != null && EditRecord.OfferRowID == item.OfferRowID) diff --git a/Lux.UI/Components/Compo/OfferRowMan.razor.cs b/Lux.UI/Components/Compo/OfferRowMan.razor.cs index b9809346..70f8bdfb 100644 --- a/Lux.UI/Components/Compo/OfferRowMan.razor.cs +++ b/Lux.UI/Components/Compo/OfferRowMan.razor.cs @@ -629,50 +629,23 @@ namespace Lux.UI.Components.Compo protected override async Task OnParametersSetAsync() { - TempCleanup(); await ReloadData(); UpdateTable(); } + /// - /// Esegue preparazione del file file: - /// - legge dal DB il contenuto - /// - salva in area temp + /// Prepara URL x download file JWD /// - /// + /// + /// + /// /// - protected async Task PrepareFile(OfferRowModel currRec) + private string DownloadUrl(string currUid, string objType = "SOR", EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS envir = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW) { - // verifico sia un JWD x ora... - if (currRec.Envir == EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW) - { - string fName = FixUidName($"{currRec.OfferRowUID}"); - var filePath = Path.Combine(CurrEnv.ContentRootPath, "temp\\", $"{fName}.jwd"); - // verifico la cartella esista... - var parentDir = Path.GetDirectoryName(filePath); - if (parentDir != null && !Directory.Exists(parentDir)) - { - Directory.CreateDirectory(parentDir); - } - // salvo il contenuto - File.WriteAllText(filePath, currRec.SerStruct); - // aggiungo a lista preparati se non ci fosse... - if (!PreparedFile.Contains(fName)) - { - PreparedFile.Add(fName); - } - } + return $"{apiUrl}/file/{currUid}?objType={objType}&env={envir}"; } - /// - /// Fix nome UID senza punti intermedi o spazi - /// - /// - /// - private string FixUidName(string origName) - { - return origName.Replace(" ", "_").Replace(".", "_"); - } /// /// Lancia la richiesta di ricaolo della BOM dal JWD (o equivalente) /// @@ -1562,30 +1535,6 @@ namespace Lux.UI.Components.Compo return rawList ?? new List(); } - /// - /// Pulizia folder temp - /// - private void TempCleanup() - { - var tempPath = Path.Combine(CurrEnv.ContentRootPath, "temp\\"); - var listFiles = Directory.GetFiles(tempPath); - if (listFiles != null && listFiles.Count() > 0) - { - foreach (var cFile in listFiles) - { - // escludo placeholder... - if (!cFile.Contains("placeholder")) - { - var fInfo = File.GetLastWriteTime(cFile); - if (DateTime.Now.Subtract(fInfo).TotalMinutes > 10) - { - File.Delete(cFile); - } - } - } - } - } - /// /// Toggle visibilit� modifica file indicando ID della OfferRow corrente (o zero se deselect) /// diff --git a/Lux.UI/Lux.UI.csproj b/Lux.UI/Lux.UI.csproj index c2f7c67e..a02c5661 100644 --- a/Lux.UI/Lux.UI.csproj +++ b/Lux.UI/Lux.UI.csproj @@ -5,7 +5,7 @@ enable enable aspnet-Lux.UI-a758c101-a2f4-4e38-977d-1c4887dbbd50 - 0.9.2601.1312 + 0.9.2601.1315 diff --git a/Lux.UI/temp/.placeholder.txt b/Lux.UI/temp/.placeholder.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lux.UI/temp/SOR_25_00000044.jwd b/Lux.UI/temp/SOR_25_00000044.jwd deleted file mode 100644 index ba472733..00000000 --- a/Lux.UI/temp/SOR_25_00000044.jwd +++ /dev/null @@ -1,93 +0,0 @@ -{ - "ProfilePath": "Profilo78", - "Material": "Pino", - "ColorMaterial": "Black", - "Glass": "Vetro BE 2S 4T/16/4T", - "AreaList": [ - { - "Shape": "RECTANGLE", - "DimensionList": [ - { - "Index": 1, - "Name": "Width", - "Value": 800.0 - }, - { - "Index": 2, - "Name": "Height", - "Value": 1400.0 - } - ], - "JointList": [ - { - "Index": 1, - "JointType": "FULL_H" - }, - { - "Index": 2, - "JointType": "FULL_H" - }, - { - "Index": 3, - "JointType": "FULL_H" - }, - { - "Index": 4, - "JointType": "FULL_H" - } - ], - "Threshold": "Bottom", - "BottomRail": false, - "BottomRailQty": 0, - "GroupId": 1, - "AreaList": [ - { - "IsSashVertical": true, - "SashList": [ - { - "SashId": 1, - "OpeningType": "TILTTURN_LEFT", - "MeasureType": "PERCENTAGE", - "Dimension": 100.0, - "HasHandle": true, - "JointList": [ - { - "Index": 1, - "JointType": "FULL_V" - }, - { - "Index": 2, - "JointType": "FULL_V" - }, - { - "Index": 3, - "JointType": "FULL_V" - }, - { - "Index": 4, - "JointType": "FULL_V" - } - ] - } - ], - "SashType": "NULL", - "BottomRail": false, - "BottomRailQty": 0, - "Hardware": "000545", - "HwOptionList": [], - "GroupId": 4, - "AreaList": [ - { - "FillType": "GLASS", - "GroupId": 3, - "AreaList": [], - "AreaType": "FILL" - } - ], - "AreaType": "SASH" - } - ], - "AreaType": "FRAME" - } - ] -} \ No newline at end of file diff --git a/Lux.UI/temp/SOR_25_00000048.jwd b/Lux.UI/temp/SOR_25_00000048.jwd deleted file mode 100644 index 4e233e5d..00000000 --- a/Lux.UI/temp/SOR_25_00000048.jwd +++ /dev/null @@ -1,165 +0,0 @@ -{ - "ProfilePath": "Profilo78", - "Material": "Pino", - "ColorMaterial": "Black", - "Glass": "Vetro BE 2S 4T/16/4T", - "AreaList": [ - { - "Shape": "RECTANGLE", - "DimensionList": [ - { - "Index": 1, - "Name": "Width", - "Value": 1800.0 - }, - { - "Index": 2, - "Name": "Height", - "Value": 2100.0 - } - ], - "JointList": [ - { - "Index": 1, - "JointType": "FULL_H" - }, - { - "Index": 2, - "JointType": "FULL_H" - }, - { - "Index": 3, - "JointType": "FULL_H" - }, - { - "Index": 4, - "JointType": "FULL_H" - } - ], - "Threshold": "Bottom", - "BottomRail": false, - "BottomRailQty": 0, - "GroupId": 1, - "AreaList": [ - { - "IsSashVertical": true, - "SashList": [ - { - "SashId": 1, - "OpeningType": "TILTTURN_LEFT", - "MeasureType": "PERCENTAGE", - "Dimension": 50.0, - "HasHandle": true, - "JointList": [ - { - "Index": 1, - "JointType": "FULL_V" - }, - { - "Index": 2, - "JointType": "FULL_V" - }, - { - "Index": 3, - "JointType": "FULL_V" - }, - { - "Index": 4, - "JointType": "FULL_V" - } - ] - }, - { - "SashId": 2, - "OpeningType": "TURNONLY_RIGHT", - "MeasureType": "PERCENTAGE", - "Dimension": 50.0, - "HasHandle": false, - "JointList": [ - { - "Index": 1, - "JointType": "FULL_V" - }, - { - "Index": 2, - "JointType": "FULL_V" - }, - { - "Index": 3, - "JointType": "FULL_V" - }, - { - "Index": 4, - "JointType": "FULL_V" - } - ] - } - ], - "SashType": "NULL", - "BottomRail": false, - "BottomRailQty": 0, - "Hardware": "000548", - "HwOptionList": [ - { - "Name": "Entrata", - "Value": "15" - }, - { - "Name": "LavManigliaPassante", - "Value": "false" - }, - { - "Name": "PosizioneForoCilindro", - "Value": "sopra" - }, - { - "Name": "Deviatore", - "Value": "false" - }, - { - "Name": "ModelloCilindro", - "Value": "c999" - }, - { - "Name": "LavCilindroPassante", - "Value": "false" - }, - { - "Name": "HMan", - "Value": "500" - } - ], - "GroupId": 4, - "AreaList": [ - { - "GroupId": 5, - "AreaList": [ - { - "FillType": "GLASS", - "GroupId": 3, - "AreaList": [], - "AreaType": "FILL" - } - ], - "AreaType": "SPLITTED" - }, - { - "GroupId": 6, - "AreaList": [ - { - "FillType": "GLASS", - "GroupId": 7, - "AreaList": [], - "AreaType": "FILL" - } - ], - "AreaType": "SPLITTED" - } - ], - "AreaType": "SASH" - } - ], - "AreaType": "FRAME" - } - ] -} \ No newline at end of file diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html index dd935f26..be2c9d50 100644 --- a/Resources/ChangeLog.html +++ b/Resources/ChangeLog.html @@ -1,6 +1,6 @@ LUX - Web Windows MES -

    Versione: 0.9.2601.1312

    +

    Versione: 0.9.2601.1315


    Note di rilascio:
    • diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt index 101d1482..deaca5f6 100644 --- a/Resources/VersNum.txt +++ b/Resources/VersNum.txt @@ -1 +1 @@ -0.9.2601.1312 +0.9.2601.1315 diff --git a/Resources/manifest.xml b/Resources/manifest.xml index 486cfaa4..af5888e2 100644 --- a/Resources/manifest.xml +++ b/Resources/manifest.xml @@ -1,6 +1,6 @@ - 0.9.2601.1312 + 0.9.2601.1315 http://nexus.steamware.net/repository/SWS/GPW/stable/GPW.UI.zip http://nexus.steamware.net/repository/SWS/GPW/stable/ChangeLog.html false