Aggiunta metodi con MinimalApi
This commit is contained in:
@@ -75,6 +75,7 @@ namespace MP.IOC.Controllers
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// GET: IOB/enabled/SIMUL_03
|
||||
/// </summary>
|
||||
@@ -83,11 +84,10 @@ namespace MP.IOC.Controllers
|
||||
[HttpGet("enabled/{id}")]
|
||||
public async Task<string> 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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// <summary>
|
||||
/// 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
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce la quantità pezzi dell'odl correntemente in lavorazione sulla macchina...
|
||||
@@ -1227,6 +1227,7 @@ namespace MP.IOC.Controllers
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// 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
|
||||
|
||||
/// <summary>
|
||||
/// Salva associazione tra macchina, device IOB chiamante e sue info
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>8.16.2606.1120</Version>
|
||||
<Version>8.16.2606.1208</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+5
-4
@@ -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<App>()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MP-IOC </i>
|
||||
<h4>Versione: 8.16.2606.1120</h4>
|
||||
<h4>Versione: 8.16.2606.1208</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
8.16.2606.1120
|
||||
8.16.2606.1208
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>8.16.2606.1120</version>
|
||||
<version>8.16.2606.1208</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/MP.IOC.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>MP.RIOC</RootNamespace>
|
||||
<Version>8.16.2606.1120</Version>
|
||||
<Version>8.16.2606.1208</Version>
|
||||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -1,33 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<WebPublishMethod>MSDeploy</WebPublishMethod>
|
||||
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
|
||||
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
|
||||
<LastUsedPlatform>Any CPU</LastUsedPlatform>
|
||||
<SiteUrlToLaunchAfterPublish>https://iis01.egalware.com/MP/RIOC/</SiteUrlToLaunchAfterPublish>
|
||||
<ExcludeApp_Data>false</ExcludeApp_Data>
|
||||
<ProjectGuid>b9188473-f4ae-4f9f-be2d-70edaace0db9</ProjectGuid>
|
||||
<SelfContained>false</SelfContained>
|
||||
<MSDeployServiceURL>https://iis01.egalware.com:8172/MsDeploy.axd</MSDeployServiceURL>
|
||||
<DeployIisAppPath>Default Web Site/MP/RIOC</DeployIisAppPath>
|
||||
<RemoteSitePhysicalPath />
|
||||
<SkipExtraFilesOnServer>true</SkipExtraFilesOnServer>
|
||||
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
|
||||
<EnableMSDeployBackup>true</EnableMSDeployBackup>
|
||||
<EnableMsDeployAppOffline>true</EnableMsDeployAppOffline>
|
||||
<UserName>jenkins</UserName>
|
||||
<_SavePWD>true</_SavePWD>
|
||||
<_TargetId>IISWebDeploy</_TargetId>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<PublishReadyToRun>true</PublishReadyToRun>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<MsDeploySkipRules Include="SkipLogFiles">
|
||||
<ObjectName>filePath</ObjectName>
|
||||
<AbsolutePath>logs\\.*\.log$</AbsolutePath>
|
||||
</MsDeploySkipRules>
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<WebPublishMethod>MSDeploy</WebPublishMethod>
|
||||
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
|
||||
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
|
||||
<LastUsedPlatform>Any CPU</LastUsedPlatform>
|
||||
<SiteUrlToLaunchAfterPublish>https://iis01.egalware.com/MP/RIOC/</SiteUrlToLaunchAfterPublish>
|
||||
<ExcludeApp_Data>false</ExcludeApp_Data>
|
||||
<ProjectGuid>b9188473-f4ae-4f9f-be2d-70edaace0db9</ProjectGuid>
|
||||
<SelfContained>false</SelfContained>
|
||||
<MSDeployServiceURL>https://iis01.egalware.com:8172/MsDeploy.axd</MSDeployServiceURL>
|
||||
<DeployIisAppPath>Default Web Site/MP/RIOC</DeployIisAppPath>
|
||||
<RemoteSitePhysicalPath />
|
||||
<SkipExtraFilesOnServer>true</SkipExtraFilesOnServer>
|
||||
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
|
||||
<EnableMSDeployBackup>true</EnableMSDeployBackup>
|
||||
<EnableMsDeployAppOffline>true</EnableMsDeployAppOffline>
|
||||
<UserName>jenkins</UserName>
|
||||
<_SavePWD>true</_SavePWD>
|
||||
<_TargetId>IISWebDeploy</_TargetId>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<PublishReadyToRun>true</PublishReadyToRun>
|
||||
<AllowUntrustedCertificate>True</AllowUntrustedCertificate>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<MsDeploySkipRules Include="SkipLogFiles">
|
||||
<ObjectName>filePath</ObjectName>
|
||||
<AbsolutePath>logs\\.*\.log$</AbsolutePath>
|
||||
</MsDeploySkipRules>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MP-RIOC </i>
|
||||
<h4>Versione: 8.16.2606.1120</h4>
|
||||
<h4>Versione: 8.16.2606.1208</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
8.16.2606.1120
|
||||
8.16.2606.1208
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>8.16.2606.1120</version>
|
||||
<version>8.16.2606.1208</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-RIOC/stable/LAST/MP.RIOC.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-RIOC/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
Reference in New Issue
Block a user