70 lines
2.1 KiB
C#
70 lines
2.1 KiB
C#
using EgwMultiEngineManager;
|
|
using Lux.Data.Services;
|
|
using NLog;
|
|
using NLog.Web;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
var logger = LogManager.Setup()
|
|
.LoadConfigurationFromAppSettings()
|
|
.GetCurrentClassLogger();
|
|
|
|
ConfigurationManager configuration = builder.Configuration;
|
|
logger.Info("Program.cs: startup");
|
|
|
|
|
|
bool enableEgwEng = configuration.GetValue<bool>("ServerConf:EgwEngineEnab");
|
|
|
|
// Add services to the container.
|
|
|
|
builder.Services.AddControllers();
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
ExecProcessManager? myExecProcessManager = null;
|
|
|
|
// solo se abilitato da conf
|
|
if (enableEgwEng)
|
|
{
|
|
// aggiungo rif libreria EgwManager
|
|
string sCamExePath = @"c:\EgtProg\EgtEngine\EgtEngineR32.exe";
|
|
string sMainLuaPath = @"c:\Temp\EgwMultiEngineManager\Pipe.lua";
|
|
myExecProcessManager = new ExecProcessManager(sCamExePath, sMainLuaPath, 1, ExecProcessManager.ReturnModes.EVENT_);
|
|
myExecProcessManager.StartExecutionThread();
|
|
builder.Services.AddSingleton<ExecProcessManager>(myExecProcessManager);
|
|
}
|
|
builder.Services.AddSingleton<ImageCacheService>();
|
|
|
|
var app = builder.Build();
|
|
|
|
// aggiunt base URL x routing corretto
|
|
string baseUrl = configuration.GetValue<string>("ServerConf:BaseUrl") ?? "";
|
|
app.UsePathBase(baseUrl);
|
|
logger.Info($"BaseUrl: {baseUrl}");
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment() || app.Environment.IsStaging())
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
// inserisco evento in chiusura x fermare i thread di calcolo sottostanti:
|
|
// https://shazwazza.com/post/aspnet-core-application-shutdown-events/
|
|
// https://dotnetblog.asphostportal.com/how-to-handle-application-shutdown-in-asp-net-core/
|
|
app.Lifetime.ApplicationStopping.Register(() =>
|
|
{
|
|
if (myExecProcessManager != null)
|
|
{
|
|
myExecProcessManager.StopExecutionThread();
|
|
}
|
|
});
|
|
|
|
// avvio app
|
|
app.Run(); |