This commit is contained in:
Alex Bezdieniezhnykh
2024-11-21 16:38:45 +02:00
parent 5a592e9dbf
commit 490e90f239
2 changed files with 12 additions and 9 deletions
@@ -69,8 +69,10 @@ public class DatasetExplorerEventHandler(DatasetExplorer datasetExplorer, IGalle
}
}
public Task Handle(ImageCreatedEvent notification, CancellationToken cancellationToken)
public async Task Handle(ImageCreatedEvent imageCreatedEvent, CancellationToken cancellationToken)
{
throw new NotImplementedException();
var (thumbnailDto, detections) = await galleryManager.CreateThumbnail(imageCreatedEvent.ImagePath, cancellationToken);
if (thumbnailDto != null && detections != null)
datasetExplorer.AddThumbnail(thumbnailDto, detections);
}
}
+8 -7
View File
@@ -30,7 +30,7 @@ public class GalleryManager(
private readonly AnnotationConfig _annotationConfig = annotationConfig.Value;
private readonly string _thumbnailsCacheFile = Path.Combine(directoriesConfig.Value.ThumbnailsDirectory, Constants.THUMBNAILS_CACHE_FILE);
public event ThumbnailsUpdatedEventHandler ThumbnailsUpdate;
public event ThumbnailsUpdatedEventHandler? ThumbnailsUpdate;
private readonly SemaphoreSlim _updateLock = new(1);
@@ -125,7 +125,7 @@ public class GalleryManager(
await File.WriteAllTextAsync(_thumbnailsCacheFile, labelsCacheStr);
}
public async Task<ThumbnailDto?> CreateThumbnail(string imgPath, CancellationToken cancellationToken = default)
public async Task<(ThumbnailDto? thumbnailDto, List<int>? classes)> CreateThumbnail(string imgPath, CancellationToken cancellationToken = default)
{
try
{
@@ -149,7 +149,7 @@ public class GalleryManager(
{
File.Delete(imgPath);
logger.LogInformation($"No labels found for image {imgName}! Image deleted!");
return null;
return (null, null);
}
var labels = (await YoloLabel.ReadFromFile(labelName, cancellationToken))
@@ -209,18 +209,19 @@ public class GalleryManager(
var thumbnailName = Path.Combine(ThumbnailsDirectory.FullName, $"{Path.GetFileNameWithoutExtension(imgPath)}{Constants.THUMBNAIL_PREFIX}.jpg");
bitmap.Save(thumbnailName, ImageFormat.Jpeg);
return new ThumbnailDto
var thumbnailDto = new ThumbnailDto
{
ThumbnailPath = thumbnailName,
ImagePath = imgPath,
LabelPath = labelName,
ImageDate = File.GetCreationTimeUtc(imgPath)
};
return (thumbnailDto, classes);
}
catch (Exception e)
{
logger.LogError(e, e.Message);
return null;
return (null, null);
}
}
@@ -241,12 +242,12 @@ public class GalleryManager(
public interface IGalleryManager
{
event ThumbnailsUpdatedEventHandler ThumbnailsUpdate;
event ThumbnailsUpdatedEventHandler? ThumbnailsUpdate;
double ThumbnailsPercentage { get; set; }
Task SaveLabelsCache();
LabelInfo AddToCache(string imgPath, List<int> classes);
ConcurrentDictionary<string, LabelInfo> LabelsCache { get; set; }
Task<ThumbnailDto?> CreateThumbnail(string imgPath, CancellationToken cancellationToken = default);
Task<(ThumbnailDto? thumbnailDto, List<int>? classes)> CreateThumbnail(string imgPath, CancellationToken cancellationToken = default);
Task RefreshThumbnails();
void ClearThumbnails();
}