diff --git a/MP.IOC/Controllers/IOBController.cs b/MP.IOC/Controllers/IOBController.cs index d4c0b7ae..0555f619 100644 --- a/MP.IOC/Controllers/IOBController.cs +++ b/MP.IOC/Controllers/IOBController.cs @@ -75,6 +75,7 @@ namespace MP.IOC.Controllers return Ok(answ); } +#if false /// /// GET: IOB/enabled/SIMUL_03 /// @@ -83,11 +84,10 @@ namespace MP.IOC.Controllers [HttpGet("enabled/{id}")] public async Task Enabled(string id) { - if (string.IsNullOrWhiteSpace(id)) + if (string.IsNullOrEmpty(id)) { Response.StatusCode = StatusCodes.Status400BadRequest; return "Missing ID"; - //return BadRequest("Missing ID"); } try @@ -110,28 +110,26 @@ namespace MP.IOC.Controllers Log.Error(ex, "Errore durante la verifica abilitazione per {Id}", id); Response.StatusCode = StatusCodes.Status500InternalServerError; return "Errore interno del server"; - //return StatusCode(500, "Errore interno del server"); } -#if false - if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID"); + //if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID"); - try - { - // Il metodo ora restituisce direttamente il booleano logico - bool isEnabled = await IOCService.IobInsEnabAsync(id); + //try + //{ + // // Il metodo ora restituisce direttamente il booleano logico + // bool isEnabled = await IOCService.IobInsEnabAsync(id); - return isEnabled - ? Ok("OK") - : UnprocessableEntity("NO"); - } - catch (Exception ex) - { - Log.Error(ex, "Errore durante la verifica abilitazione per {Id}", id); - return StatusCode(500, "Errore interno del server"); - } + // return isEnabled + // ? Ok("OK") + // : UnprocessableEntity("NO"); + //} + //catch (Exception ex) + //{ + // Log.Error(ex, "Errore durante la verifica abilitazione per {Id}", id); + // return StatusCode(500, "Errore interno del server"); + //} + } #endif - } /// /// Processa una chiamata POST per l'invio di un array Json di oggetti input (EVENTI) @@ -485,6 +483,7 @@ namespace MP.IOC.Controllers return Ok(actValues); } +#if false /// /// Recupera ODL corrente x macchina: /// GET: IOB/getCurrODL/SIMUL_03 @@ -508,7 +507,8 @@ namespace MP.IOC.Controllers Log.Error(exc, "Errore GetCurrODL | macchina {MachineId}", id); return StatusCode(StatusCodes.Status500InternalServerError, "NO"); } - } + } +#endif /// /// Restituisce la quantità pezzi dell'odl correntemente in lavorazione sulla macchina... @@ -1227,6 +1227,7 @@ namespace MP.IOC.Controllers return Ok(answ); } +#if false /// /// SALVA Counter x macchina restituendo il valore appena inviato o, se mancasse chiave /// redis, valore da DB /// @@ -1257,7 +1258,8 @@ namespace MP.IOC.Controllers return StatusCode(StatusCodes.Status500InternalServerError, "NO"); } return Ok(answ); - } + } +#endif /// /// Salva associazione tra macchina, device IOB chiamante e sue info diff --git a/MP.IOC/Endpoints/IobEndpoints.cs b/MP.IOC/Endpoints/IobEndpoints.cs new file mode 100644 index 00000000..f998de18 --- /dev/null +++ b/MP.IOC/Endpoints/IobEndpoints.cs @@ -0,0 +1,112 @@ +using MP.Data.Services.IOC; +using NLog; + +namespace MP.IOC.Endpoints +{ + public static class IobEndpoints + { + public static void MapIobHighPerformanceEndpoints(this IEndpointRouteBuilder app) + { + // 1. Root di test base: api/IOB e api/IOB/alive + app.MapGet("api/IOB", () => "OK"); + app.MapGet("api/IOB/alive", () => "OK"); + + // 2. Il metodo Enabled ad alto traffico: api/IOB/enabled/{id} + app.MapGet("api/IOB/enabled/{id}", async (string id, IIocService iocService, HttpContext context) => + { + if (string.IsNullOrEmpty(id)) + { + context.Response.StatusCode = StatusCodes.Status400BadRequest; + return "Missing ID"; + } + + try + { + bool isEnabled = await iocService.IobInsEnabAsync(id); + + if (!isEnabled) + { + context.Response.StatusCode = StatusCodes.Status422UnprocessableEntity; + return "NO"; + } + + return "OK"; + } + catch (Exception ex) + { + Log.Error(ex, "Errore durante la verifica abilitazione per {Id}", id); + context.Response.StatusCode = StatusCodes.Status500InternalServerError; + return "Errore interno del server"; + } + }); + + // 3. Metodo: SetCounter (api/IOB/setCounter/{id}?counter=10) + // Nota: 'counter' viene letto automaticamente dalla Query String grazie al Model Binding automatico + app.MapGet("api/IOB/setCounter/{id}", async (string id, string counter, IIocService iocService, HttpContext context) => + { + if (string.IsNullOrEmpty(id)) + { + context.Response.StatusCode = StatusCodes.Status400BadRequest; + return "Missing ID"; + } + + // Ottimizzazione: esegui il Replace solo se il carattere è effettivamente presente + if (id.Contains('|')) + { + id = id.Replace('|', '#'); + } + + // Se il log di Debug è disattivato in produzione, eviti l'allocazione della stringa interpolata + if (Log.IsDebugEnabled) + { + Log.Debug($"Salvataggio counter | id: {id} | pzCount: {counter}"); + } + + try + { + string answ = await iocService.SaveCounterAsync(id, counter); + return answ; // Ritorna direttamente la stringa (Status 200 di default, zero allocazioni di ObjectResult) + } + catch (Exception exc) + { + // Usiamo la stringa formattata standard di NLog per evitare Environment.NewLine manuale + Log.Error(exc, "Errore in SetCounter per macchina {MachineId}", id); + context.Response.StatusCode = StatusCodes.Status500InternalServerError; + return "NO"; + } + }); + + // 4. Metodo: GetCurrODL (api/IOB/getCurrODL/{id}) + app.MapGet("api/IOB/getCurrODL/{id}", async (string id, IIocService iocService, HttpContext context) => + { + if (string.IsNullOrEmpty(id)) + { + context.Response.StatusCode = StatusCodes.Status400BadRequest; + return "Missing ID"; + } + + if (id.Contains('|')) + { + id = id.Replace('|', '#'); + } + + try + { + var odl = await iocService.GetCurrOdlAsync(id); + + // Ottimizzazione: Se 'odl' è già una stringa, ritornala direttamente. + // Se è un oggetto o un numero, il C# gestirà l'estrazione. Evitiamo $"{odl}" che alloca memoria inutilmente. + return odl?.ToString() ?? string.Empty; + } + catch (Exception exc) + { + Log.Error(exc, "Errore GetCurrODL | macchina {MachineId}", id); + context.Response.StatusCode = StatusCodes.Status500InternalServerError; + return "NO"; + } + }); + + } + private static Logger Log = LogManager.GetCurrentClassLogger(); + } +} \ No newline at end of file diff --git a/MP.IOC/MP.IOC.csproj b/MP.IOC/MP.IOC.csproj index b6338f70..a51454d0 100644 --- a/MP.IOC/MP.IOC.csproj +++ b/MP.IOC/MP.IOC.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 8.16.2606.1120 + 8.16.2606.1208 diff --git a/MP.IOC/Program.cs b/MP.IOC/Program.cs index e8b04c59..376940a2 100644 --- a/MP.IOC/Program.cs +++ b/MP.IOC/Program.cs @@ -6,6 +6,7 @@ using MP.Core.Conf; using MP.Data; using MP.IOC.Components; using MP.IOC.Data; +using MP.IOC.Endpoints; using MP.IOC.Services; using NLog; using NLog.Web; @@ -170,12 +171,12 @@ app.UseDefaultFiles(); app.UseStaticFiles(); app.UseAntiforgery(); -// Mappatura delle API +// Mappatura MinimalApi da file ext x metodi high perf +app.MapIobHighPerformanceEndpoints(); + +// Mappatura delle API "standard" app.MapControllers(); -// mappa del base url check -app.MapGet("api/IOB/", () => Results.Ok("OK")); -app.MapGet("api/IOB/alive", () => Results.Ok("OK")); // Mappatura della Dashboard Blazor app.MapRazorComponents() diff --git a/MP.IOC/Resources/ChangeLog.html b/MP.IOC/Resources/ChangeLog.html index 62ff9fcb..19d81522 100644 --- a/MP.IOC/Resources/ChangeLog.html +++ b/MP.IOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-IOC -

