mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 11:06:30 +00:00
gps matcher async
put cryptography lib to fixed version fix race condition bug in queue handler add lock to db writing and backup to file db on each write
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using Azaion.Annotator.DTO;
|
||||
using Azaion.Common;
|
||||
using Azaion.Common.Database;
|
||||
using Azaion.Common.DTO;
|
||||
using Azaion.Common.DTO.Config;
|
||||
using Azaion.Common.Events;
|
||||
using Azaion.Common.Extensions;
|
||||
using Azaion.Common.Services;
|
||||
using Azaion.CommonSecurity.DTO;
|
||||
using Azaion.CommonSecurity.Services;
|
||||
using LibVLCSharp.Shared;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -27,7 +28,10 @@ public class AnnotatorEventHandler(
|
||||
ILogger<AnnotatorEventHandler> logger,
|
||||
IOptions<DirectoriesConfig> dirConfig,
|
||||
IOptions<AnnotationConfig> annotationConfig,
|
||||
IInferenceService inferenceService)
|
||||
IInferenceService inferenceService,
|
||||
IDbFactory dbFactory,
|
||||
IAzaionApi api,
|
||||
FailsafeAnnotationsProducer producer)
|
||||
:
|
||||
INotificationHandler<KeyEvent>,
|
||||
INotificationHandler<AnnClassSelectedEvent>,
|
||||
@@ -52,7 +56,7 @@ public class AnnotatorEventHandler(
|
||||
{ Key.PageDown, PlaybackControlEnum.Next },
|
||||
};
|
||||
|
||||
public async Task Handle(AnnClassSelectedEvent notification, CancellationToken cancellationToken)
|
||||
public async Task Handle(AnnClassSelectedEvent notification, CancellationToken ct)
|
||||
{
|
||||
SelectClass(notification.DetectionClass);
|
||||
await Task.CompletedTask;
|
||||
@@ -66,7 +70,7 @@ public class AnnotatorEventHandler(
|
||||
mainWindow.LvClasses.SelectNum(detClass.Id);
|
||||
}
|
||||
|
||||
public async Task Handle(KeyEvent keyEvent, CancellationToken cancellationToken = default)
|
||||
public async Task Handle(KeyEvent keyEvent, CancellationToken ct = default)
|
||||
{
|
||||
if (keyEvent.WindowEnum != WindowEnum.Annotator)
|
||||
return;
|
||||
@@ -82,7 +86,7 @@ public class AnnotatorEventHandler(
|
||||
SelectClass((DetectionClass)mainWindow.LvClasses.DetectionDataGrid.Items[keyNumber.Value]!);
|
||||
|
||||
if (_keysControlEnumDict.TryGetValue(key, out var value))
|
||||
await ControlPlayback(value, cancellationToken);
|
||||
await ControlPlayback(value, ct);
|
||||
|
||||
if (key == Key.R)
|
||||
await mainWindow.AutoDetect();
|
||||
@@ -91,10 +95,10 @@ public class AnnotatorEventHandler(
|
||||
switch (key)
|
||||
{
|
||||
case Key.VolumeMute when mediaPlayer.Volume == 0:
|
||||
await ControlPlayback(PlaybackControlEnum.TurnOnVolume, cancellationToken);
|
||||
await ControlPlayback(PlaybackControlEnum.TurnOnVolume, ct);
|
||||
break;
|
||||
case Key.VolumeMute:
|
||||
await ControlPlayback(PlaybackControlEnum.TurnOffVolume, cancellationToken);
|
||||
await ControlPlayback(PlaybackControlEnum.TurnOffVolume, ct);
|
||||
break;
|
||||
case Key.Up:
|
||||
case Key.VolumeUp:
|
||||
@@ -112,9 +116,9 @@ public class AnnotatorEventHandler(
|
||||
#endregion
|
||||
}
|
||||
|
||||
public async Task Handle(AnnotatorControlEvent notification, CancellationToken cancellationToken = default)
|
||||
public async Task Handle(AnnotatorControlEvent notification, CancellationToken ct = default)
|
||||
{
|
||||
await ControlPlayback(notification.PlaybackControl, cancellationToken);
|
||||
await ControlPlayback(notification.PlaybackControl, ct);
|
||||
mainWindow.VideoView.Focus();
|
||||
}
|
||||
|
||||
@@ -201,7 +205,7 @@ public class AnnotatorEventHandler(
|
||||
await Play(ct);
|
||||
}
|
||||
|
||||
public async Task Handle(VolumeChangedEvent notification, CancellationToken cancellationToken)
|
||||
public async Task Handle(VolumeChangedEvent notification, CancellationToken ct)
|
||||
{
|
||||
ChangeVolume(notification.Volume);
|
||||
await Task.CompletedTask;
|
||||
@@ -277,7 +281,7 @@ public class AnnotatorEventHandler(
|
||||
mainWindow.AddAnnotation(annotation);
|
||||
}
|
||||
|
||||
public Task Handle(AnnotationsDeletedEvent notification, CancellationToken cancellationToken)
|
||||
public async Task Handle(AnnotationsDeletedEvent notification, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -306,16 +310,37 @@ public class AnnotatorEventHandler(
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await dbFactory.DeleteAnnotations(notification.AnnotationNames, ct);
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var name in notification.AnnotationNames)
|
||||
{
|
||||
File.Delete(Path.Combine(dirConfig.Value.ImagesDirectory, $"{name}{Constants.JPG_EXT}"));
|
||||
File.Delete(Path.Combine(dirConfig.Value.LabelsDirectory, $"{name}{Constants.TXT_EXT}"));
|
||||
File.Delete(Path.Combine(dirConfig.Value.ThumbnailsDirectory, $"{name}{Constants.THUMBNAIL_PREFIX}{Constants.JPG_EXT}"));
|
||||
File.Delete(Path.Combine(dirConfig.Value.ResultsDirectory, $"{name}{Constants.RESULT_PREFIX}{Constants.JPG_EXT}"));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, e.Message);
|
||||
throw;
|
||||
}
|
||||
|
||||
//Only validators can send Delete to the queue
|
||||
if (!notification.FromQueue && api.CurrentUser.Role.IsValidator())
|
||||
await producer.SendToInnerQueue(notification.AnnotationNames, AnnotationStatus.Deleted, ct);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, e.Message);
|
||||
throw;
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(AnnotationAddedEvent e, CancellationToken cancellationToken)
|
||||
public Task Handle(AnnotationAddedEvent e, CancellationToken ct)
|
||||
{
|
||||
mainWindow.Dispatcher.Invoke(() =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user