135 lines
4.3 KiB
C#
135 lines
4.3 KiB
C#
using DevExpress.Blazor.Reporting;
|
|
using DevExpress.XtraReports.Web.Extensions;
|
|
using Lux.Report.Data;
|
|
using Lux.Report.Data.Repository;
|
|
using Lux.Report.Data.Reports;
|
|
using Lux.Report.Data.Services;
|
|
using Lux.Report.Manager.Components;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.FileProviders;
|
|
using NLog;
|
|
using NLog.Targets;
|
|
using NLog.Web;
|
|
using StackExchange.Redis;
|
|
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 configuration = builder.Configuration;
|
|
var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version?.ToString();
|
|
logger.Info($"Lux.Report.Manager | Program.cs: startup | v.{assemblyVersion}");
|
|
logger.Info($"Current ASPNETCORE_ENVIRONMENT: {env.EnvironmentName}");
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddRazorComponents()
|
|
.AddInteractiveServerComponents();
|
|
|
|
|
|
// costruzione connectionMultiplexer redis...
|
|
string connStr = configuration.GetConnectionString("Redis") ?? "localhost";
|
|
ConnectionMultiplexer redisConn = ConnectionMultiplexer.Connect(connStr);
|
|
// registro connMultiplexer REDIS
|
|
builder.Services.AddSingleton<IConnectionMultiplexer>(redisConn);
|
|
|
|
// DataLayerContext (manca!)
|
|
var conn = builder.Configuration.GetConnectionString("Lux.All") ?? "";
|
|
builder.Services.AddDbContextFactory<ReportContext>(options =>
|
|
{
|
|
options.UseMySql(conn, ServerVersion.AutoDetect(conn), mySqlOptions =>
|
|
{
|
|
mySqlOptions.EnableStringComparisonTranslations();
|
|
})
|
|
.EnableSensitiveDataLogging(false)
|
|
.EnableDetailedErrors(true);
|
|
//.LogTo(_ => { }, Microsoft.Extensions.Logging.LogLevel.None); // disabilita EF logging
|
|
});
|
|
|
|
//builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
|
|
|
// aggiungo servizi "interni"
|
|
builder.Services.AddSingleton<IFileService, FileService>();
|
|
builder.Services.AddScoped<IReportRepository, ReportRepository>();
|
|
builder.Services.AddScoped<IReportService, ReportService>();
|
|
|
|
// aggiunta servizi DevExpress
|
|
builder.Services.AddDevExpressServerSideBlazorReportViewer();
|
|
|
|
builder.Services.AddMvc();
|
|
builder.Services.AddDevExpressBlazorReporting();
|
|
builder.WebHost.UseWebRoot("wwwroot");
|
|
builder.WebHost.UseStaticWebAssets();
|
|
builder.Services.AddScoped<ReportStorageWebExtension, CustomReportStorageWebExtension>();
|
|
|
|
|
|
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.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();
|
|
|
|
// componenti DevExpress report
|
|
app.UseDevExpressBlazorReporting();
|
|
|
|
|
|
// 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 (configuration["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();
|