feature: In-App Simulation Runner (Backend)
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using VigilCare.Simulation;
|
||||
|
||||
public sealed class SimulationClientFactory : ISimulationClientFactory
|
||||
{
|
||||
private readonly IHttpClientFactory _http;
|
||||
private readonly SimulationOptions _options;
|
||||
|
||||
public SimulationClientFactory(IHttpClientFactory http, IOptions<SimulationOptions> options)
|
||||
{
|
||||
_http = http;
|
||||
_options = options.Value;
|
||||
}
|
||||
|
||||
public async Task<VigilCareApiClient> CreateAsync(CancellationToken ct = default)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_options.RunnerPassword))
|
||||
throw new InvalidOperationException(
|
||||
"Simulation:RunnerPassword is required when Simulation:Enabled is true.");
|
||||
|
||||
var http = _http.CreateClient("simulation-loopback");
|
||||
var client = new VigilCareApiClient(http);
|
||||
await client.LoginAsync(_options.RunnerUsername, _options.RunnerPassword);
|
||||
return client;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user