feature: Console Replay Simulator
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using System.CommandLine;
|
||||
|
||||
public static class ReplayCommand
|
||||
{
|
||||
public static Command Create()
|
||||
{
|
||||
var fileArg = new Argument<FileInfo>("scenario-file");
|
||||
var speedOpt = new Option<double>("--speed", () => 60, "Speed multiplier (0=instant, 1=realtime)");
|
||||
var baseUrlOpt = new Option<string>("--base-url", () => "http://localhost:5270");
|
||||
var pollOpt = new Option<bool>("--poll", () => false, "Poll alerts/scores after each cluster");
|
||||
var pollIntervalOpt = new Option<int>("--poll-interval", () => 5, "Seconds between polls");
|
||||
|
||||
var command = new Command("replay", "Replay a scenario against the API")
|
||||
{
|
||||
fileArg, speedOpt, baseUrlOpt, pollOpt, pollIntervalOpt
|
||||
};
|
||||
|
||||
command.SetHandler(async (FileInfo file, double speed, string baseUrl, bool poll, int pollInterval) =>
|
||||
{
|
||||
var scenario = ScenarioLoader.Load(file.FullName);
|
||||
var errors = ScenarioValidator.Validate(scenario);
|
||||
if (errors.Count > 0)
|
||||
{
|
||||
SimulatorConsole.Error($"Scenario validation failed with {errors.Count} error(s):");
|
||||
foreach (var err in errors) SimulatorConsole.Error($" • {err}");
|
||||
return;
|
||||
}
|
||||
|
||||
using var http = new HttpClient { BaseAddress = new Uri(baseUrl) };
|
||||
var client = new VigilCareApiClient(http);
|
||||
var poller = poll ? new ApiPoller(client) : null;
|
||||
var engine = new ReplayEngine(client, poller);
|
||||
var options = new ReplayOptions(speed, poll, pollInterval);
|
||||
|
||||
await engine.RunAsync(scenario, options);
|
||||
}, fileArg, speedOpt, baseUrlOpt, pollOpt, pollIntervalOpt);
|
||||
|
||||
return command;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user