feat: load legacy Cuts and Res runtime assets
This commit is contained in:
@@ -25,11 +25,10 @@ Console.CancelKeyPress += (_, eventArgs) =>
|
||||
cancellation.Cancel();
|
||||
};
|
||||
|
||||
var configurationPath = GetConfigurationPath(args);
|
||||
|
||||
try
|
||||
{
|
||||
var runtime = DatabaseRuntime.CreateDefault(configurationPath);
|
||||
var selection = CreateRuntimeSelection(args);
|
||||
var runtime = selection.Runtime;
|
||||
var statuses = await runtime.HealthService.CheckAllAsync(cancellation.Token);
|
||||
|
||||
foreach (var status in statuses)
|
||||
@@ -59,6 +58,7 @@ try
|
||||
await NxtThemeRestoreDbAudit.RunAsync(
|
||||
runtime.Executor,
|
||||
runtime.Options.MariaDb,
|
||||
selection.ReferenceMariaDb,
|
||||
cancellation.Token);
|
||||
await VerifyLegacyComparisonImportAsync(runtime.Executor, cancellation.Token);
|
||||
|
||||
@@ -131,23 +131,63 @@ static string FormatNullableBoolean(bool? value) => value switch
|
||||
static string FormatProviderErrorCode(int? value) =>
|
||||
value?.ToString(CultureInfo.InvariantCulture) ?? "none";
|
||||
|
||||
static string? GetConfigurationPath(string[] arguments)
|
||||
static DatabaseSmokeRuntimeSelection CreateRuntimeSelection(string[] arguments)
|
||||
{
|
||||
if (arguments.Length == 0)
|
||||
{
|
||||
return null;
|
||||
return CreateJsonRuntimeSelection(configurationPath: null);
|
||||
}
|
||||
|
||||
if (arguments.Length == 2 &&
|
||||
arguments[0].Equals("--config", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return arguments[1];
|
||||
return CreateJsonRuntimeSelection(arguments[1]);
|
||||
}
|
||||
|
||||
if (arguments.Length == 2 &&
|
||||
arguments[0].Equals("--legacy-runtime-root", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var root = Path.GetFullPath(arguments[1]);
|
||||
var iniPath = Path.Combine(root, "Res", "MmoneyCoder.ini");
|
||||
if (!File.Exists(iniPath))
|
||||
{
|
||||
throw new DatabaseConfigurationException(
|
||||
"The legacy runtime root does not contain Res\\MmoneyCoder.ini.");
|
||||
}
|
||||
|
||||
// Keep the selected file's endpoint as the comparison reference before
|
||||
// environment overrides are applied. Credentials never leave the
|
||||
// loader-owned DatabaseOptions instance.
|
||||
var selectedOptions = new LegacyIniDatabaseOptionsLoader(_ => null).Load(iniPath);
|
||||
var runtime = DatabaseRuntime.CreateLegacyExecutableDefault(
|
||||
root,
|
||||
fallbackConfigurationPath: Path.Combine(root, "missing-database.json"),
|
||||
legacyOverridePath: Path.Combine(root, "missing-legacy.ini"));
|
||||
return new DatabaseSmokeRuntimeSelection(
|
||||
runtime,
|
||||
MariaDbEndpointReference.From(selectedOptions.MariaDb));
|
||||
}
|
||||
|
||||
throw new DatabaseConfigurationException(
|
||||
"Usage: MBN_STOCK_WEBVIEW.DbSmoke [--config <path>|--manual-import-audit|--manual-import-fixture]");
|
||||
"Usage: MBN_STOCK_WEBVIEW.DbSmoke [--config <path>|--legacy-runtime-root <bin-debug-path>|--manual-import-audit|--manual-import-fixture]");
|
||||
}
|
||||
|
||||
static DatabaseSmokeRuntimeSelection CreateJsonRuntimeSelection(string? configurationPath)
|
||||
{
|
||||
var configuredOptions = new DatabaseOptionsLoader(_ => null).Load(configurationPath);
|
||||
var runtime = DatabaseRuntime.CreateDefault(configurationPath);
|
||||
var configuredMariaDb = configuredOptions.MariaDb;
|
||||
var reference = HasCompleteEndpointIdentity(configuredMariaDb)
|
||||
? MariaDbEndpointReference.From(configuredMariaDb)
|
||||
: MariaDbEndpointReference.From(runtime.Options.MariaDb);
|
||||
return new DatabaseSmokeRuntimeSelection(runtime, reference);
|
||||
}
|
||||
|
||||
static bool HasCompleteEndpointIdentity(MariaDbDatabaseOptions options) =>
|
||||
!string.IsNullOrWhiteSpace(options.Host) &&
|
||||
options.Port is >= 1 and <= 65_535 &&
|
||||
!string.IsNullOrWhiteSpace(options.Database);
|
||||
|
||||
static async Task VerifyLegacyComparisonImportAsync(
|
||||
IDataQueryExecutor executor,
|
||||
CancellationToken cancellationToken)
|
||||
@@ -711,3 +751,7 @@ static async Task VerifyTradingHaltSelectorAsync(
|
||||
Console.WriteLine(
|
||||
$"TradingHaltSelector: {result.Items.Count.ToString(CultureInfo.InvariantCulture)} rows");
|
||||
}
|
||||
|
||||
internal sealed record DatabaseSmokeRuntimeSelection(
|
||||
DatabaseRuntime Runtime,
|
||||
MariaDbEndpointReference ReferenceMariaDb);
|
||||
|
||||
Reference in New Issue
Block a user