mirror of
https://github.com/azaion/annotations.git
synced 2026-04-23 06:46:31 +00:00
fixed bugs with queue handling. At least most of them
This commit is contained in:
@@ -417,7 +417,8 @@ public partial class Annotator
|
|||||||
mediaFile.HasAnnotations = labelsDict.ContainsKey(mediaFile.FName);
|
mediaFile.HasAnnotations = labelsDict.ContainsKey(mediaFile.FName);
|
||||||
|
|
||||||
AllMediaFiles = new ObservableCollection<MediaFileInfo>(allFiles);
|
AllMediaFiles = new ObservableCollection<MediaFileInfo>(allFiles);
|
||||||
MediaFilesDict = AllMediaFiles.ToDictionary(x => x.FName);
|
MediaFilesDict = AllMediaFiles.GroupBy(x => x.Name)
|
||||||
|
.ToDictionary(gr => gr.Key, gr => gr.First());
|
||||||
LvFiles.ItemsSource = AllMediaFiles;
|
LvFiles.ItemsSource = AllMediaFiles;
|
||||||
DataContext = this;
|
DataContext = this;
|
||||||
}
|
}
|
||||||
@@ -463,7 +464,7 @@ public partial class Annotator
|
|||||||
{
|
{
|
||||||
Title = "Open Video folder",
|
Title = "Open Video folder",
|
||||||
IsFolderPicker = true,
|
IsFolderPicker = true,
|
||||||
InitialDirectory = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)
|
InitialDirectory = Path.GetDirectoryName(_appConfig.DirectoriesConfig.VideosDirectory)
|
||||||
};
|
};
|
||||||
var dialogResult = dlg.ShowDialog();
|
var dialogResult = dlg.ShowDialog();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Threading;
|
||||||
using Azaion.Annotator.DTO;
|
using Azaion.Annotator.DTO;
|
||||||
using Azaion.Common;
|
using Azaion.Common;
|
||||||
using Azaion.Common.DTO;
|
using Azaion.Common.DTO;
|
||||||
@@ -276,7 +277,11 @@ public class AnnotatorEventHandler(
|
|||||||
mainWindow.AddAnnotation(annotation);
|
mainWindow.AddAnnotation(annotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Handle(AnnotationsDeletedEvent notification, CancellationToken cancellationToken)
|
public Task Handle(AnnotationsDeletedEvent notification, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mainWindow.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
var namesSet = notification.AnnotationNames.ToHashSet();
|
var namesSet = notification.AnnotationNames.ToHashSet();
|
||||||
|
|
||||||
@@ -300,7 +305,14 @@ public class AnnotatorEventHandler(
|
|||||||
mainWindow.LvFiles.Items.Refresh();
|
mainWindow.LvFiles.Items.Refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await Task.CompletedTask;
|
});
|
||||||
|
}
|
||||||
|
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 cancellationToken)
|
||||||
|
|||||||
@@ -97,12 +97,7 @@ public class Constants
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Queue
|
|
||||||
|
|
||||||
public const string MQ_ANNOTATIONS_QUEUE = "azaion-annotations";
|
public const string MQ_ANNOTATIONS_QUEUE = "azaion-annotations";
|
||||||
public const string MQ_ANNOTATIONS_CONFIRM_QUEUE = "azaion-annotations-confirm";
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Database
|
#region Database
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ public enum AnnotationStatus
|
|||||||
{
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
Created = 10,
|
Created = 10,
|
||||||
Validated = 20,
|
ValidatedEdited = 20,
|
||||||
ValidatedEdited = 25,
|
|
||||||
Deleted = 30
|
Validated = 30,
|
||||||
|
Deleted = 40
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ namespace Azaion.Common.Database;
|
|||||||
|
|
||||||
public class AnnotationQueueRecord
|
public class AnnotationQueueRecord
|
||||||
{
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
public DateTime DateTime { get; set; }
|
public DateTime DateTime { get; set; }
|
||||||
public AnnotationStatus Operation { get; set; }
|
public AnnotationStatus Operation { get; set; }
|
||||||
public List<string> AnnotationNames { get; set; } = null!;
|
public List<string> AnnotationNames { get; set; } = null!;
|
||||||
|
|||||||
@@ -9,5 +9,4 @@ public class AnnotationsDb(DataOptions dataOptions) : DataConnection(dataOptions
|
|||||||
public ITable<Annotation> Annotations => this.GetTable<Annotation>();
|
public ITable<Annotation> Annotations => this.GetTable<Annotation>();
|
||||||
public ITable<AnnotationQueueRecord> AnnotationsQueueRecords => this.GetTable<AnnotationQueueRecord>();
|
public ITable<AnnotationQueueRecord> AnnotationsQueueRecords => this.GetTable<AnnotationQueueRecord>();
|
||||||
public ITable<Detection> Detections => this.GetTable<Detection>();
|
public ITable<Detection> Detections => this.GetTable<Detection>();
|
||||||
public ITable<QueueOffset> QueueOffsets => this.GetTable<QueueOffset>();
|
|
||||||
}
|
}
|
||||||
@@ -53,32 +53,24 @@ public class DbFactory : IDbFactory
|
|||||||
.UseMappingSchema(AnnotationsDbSchemaHolder.MappingSchema);
|
.UseMappingSchema(AnnotationsDbSchemaHolder.MappingSchema);
|
||||||
|
|
||||||
if (!File.Exists(_annConfig.AnnotationsDbFile))
|
if (!File.Exists(_annConfig.AnnotationsDbFile))
|
||||||
CreateDb();
|
SQLiteConnection.CreateFile(_annConfig.AnnotationsDbFile);
|
||||||
|
RecreateTables();
|
||||||
|
|
||||||
_fileConnection.Open();
|
_fileConnection.Open();
|
||||||
_fileConnection.BackupDatabase(_memoryConnection, "main", "main", -1, null, -1);
|
_fileConnection.BackupDatabase(_memoryConnection, "main", "main", -1, null, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateDb()
|
private void RecreateTables()
|
||||||
{
|
{
|
||||||
SQLiteConnection.CreateFile(_annConfig.AnnotationsDbFile);
|
|
||||||
using var db = new AnnotationsDb(_fileDataOptions);
|
using var db = new AnnotationsDb(_fileDataOptions);
|
||||||
|
var schema = db.DataProvider.GetSchemaProvider().GetSchema(db);
|
||||||
|
var existingTables = schema.Tables.Select(x => x.TableName).ToHashSet();
|
||||||
|
if (!existingTables.Contains(Constants.ANNOTATIONS_TABLENAME))
|
||||||
db.CreateTable<Annotation>();
|
db.CreateTable<Annotation>();
|
||||||
db.CreateTable<AnnotationQueueRecord>();
|
if (!existingTables.Contains(Constants.DETECTIONS_TABLENAME))
|
||||||
db.CreateTable<Detection>();
|
db.CreateTable<Detection>();
|
||||||
db.CreateTable<QueueOffset>();
|
if (!existingTables.Contains(Constants.ANNOTATIONS_QUEUE_TABLENAME))
|
||||||
db.QueueOffsets.BulkCopy(new List<QueueOffset>
|
db.CreateTable<AnnotationQueueRecord>();
|
||||||
{
|
|
||||||
new()
|
|
||||||
{
|
|
||||||
Offset = 0,
|
|
||||||
QueueName = Constants.MQ_ANNOTATIONS_QUEUE
|
|
||||||
},
|
|
||||||
new()
|
|
||||||
{
|
|
||||||
Offset = 0,
|
|
||||||
QueueName = Constants.MQ_ANNOTATIONS_CONFIRM_QUEUE
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<T> Run<T>(Func<AnnotationsDb, Task<T>> func)
|
public async Task<T> Run<T>(Func<AnnotationsDb, Task<T>> func)
|
||||||
@@ -138,6 +130,7 @@ public static class AnnotationsDbSchemaHolder
|
|||||||
|
|
||||||
builder.Entity<AnnotationQueueRecord>()
|
builder.Entity<AnnotationQueueRecord>()
|
||||||
.HasTableName(Constants.ANNOTATIONS_QUEUE_TABLENAME)
|
.HasTableName(Constants.ANNOTATIONS_QUEUE_TABLENAME)
|
||||||
|
.HasPrimaryKey(x => x.Id)
|
||||||
.Property(x => x.AnnotationNames)
|
.Property(x => x.AnnotationNames)
|
||||||
.HasDataType(DataType.NVarChar)
|
.HasDataType(DataType.NVarChar)
|
||||||
.HasConversion(list => JsonConvert.SerializeObject(list), str => JsonConvert.DeserializeObject<List<string>>(str) ?? new List<string>());
|
.HasConversion(list => JsonConvert.SerializeObject(list), str => JsonConvert.DeserializeObject<List<string>>(str) ?? new List<string>());
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace Azaion.Common.Database;
|
|
||||||
|
|
||||||
public class QueueOffset
|
|
||||||
{
|
|
||||||
public string QueueName { get; set; } = null!;
|
|
||||||
public ulong Offset { get; set; }
|
|
||||||
}
|
|
||||||
@@ -77,15 +77,17 @@ public class AnnotationService : IAnnotationService, INotificationHandler<Annota
|
|||||||
_consumer = await Consumer.Create(new ConsumerConfig(consumerSystem, Constants.MQ_ANNOTATIONS_QUEUE)
|
_consumer = await Consumer.Create(new ConsumerConfig(consumerSystem, Constants.MQ_ANNOTATIONS_QUEUE)
|
||||||
{
|
{
|
||||||
Reference = _api.CurrentUser.Email,
|
Reference = _api.CurrentUser.Email,
|
||||||
OffsetSpec = new OffsetTypeOffset(offsets.AnnotationsOffset + 1),
|
OffsetSpec = new OffsetTypeOffset(offsets.AnnotationsOffset),
|
||||||
MessageHandler = async (_, _, context, message) =>
|
MessageHandler = async (_, _, context, message) =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var email = (string)message.ApplicationProperties[nameof(User.Email)]!;
|
var email = (string)message.ApplicationProperties[nameof(User.Email)]!;
|
||||||
if (email == _api.CurrentUser.Email) //Don't process messages by yourself
|
if (!Enum.TryParse<AnnotationStatus>((string)message.ApplicationProperties[nameof(AnnotationStatus)], out var annotationStatus))
|
||||||
return;
|
return;
|
||||||
var annotationStatus = (AnnotationStatus)message.ApplicationProperties[nameof(AnnotationStatus)];
|
|
||||||
|
if (email != _api.CurrentUser.Email) //Don't process messages by yourself
|
||||||
|
{
|
||||||
if (annotationStatus.In(AnnotationStatus.Created, AnnotationStatus.ValidatedEdited))
|
if (annotationStatus.In(AnnotationStatus.Created, AnnotationStatus.ValidatedEdited))
|
||||||
{
|
{
|
||||||
var msg = MessagePackSerializer.Deserialize<AnnotationMessage>(message.Data.Contents);
|
var msg = MessagePackSerializer.Deserialize<AnnotationMessage>(message.Data.Contents);
|
||||||
@@ -109,8 +111,9 @@ public class AnnotationService : IAnnotationService, INotificationHandler<Annota
|
|||||||
if (annotationStatus == AnnotationStatus.Deleted)
|
if (annotationStatus == AnnotationStatus.Deleted)
|
||||||
await _mediator.Publish(new AnnotationsDeletedEvent(msg.AnnotationNames.ToList(), fromQueue:true), cancellationToken);
|
await _mediator.Publish(new AnnotationsDeletedEvent(msg.AnnotationNames.ToList(), fromQueue:true), cancellationToken);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
offsets.AnnotationsOffset = context.Offset;
|
offsets.AnnotationsOffset = context.Offset + 1; //to consume on the next launch from the next message
|
||||||
ThrottleExt.Throttle(() =>
|
ThrottleExt.Throttle(() =>
|
||||||
{
|
{
|
||||||
_api.UpdateOffsets(offsets);
|
_api.UpdateOffsets(offsets);
|
||||||
@@ -154,12 +157,6 @@ public class AnnotationService : IAnnotationService, INotificationHandler<Annota
|
|||||||
.LoadWith(x => x.Detections)
|
.LoadWith(x => x.Detections)
|
||||||
.FirstOrDefaultAsync(x => x.Name == fName, token: token);
|
.FirstOrDefaultAsync(x => x.Name == fName, token: token);
|
||||||
|
|
||||||
if (userRole.IsValidator() && source == SourceEnum.Manual)
|
|
||||||
status = AnnotationStatus.Validated;
|
|
||||||
|
|
||||||
if (fromQueue && ann is { AnnotationStatus: AnnotationStatus.Validated })
|
|
||||||
return ann;
|
|
||||||
|
|
||||||
await db.Detections.DeleteAsync(x => x.AnnotationName == fName, token: token);
|
await db.Detections.DeleteAsync(x => x.AnnotationName == fName, token: token);
|
||||||
|
|
||||||
if (ann != null) //Annotation is already exists
|
if (ann != null) //Annotation is already exists
|
||||||
@@ -169,10 +166,9 @@ public class AnnotationService : IAnnotationService, INotificationHandler<Annota
|
|||||||
.Set(x => x.Source, source)
|
.Set(x => x.Source, source)
|
||||||
.Set(x => x.CreatedRole, userRole);
|
.Set(x => x.CreatedRole, userRole);
|
||||||
|
|
||||||
if (status == AnnotationStatus.Validated)
|
if (userRole.IsValidator() && source == SourceEnum.Manual)
|
||||||
{
|
{
|
||||||
if (status == AnnotationStatus.Validated)
|
status = AnnotationStatus.ValidatedEdited;
|
||||||
status = AnnotationStatus.ValidatedEdited; //For further processing mark Annotations *edited* by Validator, not just simply Validated by button.
|
|
||||||
|
|
||||||
annotationUpdatable = annotationUpdatable
|
annotationUpdatable = annotationUpdatable
|
||||||
.Set(x => x.ValidateDate, createdDate)
|
.Set(x => x.ValidateDate, createdDate)
|
||||||
@@ -212,9 +208,6 @@ public class AnnotationService : IAnnotationService, INotificationHandler<Annota
|
|||||||
return ann;
|
return ann;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (fromQueue && annotation is { AnnotationStatus: AnnotationStatus.Validated })
|
|
||||||
return annotation;
|
|
||||||
|
|
||||||
if (stream != null)
|
if (stream != null)
|
||||||
{
|
{
|
||||||
var img = System.Drawing.Image.FromStream(stream);
|
var img = System.Drawing.Image.FromStream(stream);
|
||||||
@@ -228,7 +221,7 @@ public class AnnotationService : IAnnotationService, INotificationHandler<Annota
|
|||||||
|
|
||||||
await _mediator.Publish(new AnnotationCreatedEvent(annotation), token);
|
await _mediator.Publish(new AnnotationCreatedEvent(annotation), token);
|
||||||
|
|
||||||
if (!fromQueue && !_uiConfig.SilentDetection) //Send to queue only if we're not getting from queue already
|
if (!fromQueue) //Send to queue only if we're not getting from queue already
|
||||||
await _producer.SendToInnerQueue([annotation.Name], status, token);
|
await _producer.SendToInnerQueue([annotation.Name], status, token);
|
||||||
|
|
||||||
ThrottleExt.Throttle(async () =>
|
ThrottleExt.Throttle(async () =>
|
||||||
@@ -275,7 +268,8 @@ public class AnnotationService : IAnnotationService, INotificationHandler<Annota
|
|||||||
File.Delete(Path.Combine(_dirConfig.ResultsDirectory, $"{name}{Constants.RESULT_PREFIX}{Constants.JPG_EXT}"));
|
File.Delete(Path.Combine(_dirConfig.ResultsDirectory, $"{name}{Constants.RESULT_PREFIX}{Constants.JPG_EXT}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!notification.FromQueue)
|
//Only validators can send Delete to the queue
|
||||||
|
if (!notification.FromQueue && _api.CurrentUser.Role.IsValidator())
|
||||||
await _producer.SendToInnerQueue(notification.AnnotationNames, AnnotationStatus.Deleted, ct);
|
await _producer.SendToInnerQueue(notification.AnnotationNames, AnnotationStatus.Deleted, ct);
|
||||||
|
|
||||||
ThrottleExt.Throttle(async () =>
|
ThrottleExt.Throttle(async () =>
|
||||||
|
|||||||
@@ -23,14 +23,22 @@ public class FailsafeAnnotationsProducer
|
|||||||
private readonly IDbFactory _dbFactory;
|
private readonly IDbFactory _dbFactory;
|
||||||
private readonly IAzaionApi _azaionApi;
|
private readonly IAzaionApi _azaionApi;
|
||||||
private readonly QueueConfig _queueConfig;
|
private readonly QueueConfig _queueConfig;
|
||||||
|
private readonly UIConfig _uiConfig;
|
||||||
|
|
||||||
private Producer _annotationProducer = null!;
|
private Producer _annotationProducer = null!;
|
||||||
|
|
||||||
public FailsafeAnnotationsProducer(ILogger<FailsafeAnnotationsProducer> logger, IDbFactory dbFactory, IOptions<QueueConfig> queueConfig, IAzaionApi azaionApi)
|
|
||||||
|
public FailsafeAnnotationsProducer(ILogger<FailsafeAnnotationsProducer> logger,
|
||||||
|
IDbFactory dbFactory,
|
||||||
|
IOptions<QueueConfig> queueConfig,
|
||||||
|
IOptions<UIConfig> uiConfig,
|
||||||
|
IAzaionApi azaionApi)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_dbFactory = dbFactory;
|
_dbFactory = dbFactory;
|
||||||
_azaionApi = azaionApi;
|
_azaionApi = azaionApi;
|
||||||
_queueConfig = queueConfig.Value;
|
_queueConfig = queueConfig.Value;
|
||||||
|
_uiConfig = uiConfig.Value;
|
||||||
Task.Run(async () => await ProcessQueue());
|
Task.Run(async () => await ProcessQueue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +79,7 @@ public class FailsafeAnnotationsProducer
|
|||||||
{
|
{
|
||||||
var appProperties = new ApplicationProperties
|
var appProperties = new ApplicationProperties
|
||||||
{
|
{
|
||||||
{ nameof(AnnotationStatus), record.Operation },
|
{ nameof(AnnotationStatus), record.Operation.ToString() },
|
||||||
{ nameof(User.Email), _azaionApi.CurrentUser.Email }
|
{ nameof(User.Email), _azaionApi.CurrentUser.Email }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -86,7 +94,7 @@ public class FailsafeAnnotationsProducer
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var annotation = annotationsDict.GetValueOrDefault(record.AnnotationNames.FirstOrDefault());
|
var annotation = annotationsDict!.GetValueOrDefault(record.AnnotationNames.FirstOrDefault());
|
||||||
if (annotation == null)
|
if (annotation == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -118,7 +126,8 @@ public class FailsafeAnnotationsProducer
|
|||||||
if (result.messages.Any())
|
if (result.messages.Any())
|
||||||
{
|
{
|
||||||
await _annotationProducer.Send(result.messages, CompressionType.Gzip);
|
await _annotationProducer.Send(result.messages, CompressionType.Gzip);
|
||||||
await _dbFactory.Run(async db => await db.DeleteAsync(result.records, token: ct));
|
var ids = result.records.Select(x => x.Id).ToList();
|
||||||
|
var removed = await _dbFactory.Run(async db => await db.AnnotationsQueueRecords.DeleteAsync(x => ids.Contains(x.Id), token: ct));
|
||||||
sent = true;
|
sent = true;
|
||||||
_dbFactory.SaveToDisk();
|
_dbFactory.SaveToDisk();
|
||||||
}
|
}
|
||||||
@@ -136,9 +145,12 @@ public class FailsafeAnnotationsProducer
|
|||||||
|
|
||||||
public async Task SendToInnerQueue(List<string> annotationNames, AnnotationStatus status, CancellationToken cancellationToken = default)
|
public async Task SendToInnerQueue(List<string> annotationNames, AnnotationStatus status, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
if (_uiConfig.SilentDetection)
|
||||||
|
return;
|
||||||
await _dbFactory.Run(async db =>
|
await _dbFactory.Run(async db =>
|
||||||
await db.InsertAsync(new AnnotationQueueRecord
|
await db.InsertAsync(new AnnotationQueueRecord
|
||||||
{
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
DateTime = DateTime.UtcNow,
|
DateTime = DateTime.UtcNow,
|
||||||
Operation = status,
|
Operation = status,
|
||||||
AnnotationNames = annotationNames
|
AnnotationNames = annotationNames
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class GpsMatcherService(IGpsMatcherClient gpsMatcherClient, ISatelliteDow
|
|||||||
var indexOffset = 0;
|
var indexOffset = 0;
|
||||||
while (routeFiles.Any())
|
while (routeFiles.Any())
|
||||||
{
|
{
|
||||||
//await satelliteTileDownloader.GetTiles(currentLat, currentLon, SATELLITE_RADIUS_M, ZOOM_LEVEL, detectToken);
|
await satelliteTileDownloader.GetTiles(currentLat, currentLon, SATELLITE_RADIUS_M, ZOOM_LEVEL, detectToken);
|
||||||
gpsMatcherClient.StartMatching(new StartMatchingEvent
|
gpsMatcherClient.StartMatching(new StartMatchingEvent
|
||||||
{
|
{
|
||||||
ImagesCount = POINTS_COUNT,
|
ImagesCount = POINTS_COUNT,
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ public class InferenceClient : IInferenceClient, IResourceLoader
|
|||||||
_waitFileCancelSource.Cancel();
|
_waitFileCancelSource.Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = command.Data;
|
bytes = command.Data!;
|
||||||
_waitFileCancelSource.Cancel();
|
_waitFileCancelSource.Cancel();
|
||||||
}
|
}
|
||||||
_waitFileCancelSource.Token.WaitForCancel(timeout ?? TimeSpan.FromSeconds(15));
|
_waitFileCancelSource.Token.WaitForCancel(timeout ?? TimeSpan.FromSeconds(15));
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
using System.IO;
|
using System.Windows.Input;
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Threading;
|
|
||||||
using Azaion.Common.Database;
|
using Azaion.Common.Database;
|
||||||
using Azaion.Common.DTO;
|
using Azaion.Common.DTO;
|
||||||
using Azaion.Common.DTO.Queue;
|
|
||||||
using Azaion.Common.Events;
|
using Azaion.Common.Events;
|
||||||
using Azaion.Common.Services;
|
using Azaion.Common.Services;
|
||||||
using Azaion.CommonSecurity.DTO;
|
using Azaion.CommonSecurity.DTO;
|
||||||
using Azaion.CommonSecurity.Services;
|
using Azaion.CommonSecurity.Services;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Azaion.Dataset;
|
namespace Azaion.Dataset;
|
||||||
|
|
||||||
public class DatasetExplorerEventHandler(
|
public class DatasetExplorerEventHandler(
|
||||||
|
ILogger<DatasetExplorerEventHandler> logger,
|
||||||
DatasetExplorer datasetExplorer,
|
DatasetExplorer datasetExplorer,
|
||||||
IAnnotationService annotationService,
|
IAnnotationService annotationService,
|
||||||
IAzaionApi azaionApi) :
|
IAzaionApi azaionApi) :
|
||||||
@@ -22,8 +20,6 @@ public class DatasetExplorerEventHandler(
|
|||||||
INotificationHandler<AnnotationCreatedEvent>,
|
INotificationHandler<AnnotationCreatedEvent>,
|
||||||
INotificationHandler<AnnotationsDeletedEvent>
|
INotificationHandler<AnnotationsDeletedEvent>
|
||||||
{
|
{
|
||||||
private readonly IAzaionApi _azaionApi = azaionApi;
|
|
||||||
|
|
||||||
private readonly Dictionary<Key, PlaybackControlEnum> _keysControlEnumDict = new()
|
private readonly Dictionary<Key, PlaybackControlEnum> _keysControlEnumDict = new()
|
||||||
{
|
{
|
||||||
{ Key.Enter, PlaybackControlEnum.SaveAnnotations },
|
{ Key.Enter, PlaybackControlEnum.SaveAnnotations },
|
||||||
@@ -127,7 +123,7 @@ public class DatasetExplorerEventHandler(
|
|||||||
if (annotation.Classes.Contains(selectedClass) || selectedClass == -1)
|
if (annotation.Classes.Contains(selectedClass) || selectedClass == -1)
|
||||||
{
|
{
|
||||||
var index = 0;
|
var index = 0;
|
||||||
var annThumb = new AnnotationThumbnail(annotation, _azaionApi.CurrentUser.Role.IsValidator());
|
var annThumb = new AnnotationThumbnail(annotation, azaionApi.CurrentUser.Role.IsValidator());
|
||||||
if (datasetExplorer.SelectedAnnotationDict.ContainsKey(annThumb.Annotation.Name))
|
if (datasetExplorer.SelectedAnnotationDict.ContainsKey(annThumb.Annotation.Name))
|
||||||
{
|
{
|
||||||
datasetExplorer.SelectedAnnotationDict.Remove(annThumb.Annotation.Name);
|
datasetExplorer.SelectedAnnotationDict.Remove(annThumb.Annotation.Name);
|
||||||
@@ -147,6 +143,10 @@ public class DatasetExplorerEventHandler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task Handle(AnnotationsDeletedEvent notification, CancellationToken cancellationToken)
|
public async Task Handle(AnnotationsDeletedEvent notification, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
datasetExplorer.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
var annThumbs = datasetExplorer.SelectedAnnotationDict
|
var annThumbs = datasetExplorer.SelectedAnnotationDict
|
||||||
.Where(x => notification.AnnotationNames.Contains(x.Key))
|
.Where(x => notification.AnnotationNames.Contains(x.Key))
|
||||||
@@ -157,6 +157,13 @@ public class DatasetExplorerEventHandler(
|
|||||||
datasetExplorer.SelectedAnnotations.Remove(annThumb);
|
datasetExplorer.SelectedAnnotations.Remove(annThumb);
|
||||||
datasetExplorer.SelectedAnnotationDict.Remove(annThumb.Annotation.Name);
|
datasetExplorer.SelectedAnnotationDict.Remove(annThumb.Annotation.Name);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.LogError(e, e.Message);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
await Task.CompletedTask;
|
await Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,6 +145,9 @@ public partial class App
|
|||||||
StartMain();
|
StartMain();
|
||||||
_host.Start();
|
_host.Start();
|
||||||
EventManager.RegisterClassHandler(typeof(UIElement), UIElement.PreviewKeyDownEvent, new RoutedEventHandler(GlobalKeyHandler));
|
EventManager.RegisterClassHandler(typeof(UIElement), UIElement.PreviewKeyDownEvent, new RoutedEventHandler(GlobalKeyHandler));
|
||||||
|
var datasetExplorer = _host.Services.GetRequiredService<DatasetExplorer>();
|
||||||
|
datasetExplorer.Show();
|
||||||
|
datasetExplorer.Hide();
|
||||||
_host.Services.GetRequiredService<MainSuite>().Show();
|
_host.Services.GetRequiredService<MainSuite>().Show();
|
||||||
};
|
};
|
||||||
login.Closed += (sender, args) =>
|
login.Closed += (sender, args) =>
|
||||||
|
|||||||
@@ -27,6 +27,6 @@
|
|||||||
"LeftPanelWidth": 220.0,
|
"LeftPanelWidth": 220.0,
|
||||||
"RightPanelWidth": 230.0,
|
"RightPanelWidth": 230.0,
|
||||||
"GenerateAnnotatedImage": true,
|
"GenerateAnnotatedImage": true,
|
||||||
"SilentDetection": true
|
"SilentDetection": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user