big refactoring. get rid of static properties and coupled architecture. prepare system for integration tests

This commit is contained in:
Oleksandr Bezdieniezhnykh
2025-11-17 13:14:05 +02:00
parent 22529c26ec
commit e7ea5a8ded
38 changed files with 808 additions and 157 deletions
@@ -20,6 +20,8 @@ public interface IInferenceClient : IDisposable
public class InferenceClient : IInferenceClient
{
private readonly ILogger<InferenceClient> _logger;
private readonly IProcessLauncher _processLauncher;
private readonly IDetectionClassProvider _classProvider;
private readonly DealerSocket _dealer = new();
private readonly NetMQPoller _poller = new();
@@ -30,12 +32,16 @@ public class InferenceClient : IInferenceClient
public InferenceClient(ILogger<InferenceClient> logger, IOptions<InferenceClientConfig> inferenceConfig,
IMediator mediator,
IOptions<LoaderClientConfig> loaderConfig)
IOptions<LoaderClientConfig> loaderConfig,
IProcessLauncher processLauncher,
IDetectionClassProvider classProvider)
{
_logger = logger;
_inferenceClientConfig = inferenceConfig.Value;
_loaderClientConfig = loaderConfig.Value;
_mediator = mediator;
_processLauncher = processLauncher;
_classProvider = classProvider;
Start();
}
@@ -43,14 +49,9 @@ public class InferenceClient : IInferenceClient
{
try
{
using var process = new Process();
process.StartInfo = new ProcessStartInfo
{
FileName = Constants.EXTERNAL_INFERENCE_PATH,
Arguments = $"-p {_inferenceClientConfig.ZeroMqPort} -lp {_loaderClientConfig.ZeroMqPort} -a {_inferenceClientConfig.ApiUrl}",
CreateNoWindow = true
};
process.Start();
_processLauncher.Launch(
Constants.EXTERNAL_INFERENCE_PATH,
$"-p {_inferenceClientConfig.ZeroMqPort} -lp {_loaderClientConfig.ZeroMqPort} -a {_inferenceClientConfig.ApiUrl}");
}
catch (Exception e)
{
@@ -77,7 +78,9 @@ public class InferenceClient : IInferenceClient
{
case CommandType.InferenceData:
var annotationImage = MessagePackSerializer.Deserialize<AnnotationImage>(remoteCommand.Data, cancellationToken: ct);
_logger.LogInformation("Received command: {AnnotationImage}", annotationImage.ToString());
var className = _classProvider.GetClassName(annotationImage);
_logger.LogInformation("Received command: Annotation {Name} {Time} - {ClassName}",
annotationImage.Name, annotationImage.TimeStr, className);
await _mediator.Publish(new InferenceDataEvent(annotationImage), ct);
break;
case CommandType.InferenceStatus: