fix split tile size

rework inference events and handling
todo: add Medias table and reflect recognition status there
This commit is contained in:
Oleksandr Bezdieniezhnykh
2025-09-05 16:50:09 +03:00
parent 7d68f7faee
commit 9a16099194
14 changed files with 86 additions and 47 deletions
@@ -12,32 +12,23 @@ public class InferenceServiceEventHandler(IInferenceService inferenceService,
IMediator mediator,
ILogger<InferenceServiceEventHandler> logger) :
INotificationHandler<InferenceDataEvent>,
INotificationHandler<AIAvailabilityStatusEvent>
INotificationHandler<InferenceStatusEvent>,
INotificationHandler<InferenceDoneEvent>
{
public async Task Handle(InferenceDataEvent e, CancellationToken ct)
{
try
{
if (e.Command.Message == "DONE")
{
await inferenceService.InferenceCancelTokenSource.CancelAsync();
return;
}
var annImage = MessagePackSerializer.Deserialize<AnnotationImage>(e.Command.Data, cancellationToken: ct);
var annotation = await annotationService.SaveAnnotation(annImage, ct);
await mediator.Publish(new AnnotationAddedEvent(annotation), ct);
}
catch (Exception ex)
{
logger.LogError(ex, ex.Message);
}
var annotation = await annotationService.SaveAnnotation(e.AnnotationImage, ct);
await mediator.Publish(new AnnotationAddedEvent(annotation), ct);
}
public async Task Handle(AIAvailabilityStatusEvent e, CancellationToken ct)
public async Task Handle(InferenceStatusEvent e, CancellationToken ct)
{
await mediator.Publish(new SetStatusTextEvent($"{e.MediaName}: {e.DetectionsCount} detections"), ct);
}
e.Status = AIAvailabilityEnum.Enabled;
public async Task Handle(InferenceDoneEvent notification, CancellationToken cancellationToken)
{
await inferenceService.InferenceCancelTokenSource.CancelAsync();
}
}