Files
2026-04-30 17:12:28 +02:00

163 lines
4.8 KiB
C#

using DevExpress.Blazor.Reporting;
using Lux.Report.Data.Services;
using Lux.Report.Server.Components;
using Microsoft.AspNetCore.Localization;
using Microsoft.Extensions.FileProviders;
using NLog;
using NLog.Web;
using System.Globalization;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args);
// recupero env corrente
var env = builder.Environment;
var logger = LogManager.Setup()
.LoadConfigurationFromAppSettings()
.GetCurrentClassLogger();
ConfigurationManager _config = builder.Configuration;
var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version?.ToString();
logger.Info($"Lux.Report.Server | Program.cs: startup | v.{assemblyVersion}");
logger.Info($"Current ASPNETCORE_ENVIRONMENT: {env.EnvironmentName}");
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
// aggiungo servizi "interni"
builder.Services.AddSingleton<IFileService, FileService>();
// aggiunta servizi DevExpress
builder.Services.AddDevExpressServerSideBlazorReportViewer();
builder.Services.AddMvc();
builder.Services.AddDevExpressBlazorReporting();
// servizio x generazione report
builder.Services.AddScoped<IPdfReportService, PdfReportService>();
// build applicazione
var app = builder.Build();
// aggiunt base URL x routing corretto
string baseUrl = _config.GetValue<string>("ServerConf:BaseUrl") ?? "";
app.UsePathBase(baseUrl);
logger.Info($"BaseUrl: {baseUrl}");
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAntiforgery();
// calcolo parametri base...
string apiUrl = _config.GetValue<string>("ServerConf:ApiBaseUrl") ?? "https://iis01.egalware.com/lux/srv/api";
string imgUrl = _config.GetValue<string>("ServerConf:ImageUrl") ?? "image";
string dataUrl = _config.GetValue<string>("ServerConf:DataUrl") ?? "report";
// calcolo valori specifici del report
string imgFullUrl = $"{apiUrl}/{imgUrl}/";
app.MapGet("/download", async (
int? reqId,
string? repType,
string? selFile,
string? codGroup,
IPdfReportService pdfService
) =>
{
var missing = new List<string>();
if (reqId is null) missing.Add(nameof(reqId));
if (string.IsNullOrWhiteSpace(repType)) missing.Add(nameof(repType));
if (string.IsNullOrWhiteSpace(selFile)) missing.Add(nameof(selFile));
if (missing.Count > 0)
return Results.BadRequest(new { Missing = missing });
//string dataReportUrl = "offert"; // da recuperare dal DB
string dataReportUrl = "";
switch (repType)
{
case "Offerta":
dataReportUrl = "offert";
break;
case "Ordine":
dataReportUrl = "order";
break;
case "Template":
dataReportUrl = "template";
break;
case "MaterialReqOrd":
dataReportUrl = "matreq-sale-ord";
break;
case "MaterialReqOrdRow":
dataReportUrl = "matreq-sale-ord-row";
break;
case "BuyOrder":
dataReportUrl = "buyorder";
break;
}
string dataFullUrl = $"{apiUrl}/{dataUrl}/{dataReportUrl}";
var pdf = await pdfService.GeneratePdfAsync(reqId.Value, repType, selFile, codGroup, imgFullUrl, dataFullUrl);
string fName = $"{repType}_{reqId:00000000}.pdf";
return Results.File(pdf, "application/pdf", fName);
});
// cultura IT...
var supportedCultures = new[]{
new CultureInfo("it-IT")
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("it-IT"),
SupportedCultures = supportedCultures,
FallBackToParentCultures = false
});
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("it-IT");
// gestione fileshare x uploads: verifico da conf se sia linux o windows x file da accedere...
if (_config["ServerConf:HostOs"] == "Win")
{
app.UseFileServer(new FileServerOptions
{
FileProvider = new PhysicalFileProvider(@"\\stor01\TEAM DRIVES\40_FileUpload\LuxUploads"),
RequestPath = new PathString("/unsafe_uploads"),
EnableDirectoryBrowsing = true
//EnableDirectoryBrowsing = false
});
}
else
{
app.UseFileServer(new FileServerOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "unsafe_uploads")),
RequestPath = new PathString("/unsafe_uploads"),
EnableDirectoryBrowsing = true
//EnableDirectoryBrowsing = false
});
}
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();