mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 06:46:30 +00:00
9a16099194
rework inference events and handling todo: add Medias table and reflect recognition status there
34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
using Azaion.Common.Database;
|
|
using Azaion.Common.DTO;
|
|
using Azaion.Common.Events;
|
|
using MediatR;
|
|
using MessagePack;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Azaion.Common.Services.Inference;
|
|
|
|
public class InferenceServiceEventHandler(IInferenceService inferenceService,
|
|
IAnnotationService annotationService,
|
|
IMediator mediator,
|
|
ILogger<InferenceServiceEventHandler> logger) :
|
|
INotificationHandler<InferenceDataEvent>,
|
|
INotificationHandler<InferenceStatusEvent>,
|
|
INotificationHandler<InferenceDoneEvent>
|
|
{
|
|
|
|
public async Task Handle(InferenceDataEvent e, CancellationToken ct)
|
|
{
|
|
var annotation = await annotationService.SaveAnnotation(e.AnnotationImage, ct);
|
|
await mediator.Publish(new AnnotationAddedEvent(annotation), ct);
|
|
}
|
|
|
|
public async Task Handle(InferenceStatusEvent e, CancellationToken ct)
|
|
{
|
|
await mediator.Publish(new SetStatusTextEvent($"{e.MediaName}: {e.DetectionsCount} detections"), ct);
|
|
}
|
|
|
|
public async Task Handle(InferenceDoneEvent notification, CancellationToken cancellationToken)
|
|
{
|
|
await inferenceService.InferenceCancelTokenSource.CancelAsync();
|
|
}
|
|
} |