-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
65 lines (53 loc) · 2.15 KB
/
Program.cs
File metadata and controls
65 lines (53 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using DbDumper;
using DbDumper.Infrastructure;
using DbDumper.TUI;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Spectre.Console;
// ── Composition Root ──────────────────────────────────────────────────────────
var configuration = new ConfigurationBuilder()
.SetBasePath(AppContext.BaseDirectory)
.AddJsonFile("config/appsettings.json", optional: false, reloadOnChange: false)
.AddEnvironmentVariables("DBDUMPER_")
.Build();
var services = new ServiceCollection();
services.AddLogging(builder =>
builder
.SetMinimumLevel(LogLevel.Warning)
.AddConsole());
services.AddDbDumper(configuration);
await using var serviceProvider = services.BuildServiceProvider();
// ── Startup info ──────────────────────────────────────────────────────────────
AnsiConsole.MarkupLine(
$"[dim] settings.json → [grey]{Markup.Escape(JsonConnectionStore.FilePath)}[/][/]");
// ── Run ───────────────────────────────────────────────────────────────────────
using var cts = new CancellationTokenSource();
Console.CancelKeyPress += (_, e) =>
{
e.Cancel = true;
cts.Cancel();
AnsiConsole.WriteLine();
AnsiConsole.Write(new Rule("[dim]Até logo![/]") { Style = Style.Parse("dim mediumpurple1") });
AnsiConsole.WriteLine();
Environment.Exit(0);
};
try
{
var app = serviceProvider.GetRequiredService<DbDumperApp>();
await app.RunAsync(cts.Token);
}
catch (OperationCanceledException)
{
// graceful shutdown
}
catch (Exception ex)
{
AnsiConsole.WriteException(ex,
ExceptionFormats.ShortenPaths |
ExceptionFormats.ShortenTypes |
ExceptionFormats.ShortenMethods |
ExceptionFormats.ShowLinks);
return 1;
}
return 0;