Correction PDF
This commit is contained in:
35
Program.cs
35
Program.cs
@@ -26,14 +26,31 @@ namespace administration
|
||||
if (string.IsNullOrEmpty(dbConnection))
|
||||
throw new Exception("❌ ADMIN_DB_CONNECTION est introuvable.");
|
||||
|
||||
builder.Services.AddDbContext<FinancesContext>(options =>
|
||||
options.UseSqlServer(dbConnection, sqlOptions => sqlOptions.EnableRetryOnFailure()));
|
||||
bool inContainer = Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER") == "true";
|
||||
string hostOverride = builder.Configuration["DB_HOST"] ?? Environment.GetEnvironmentVariable("DB_HOST");
|
||||
|
||||
builder.Services.AddDbContext<HelloFreshContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("HelloFreshConnection")));
|
||||
string Fix(string? cs, string? dbNameFallback)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(cs) && !string.IsNullOrWhiteSpace(dbNameFallback))
|
||||
{
|
||||
var def = builder.Configuration.GetConnectionString("DefaultConnection") ?? "";
|
||||
if (!string.IsNullOrWhiteSpace(def))
|
||||
cs = System.Text.RegularExpressions.Regex.Replace(def, @"Database=([^;]+)", $"Database={dbNameFallback}");
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(cs) && !inContainer && !string.IsNullOrWhiteSpace(hostOverride))
|
||||
{
|
||||
cs = cs.Replace("Server=sqlserver,1433", $"Server={hostOverride},1433", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
return cs ?? "";
|
||||
}
|
||||
|
||||
builder.Services.AddDbContext<LayoutDataContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||
var csLayout = Fix(builder.Configuration.GetConnectionString("DefaultConnection"), "LayoutData");
|
||||
var csHello = Fix(builder.Configuration.GetConnectionString("HelloFresh"), "HelloFresh");
|
||||
var csFinance = Fix(builder.Configuration.GetConnectionString("Finances"), "Finances");
|
||||
|
||||
builder.Services.AddDbContext<LayoutDataContext>(o => o.UseSqlServer(csLayout));
|
||||
builder.Services.AddDbContext<HelloFreshContext>(o => o.UseSqlServer(csHello));
|
||||
builder.Services.AddDbContext<FinancesContext>(o => o.UseSqlServer(csFinance));
|
||||
|
||||
AppSettings.Initialize(builder.Configuration);
|
||||
builder.Services.AddSingleton<OllamaService>();
|
||||
@@ -118,6 +135,12 @@ var ollamaBuilder = builder.Services.AddHttpClient("ollama", (sp, client) =>
|
||||
var app = builder.Build();
|
||||
// ==============================================
|
||||
// 6️⃣ Pipeline
|
||||
app.MapGet("/_dbping", async (HelloFreshContext hf, LayoutDataContext ld) =>
|
||||
{
|
||||
try { await hf.Database.ExecuteSqlRawAsync("SELECT 1"); } catch (Exception ex) { return Results.Problem($"HelloFresh: {ex.GetBaseException().Message}"); }
|
||||
try { await ld.Database.ExecuteSqlRawAsync("SELECT 1"); } catch (Exception ex) { return Results.Problem($"LayoutData: {ex.GetBaseException().Message}"); }
|
||||
return Results.Ok("OK");
|
||||
});
|
||||
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user