Files
annotations/Azaion.Common/Services/Inference/InferenceServiceEventHandler.cs
T
Oleksandr Bezdieniezhnykh fd95d2ba2c add MediaHash. Step1
2025-11-17 07:46:05 +02:00

29 lines
1.0 KiB
C#

using Azaion.Common.Events;
using MediatR;
namespace Azaion.Common.Services.Inference;
public class InferenceServiceEventHandler(
IInferenceService inferenceService,
IAnnotationService annotationService,
IMediator mediator) :
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();
}
}