mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 10:56:31 +00:00
big refactoring. get rid of static properties and coupled architecture. prepare system for integration tests
This commit is contained in:
@@ -36,7 +36,10 @@ public class AnnotatorEventHandler(
|
||||
IInferenceService inferenceService,
|
||||
IDbFactory dbFactory,
|
||||
IAzaionApi api,
|
||||
FailsafeAnnotationsProducer producer)
|
||||
FailsafeAnnotationsProducer producer,
|
||||
IAnnotationPathResolver pathResolver,
|
||||
IFileSystem fileSystem,
|
||||
IUICommandDispatcher uiDispatcher)
|
||||
:
|
||||
INotificationHandler<KeyEvent>,
|
||||
INotificationHandler<AnnClassSelectedEvent>,
|
||||
@@ -318,7 +321,7 @@ public class AnnotatorEventHandler(
|
||||
var annotationsResult = new List<Annotation>();
|
||||
var time = formState.BackgroundTime ?? TimeSpan.FromMilliseconds(mediaPlayer.Time);
|
||||
|
||||
if (!File.Exists(imgPath))
|
||||
if (!fileSystem.FileExists(imgPath))
|
||||
{
|
||||
if (mediaSize.FitSizeForAI())
|
||||
await source.SaveImage(imgPath, ct);
|
||||
@@ -339,7 +342,8 @@ public class AnnotatorEventHandler(
|
||||
{
|
||||
var annotationName = $"{formState.CurrentMedia?.Name ?? ""}{Constants.SPLIT_SUFFIX}{res.Tile.Width}_{res.Tile.Left:0000}_{res.Tile.Top:0000}!".ToTimeName(time);
|
||||
|
||||
var tileImgPath = Path.Combine(dirConfig.Value.ImagesDirectory, $"{annotationName}{Constants.JPG_EXT}");
|
||||
var tempAnnotation = new Annotation { Name = annotationName, ImageExtension = Constants.JPG_EXT };
|
||||
var tileImgPath = pathResolver.GetImagePath(tempAnnotation);
|
||||
var bitmap = new CroppedBitmap(source, new Int32Rect((int)res.Tile.Left, (int)res.Tile.Top, (int)res.Tile.Width, (int)res.Tile.Height));
|
||||
await bitmap.SaveImage(tileImgPath, ct);
|
||||
|
||||
@@ -367,7 +371,7 @@ public class AnnotatorEventHandler(
|
||||
{
|
||||
try
|
||||
{
|
||||
mainWindow.Dispatcher.Invoke(() =>
|
||||
uiDispatcher.Execute(() =>
|
||||
{
|
||||
var namesSet = notification.AnnotationNames.ToHashSet();
|
||||
|
||||
@@ -391,10 +395,11 @@ public class AnnotatorEventHandler(
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(Path.Combine(dirConfig.Value.ImagesDirectory, $"{name}{Constants.JPG_EXT}"));
|
||||
File.Delete(Path.Combine(dirConfig.Value.LabelsDirectory, $"{name}{Constants.TXT_EXT}"));
|
||||
File.Delete(Path.Combine(dirConfig.Value.ThumbnailsDirectory, $"{name}{Constants.THUMBNAIL_PREFIX}{Constants.JPG_EXT}"));
|
||||
File.Delete(Path.Combine(dirConfig.Value.ResultsDirectory, $"{name}{Constants.RESULT_PREFIX}{Constants.JPG_EXT}"));
|
||||
var tempAnnotation = new Annotation { Name = name, ImageExtension = Constants.JPG_EXT };
|
||||
fileSystem.DeleteFile(pathResolver.GetImagePath(tempAnnotation));
|
||||
fileSystem.DeleteFile(pathResolver.GetLabelPath(tempAnnotation));
|
||||
fileSystem.DeleteFile(pathResolver.GetThumbPath(tempAnnotation));
|
||||
fileSystem.DeleteFile(Path.Combine(dirConfig.Value.ResultsDirectory, $"{name}{Constants.RESULT_PREFIX}{Constants.JPG_EXT}"));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -416,7 +421,7 @@ public class AnnotatorEventHandler(
|
||||
|
||||
public Task Handle(AnnotationAddedEvent e, CancellationToken ct)
|
||||
{
|
||||
mainWindow.Dispatcher.Invoke(() =>
|
||||
uiDispatcher.Execute(() =>
|
||||
{
|
||||
var mediaInfo = (MediaFile)mainWindow.LvFiles.SelectedItem;
|
||||
if ((mediaInfo?.Name ?? "") == e.Annotation.OriginalMediaName)
|
||||
@@ -442,7 +447,7 @@ public class AnnotatorEventHandler(
|
||||
|
||||
public Task Handle(SetStatusTextEvent e, CancellationToken cancellationToken)
|
||||
{
|
||||
mainWindow.Dispatcher.Invoke(() =>
|
||||
uiDispatcher.Execute(() =>
|
||||
{
|
||||
mainWindow.StatusHelp.Text = e.Text;
|
||||
mainWindow.StatusHelp.Foreground = e.IsError ? Brushes.Red : Brushes.White;
|
||||
@@ -452,7 +457,7 @@ public class AnnotatorEventHandler(
|
||||
|
||||
public Task Handle(GPSMatcherResultProcessedEvent e, CancellationToken cancellationToken)
|
||||
{
|
||||
mainWindow.Dispatcher.Invoke(() =>
|
||||
uiDispatcher.Execute(() =>
|
||||
{
|
||||
var ann = mainWindow.MapMatcherComponent.Annotations[e.Index];
|
||||
AddMarker(e.GeoPoint, e.Image, Brushes.Blue);
|
||||
@@ -478,7 +483,7 @@ public class AnnotatorEventHandler(
|
||||
|
||||
public async Task Handle(AIAvailabilityStatusEvent e, CancellationToken cancellationToken)
|
||||
{
|
||||
mainWindow.Dispatcher.Invoke(() =>
|
||||
uiDispatcher.Execute(() =>
|
||||
{
|
||||
logger.LogInformation(e.ToString());
|
||||
mainWindow.AIDetectBtn.IsEnabled = e.Status == AIAvailabilityEnum.Enabled;
|
||||
|
||||
Reference in New Issue
Block a user