mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 20:26:31 +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:
@@ -61,7 +61,7 @@ public class GalleryService(
|
||||
{
|
||||
foreach(var file in new DirectoryInfo(_dirConfig.ThumbnailsDirectory).GetFiles())
|
||||
file.Delete();
|
||||
await dbFactory.Run(async db =>
|
||||
await dbFactory.RunWrite(async db =>
|
||||
{
|
||||
await db.Detections.DeleteAsync(x => true, token: cancellationToken);
|
||||
await db.Annotations.DeleteAsync(x => true, token: cancellationToken);
|
||||
@@ -157,7 +157,7 @@ public class GalleryService(
|
||||
|
||||
|
||||
if (!thumbnails.Contains(fName))
|
||||
await CreateThumbnail(annotation, cancellationToken);
|
||||
await CreateThumbnail(annotation, cancellationToken: cancellationToken);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -198,24 +198,23 @@ public class GalleryService(
|
||||
.Select(x => x.Value)
|
||||
.ToList();
|
||||
|
||||
await dbFactory.Run(async db =>
|
||||
await dbFactory.RunWrite(async db =>
|
||||
{
|
||||
await db.BulkCopyAsync(copyOptions, annotationsToInsert);
|
||||
await db.BulkCopyAsync(copyOptions, annotationsToInsert.SelectMany(x => x.Detections));
|
||||
});
|
||||
dbFactory.SaveToDisk();
|
||||
_updateLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CreateThumbnail(Annotation annotation, CancellationToken cancellationToken = default)
|
||||
public async Task CreateThumbnail(Annotation annotation, Image? originalImage = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var width = (int)_thumbnailConfig.Size.Width;
|
||||
var height = (int)_thumbnailConfig.Size.Height;
|
||||
|
||||
var originalImage = Image.FromStream(new MemoryStream(await File.ReadAllBytesAsync(annotation.ImagePath, cancellationToken)));
|
||||
originalImage ??= Image.FromStream(new MemoryStream(await File.ReadAllBytesAsync(annotation.ImagePath, cancellationToken)));
|
||||
|
||||
var bitmap = new Bitmap(width, height);
|
||||
|
||||
@@ -282,10 +281,9 @@ public class GalleryService(
|
||||
logger.LogError(e, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CreateAnnotatedImage(Annotation annotation, CancellationToken token)
|
||||
public async Task CreateAnnotatedImage(Annotation annotation, Image? originalImage = null, CancellationToken token = default)
|
||||
{
|
||||
var originalImage = Image.FromStream(new MemoryStream(await File.ReadAllBytesAsync(annotation.ImagePath, token)));
|
||||
originalImage ??= Image.FromStream(new MemoryStream(await File.ReadAllBytesAsync(annotation.ImagePath, token)));
|
||||
|
||||
using var g = Graphics.FromImage(originalImage);
|
||||
foreach (var detection in annotation.Detections)
|
||||
@@ -299,17 +297,20 @@ public class GalleryService(
|
||||
var label = detection.Confidence >= 0.995 ? detClass.UIName : $"{detClass.UIName}: {detection.Confidence * 100:F0}%";
|
||||
g.DrawTextBox(label, new PointF((float)(det.X + det.Width / 2.0), (float)(det.Y - 24)), brush, Brushes.Black);
|
||||
}
|
||||
originalImage.Save(Path.Combine(_dirConfig.ResultsDirectory, $"{annotation.Name}{Constants.RESULT_PREFIX}.jpg"), ImageFormat.Jpeg);
|
||||
|
||||
var imagePath = Path.Combine(_dirConfig.ResultsDirectory, $"{annotation.Name}{Constants.RESULT_PREFIX}.jpg");
|
||||
if (File.Exists(imagePath))
|
||||
ResilienceExt.WithRetry(() => File.Delete(imagePath));
|
||||
|
||||
originalImage.Save(imagePath, ImageFormat.Jpeg);
|
||||
}
|
||||
}
|
||||
|
||||
public interface IGalleryService
|
||||
{
|
||||
event ThumbnailsUpdatedEventHandler? ThumbnailsUpdate;
|
||||
double ProcessedThumbnailsPercentage { get; set; }
|
||||
Task CreateThumbnail(Annotation annotation, CancellationToken cancellationToken = default);
|
||||
Task CreateThumbnail(Annotation annotation, Image? originalImage = null, CancellationToken cancellationToken = default);
|
||||
Task RefreshThumbnails();
|
||||
Task ClearThumbnails(CancellationToken cancellationToken = default);
|
||||
|
||||
Task CreateAnnotatedImage(Annotation annotation, CancellationToken token);
|
||||
Task CreateAnnotatedImage(Annotation annotation, Image? originalImage = null, CancellationToken token = default);
|
||||
}
|
||||
Reference in New Issue
Block a user