Versione: 8.16.2606.1120

+

Versione: 8.16.2606.1208


Note di rilascio:
  • diff --git a/MP.IOC/Resources/VersNum.txt b/MP.IOC/Resources/VersNum.txt index a0507993..fe6ac8c4 100644 --- a/MP.IOC/Resources/VersNum.txt +++ b/MP.IOC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.1120 +8.16.2606.1208 diff --git a/MP.IOC/Resources/manifest.xml b/MP.IOC/Resources/manifest.xml index 35c9bdcd..0f90abd3 100644 --- a/MP.IOC/Resources/manifest.xml +++ b/MP.IOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.1120 + 8.16.2606.1208 https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/MP.IOC.zip https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/ChangeLog.html false diff --git a/MP.IOC/appsettings.json b/MP.IOC/appsettings.json index c70d3442..4bd6bf3c 100644 --- a/MP.IOC/appsettings.json +++ b/MP.IOC/appsettings.json @@ -25,7 +25,7 @@ "logfile": { "type": "File", "fileName": "${basedir}/logs/${shortdate}.log", - "keepFileOpen": false, + "keepFileOpen": true, "archiveEvery": "Day", "archiveFileName": "${basedir}/logs/old/${shortdate}_{#}.log", "archiveNumbering": "DateAndSequence", diff --git a/MP.RIOC/MP.RIOC.csproj b/MP.RIOC/MP.RIOC.csproj index 87280c4b..9d41d7d1 100644 --- a/MP.RIOC/MP.RIOC.csproj +++ b/MP.RIOC/MP.RIOC.csproj @@ -5,7 +5,7 @@ enable enable MP.RIOC - 8.16.2606.1120 + 8.16.2606.1208 InProcess diff --git a/MP.RIOC/Program.cs b/MP.RIOC/Program.cs index 489b29dd..fbf3066d 100644 --- a/MP.RIOC/Program.cs +++ b/MP.RIOC/Program.cs @@ -161,6 +161,10 @@ app.MapWhen(ctx => ctx.Request.Path.StartsWithSegments(routePath, StringComparis }); }); +// test per ambiente di esecuzione InProcess... +app.MapGet("api/alive", () => + $"OK - Girando in: {System.Diagnostics.Process.GetCurrentProcess().ProcessName}"); + // 6. Definizione degli Endpoints locali app.MapRazorPages(); diff --git a/MP.RIOC/Properties/PublishProfiles/IIS01.pubxml b/MP.RIOC/Properties/PublishProfiles/IIS01.pubxml index 6c359c50..ca4fed85 100644 --- a/MP.RIOC/Properties/PublishProfiles/IIS01.pubxml +++ b/MP.RIOC/Properties/PublishProfiles/IIS01.pubxml @@ -1,33 +1,34 @@  - - MSDeploy - true - Release - Any CPU - https://iis01.egalware.com/MP/RIOC/ - false - b9188473-f4ae-4f9f-be2d-70edaace0db9 - false - https://iis01.egalware.com:8172/MsDeploy.axd - Default Web Site/MP/RIOC - - true - WMSVC - true - true - jenkins - <_SavePWD>true - <_TargetId>IISWebDeploy - net8.0 - win-x64 - true - - - - filePath - logs\\.*\.log$ - - + + MSDeploy + true + Release + Any CPU + https://iis01.egalware.com/MP/RIOC/ + false + b9188473-f4ae-4f9f-be2d-70edaace0db9 + false + https://iis01.egalware.com:8172/MsDeploy.axd + Default Web Site/MP/RIOC + + true + WMSVC + true + true + jenkins + <_SavePWD>true + <_TargetId>IISWebDeploy + net8.0 + win-x64 + true + True + + + + filePath + logs\\.*\.log$ + + \ No newline at end of file diff --git a/MP.RIOC/Resources/ChangeLog.html b/MP.RIOC/Resources/ChangeLog.html index 2f4766a9..fd556bd8 100644 --- a/MP.RIOC/Resources/ChangeLog.html +++ b/MP.RIOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-RIOC -

    Versione: 8.16.2606.1120

    +

    Versione: 8.16.2606.1208


    Note di rilascio:
    • diff --git a/MP.RIOC/Resources/VersNum.txt b/MP.RIOC/Resources/VersNum.txt index a0507993..fe6ac8c4 100644 --- a/MP.RIOC/Resources/VersNum.txt +++ b/MP.RIOC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.1120 +8.16.2606.1208 diff --git a/MP.RIOC/Resources/manifest.xml b/MP.RIOC/Resources/manifest.xml index 56ff116c..af3135c8 100644 --- a/MP.RIOC/Resources/manifest.xml +++ b/MP.RIOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.1120 + 8.16.2606.1208 https://nexus.steamware.net/repository/SWS/MP-RIOC/stable/LAST/MP.RIOC.zip https://nexus.steamware.net/repository/SWS/MP-RIOC/stable/LAST/ChangeLog.html false