diff --git a/Azaion.Common/DTO/AnnotationImageView.cs b/Azaion.Common/DTO/AnnotationImageView.cs index 181acf9..2e74cee 100644 --- a/Azaion.Common/DTO/AnnotationImageView.cs +++ b/Azaion.Common/DTO/AnnotationImageView.cs @@ -19,8 +19,13 @@ public class AnnotationImageView(Annotation annotation) : INotifyPropertyChanged Task.Run(async () => Thumbnail = await Annotation.ThumbPath.OpenImage()); return _thumbnail; } - private set => _thumbnail = value; + private set + { + _thumbnail = value; + OnPropertyChanged(); + } } + public string ImageName => Path.GetFileName(Annotation.ImagePath); public void Delete() diff --git a/Azaion.Common/Services/AnnotationService.cs b/Azaion.Common/Services/AnnotationService.cs index cd3e298..c6e3a9f 100644 --- a/Azaion.Common/Services/AnnotationService.cs +++ b/Azaion.Common/Services/AnnotationService.cs @@ -8,6 +8,7 @@ using Azaion.Common.DTO.Queue; using Azaion.CommonSecurity.DTO; using Azaion.CommonSecurity.Services; using LinqToDB; +using LinqToDB.Data; using MediatR; using MessagePack; using Microsoft.Extensions.Options; @@ -67,7 +68,7 @@ public class AnnotationService //Queue (only from operators) public async Task Consume(AnnotationCreatedMessage message, CancellationToken cancellationToken = default) { - if (message.CreatedRole == RoleEnum.Validator) //Don't proceed our own messages (or from another Validator) + if (message.CreatedRole != RoleEnum.Operator) //Process only operator's messages return; await SaveAnnotationInner( @@ -104,6 +105,8 @@ public class AnnotationService ? AnnotationStatus.Validated : AnnotationStatus.Created; + await db.Detections.DeleteAsync(x => x.AnnotationName == fName, token: token); + await db.BulkCopyAsync(detections, cancellationToken: token); if (ann != null) await db.Annotations .Where(x => x.Name == fName) diff --git a/Azaion.Common/Services/FailsafeProducer.cs b/Azaion.Common/Services/FailsafeProducer.cs index 54ddee8..1fa990b 100644 --- a/Azaion.Common/Services/FailsafeProducer.cs +++ b/Azaion.Common/Services/FailsafeProducer.cs @@ -65,13 +65,15 @@ public class FailsafeAnnotationsProducer .Where(x => x.Status == AnnotationStatus.Created) .Select(x => new Message(MessagePackSerializer.Serialize(x))) .ToList(); - await _annotationProducer.Send(createdMessages, CompressionType.Gzip); + if (createdMessages.Any()) + await _annotationProducer.Send(createdMessages, CompressionType.Gzip); var validatedMessages = messagesChunk .Where(x => x.Status == AnnotationStatus.Validated) .Select(x => new Message(MessagePackSerializer.Serialize(x))) .ToList(); - await _annotationConfirmProducer.Send(validatedMessages, CompressionType.Gzip); + if (validatedMessages.Any()) + await _annotationConfirmProducer.Send(validatedMessages, CompressionType.Gzip); await _dbFactory.Run(async db => await db.AnnotationsQueue.DeleteAsync(aq => messagesChunk.Any(x => aq.Name == x.Name), token: cancellationToken)); @@ -80,10 +82,12 @@ public class FailsafeAnnotationsProducer catch (Exception e) { _logger.LogError(e, e.Message); - await Task.Delay(TimeSpan.FromSeconds(30), cancellationToken); + await Task.Delay(TimeSpan.FromSeconds(10), cancellationToken); } + await Task.Delay(TimeSpan.FromSeconds(10), cancellationToken); } } + await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken); } } @@ -91,7 +95,8 @@ public class FailsafeAnnotationsProducer { return await _dbFactory.Run(async db => { - var annotations = await db.AnnotationsQueue.Join(db.Annotations, aq => aq.Name, a => a.Name, (aq, a) => a) + var annotations = await db.AnnotationsQueue.Join( + db.Annotations.LoadWith(x => x.Detections), aq => aq.Name, a => a.Name, (aq, a) => a) .ToListAsync(token: cancellationToken); var messages = new List(); @@ -105,10 +110,13 @@ public class FailsafeAnnotationsProducer CreatedRole = annotation.CreatedRole, CreatedEmail = annotation.CreatedEmail, CreatedDate = annotation.CreatedDate, + Status = annotation.AnnotationStatus, + ImageExtension = annotation.ImageExtension, Image = image, Detections = JsonConvert.SerializeObject(annotation.Detections), - Source = annotation.Source + Source = annotation.Source, + }; messages.Add(annCreateMessage); } diff --git a/Azaion.Suite/App.xaml.cs b/Azaion.Suite/App.xaml.cs index 35136dd..a31cb75 100644 --- a/Azaion.Suite/App.xaml.cs +++ b/Azaion.Suite/App.xaml.cs @@ -118,14 +118,7 @@ public partial class App services.AddSingleton(); services.AddSingleton(); - services.AddHttpClient((sp, client) => - { - var apiConfig = sp.GetRequiredService>().Value; - client.BaseAddress = new Uri(apiConfig.Url); - client.Timeout = TimeSpan.FromSeconds(apiConfig.TimeoutSeconds); - }); - - services.AddSingleton(); + services.AddSingleton(); services.AddSingleton();