diff --git a/Azaion.Common/Database/DbFactory.cs b/Azaion.Common/Database/DbFactory.cs index ba59c0e..fdce46d 100644 --- a/Azaion.Common/Database/DbFactory.cs +++ b/Azaion.Common/Database/DbFactory.cs @@ -18,6 +18,7 @@ public interface IDbFactory Task Run(Func func); void SaveToDisk(); Task DeleteAnnotations(List annotations, CancellationToken cancellationToken = default); + Task DeleteAnnotations(List annotationNames, CancellationToken cancellationToken = default); } public class DbFactory : IDbFactory @@ -100,10 +101,16 @@ public class DbFactory : IDbFactory public async Task DeleteAnnotations(List annotations, CancellationToken cancellationToken = default) { var names = annotations.Select(x => x.Name).ToList(); + await DeleteAnnotations(names, cancellationToken); + } + + public async Task DeleteAnnotations(List annotationNames, CancellationToken cancellationToken = default) + { await Run(async db => { - await db.Detections.DeleteAsync(x => names.Contains(x.AnnotationName), token: cancellationToken); - await db.Annotations.DeleteAsync(x => names.Contains(x.Name), token: cancellationToken); + var detDeleted = await db.Detections.DeleteAsync(x => annotationNames.Contains(x.AnnotationName), token: cancellationToken); + var annDeleted = await db.Annotations.DeleteAsync(x => annotationNames.Contains(x.Name), token: cancellationToken); + Console.WriteLine($"Deleted {detDeleted} detections, {annDeleted} annotations"); }); SaveToDisk(); } diff --git a/Azaion.Common/Services/AnnotationService.cs b/Azaion.Common/Services/AnnotationService.cs index c7e9cd8..4fc8dfb 100644 --- a/Azaion.Common/Services/AnnotationService.cs +++ b/Azaion.Common/Services/AnnotationService.cs @@ -71,6 +71,17 @@ public class AnnotationService : INotificationHandler MessageHandler = async (stream, consumer, context, message) => { var msg = MessagePackSerializer.Deserialize(message.Data.Contents); + await _dbFactory.Run(async db => await db.QueueOffsets + .Where(x => x.QueueName == Constants.MQ_ANNOTATIONS_QUEUE) + .Set(x => x.Offset, context.Offset) + .UpdateAsync(token: cancellationToken)); + + await ThrottleExt.ThrottleRunAfter(() => + { + _dbFactory.SaveToDisk(); + return Task.CompletedTask; + }, SaveTaskId, TimeSpan.FromSeconds(5), cancellationToken); + if (msg.CreatedRole != RoleEnum.Operator) //Process only operator's messages return; @@ -86,18 +97,6 @@ public class AnnotationService : INotificationHandler msg.CreatedEmail, generateThumbnail: true, cancellationToken); - - await _dbFactory.Run(async db => await db.QueueOffsets - .Where(x => x.QueueName == Constants.MQ_ANNOTATIONS_QUEUE) - .Set(x => x.Offset, context.Offset) - .UpdateAsync(token: cancellationToken)); - - await ThrottleExt.ThrottleRunAfter(() => - { - _dbFactory.SaveToDisk(); - return Task.CompletedTask; - }, SaveTaskId, TimeSpan.FromSeconds(3), cancellationToken); - } }); } diff --git a/Azaion.Common/Services/GalleryService.cs b/Azaion.Common/Services/GalleryService.cs index 4383fb6..896a13f 100644 --- a/Azaion.Common/Services/GalleryService.cs +++ b/Azaion.Common/Services/GalleryService.cs @@ -97,6 +97,7 @@ public class GalleryService( { File.Delete(file.FullName); logger.LogInformation($"No labels found for image {file.FullName}! Image deleted!"); + await dbFactory.DeleteAnnotations([fName], cancellationToken); return; } diff --git a/Azaion.CommonSecurity/Services/PythonResourceLoader.cs b/Azaion.CommonSecurity/Services/PythonResourceLoader.cs index be07bcd..b76faa3 100644 --- a/Azaion.CommonSecurity/Services/PythonResourceLoader.cs +++ b/Azaion.CommonSecurity/Services/PythonResourceLoader.cs @@ -71,8 +71,11 @@ public class PythonResourceLoader : IResourceLoader, IAuthProvider public void StopPython() { - _dealer.SendFrame(MessagePackSerializer.Serialize(new RemoteCommand(CommandType.Exit))); - _dealer.Close(); + if (!_dealer.IsDisposed) + { + _dealer.SendFrame(MessagePackSerializer.Serialize(new RemoteCommand(CommandType.Exit))); + _dealer.Close(); + } } public MemoryStream LoadFileFromPython(string fileName, string? folder = null) diff --git a/Azaion.Dataset/DatasetExplorerEventHandler.cs b/Azaion.Dataset/DatasetExplorerEventHandler.cs index 62c1540..f06540a 100644 --- a/Azaion.Dataset/DatasetExplorerEventHandler.cs +++ b/Azaion.Dataset/DatasetExplorerEventHandler.cs @@ -95,11 +95,16 @@ public class DatasetExplorerEventHandler( if (annotation.Classes.Contains(selectedClass) || selectedClass == -1) { var annThumb = new AnnotationThumbnail(annotation); - if (!datasetExplorer.SelectedAnnotationDict.ContainsKey(annThumb.Annotation.Name)) + if (datasetExplorer.SelectedAnnotationDict.ContainsKey(annThumb.Annotation.Name)) { - datasetExplorer.SelectedAnnotations.Insert(0, annThumb); - datasetExplorer.SelectedAnnotationDict.Add(annThumb.Annotation.Name, annThumb); + datasetExplorer.SelectedAnnotationDict.Remove(annThumb.Annotation.Name); + var ann = datasetExplorer.SelectedAnnotations.FirstOrDefault(x => x.Annotation.Name == annThumb.Annotation.Name); + if (ann != null) + datasetExplorer.SelectedAnnotations.Remove(ann); } + + datasetExplorer.SelectedAnnotations.Insert(0, annThumb); + datasetExplorer.SelectedAnnotationDict.Add(annThumb.Annotation.Name, annThumb); } await Task.CompletedTask; } diff --git a/build/publish.cmd b/build/publish.cmd index 96dc41d..ee5c627 100644 --- a/build/publish.cmd +++ b/build/publish.cmd @@ -45,13 +45,20 @@ pyinstaller --onefile ^ start.py move dist\start.exe ..\dist\azaion-inference.exe copy config.yaml ..\dist +cd.. echo Download onnx model +cd build call cdn_manager.exe download models azaion.onnx.big move azaion.onnx.big ..\dist\ -cd .. +cd.. echo Copy ico copy logo.ico dist\ + +echo building installer... iscc build\installer.iss -call cdn_manager.exe upload suite AzaionSuiteInstaller.exe \ No newline at end of file +cd build\ + +echo uploading installer... +call .\cdn_manager.exe upload suite AzaionSuiteInstaller.exe ..\AzaionSuiteInstaller.exe \ No newline at end of file