big refactoring. get rid of static properties and coupled architecture. prepare system for integration tests

This commit is contained in:
Oleksandr Bezdieniezhnykh
2025-11-17 13:14:05 +02:00
parent 22529c26ec
commit e7ea5a8ded
38 changed files with 808 additions and 157 deletions
+25 -7
View File
@@ -13,6 +13,7 @@ using Azaion.Common.Extensions;
using Azaion.Common.Services;
using Azaion.Common.Services.Inference;
using Azaion.Dataset;
using Azaion.Suite.Services;
using CommandLine;
using LibVLCSharp.Shared;
using MediatR;
@@ -98,8 +99,9 @@ public partial class App
new ConfigUpdater().CheckConfig();
var initConfig = Constants.ReadInitConfig(Log.Logger);
var apiDir = initConfig.DirectoriesConfig.ApiResourcesDirectory;
var processLauncher = new ProcessLauncher();
_loaderClient = new LoaderClient(initConfig.LoaderClientConfig, Log.Logger, _mainCTokenSource.Token);
_loaderClient = new LoaderClient(initConfig.LoaderClientConfig, Log.Logger, processLauncher, _mainCTokenSource.Token);
_loaderClient.StartClient();
_loaderClient.Connect();
_loaderClient.Login(credentials);
@@ -145,7 +147,16 @@ public partial class App
services.AddSingleton<IAzaionApi>(azaionApi);
#endregion
services.AddSingleton<IFileSystem, PhysicalFileSystem>();
services.AddSingleton<IConfigurationStore>(sp =>
new FileConfigurationStore(Constants.CONFIG_PATH, sp.GetRequiredService<IFileSystem>()));
services.AddSingleton<IConfigUpdater, ConfigUpdater>();
services.AddSingleton<IProcessLauncher, ProcessLauncher>();
services.AddSingleton<IUICommandDispatcher>(_ =>
new WpfUICommandDispatcher(Application.Current.Dispatcher));
services.AddSingleton<IAnnotationPathResolver>(sp =>
new AnnotationPathResolver(sp.GetRequiredService<IOptions<Azaion.Common.DTO.DirectoriesConfig>>().Value));
services.AddSingleton<IDetectionClassProvider, DetectionClassProvider>();
services.AddSingleton<Annotator.Annotator>();
services.AddSingleton<DatasetExplorer>();
services.AddSingleton<HelpWindow>();
@@ -155,16 +166,18 @@ public partial class App
typeof(AnnotationService).Assembly));
services.AddSingleton<LibVLC>(_ => new LibVLC("--no-osd", "--no-video-title-show", "--no-snapshot-preview"));
services.AddSingleton<FormState>();
services.AddSingleton<MediaPlayer>(sp =>
services.AddSingleton<LibVLCSharp.Shared.MediaPlayer>(sp =>
{
var libVlc = sp.GetRequiredService<LibVLC>();
return new MediaPlayer(libVlc);
return new LibVLCSharp.Shared.MediaPlayer(libVlc);
});
services.AddSingleton<IMediaPlayerService>(sp =>
new VlcMediaPlayerService(sp.GetRequiredService<LibVLCSharp.Shared.MediaPlayer>(), sp.GetRequiredService<LibVLC>()));
services.AddSingleton<AnnotatorEventHandler>();
services.AddSingleton<IDbFactory, DbFactory>();
services.AddSingleton<FailsafeAnnotationsProducer>();
services.AddSingleton<IAnnotationRepository, AnnotationRepository>();
services.AddSingleton<IAnnotationService, AnnotationService>();
services.AddSingleton<DatasetExplorer>();
@@ -175,9 +188,6 @@ public partial class App
})
.Build();
Annotation.Init(_host.Services.GetRequiredService<IOptions<DirectoriesConfig>>().Value,
_host.Services.GetRequiredService<IOptions<AnnotationConfig>>().Value.DetectionClassesDict);
_host.Services.GetRequiredService<DatasetExplorer>();
_mediator = _host.Services.GetRequiredService<IMediator>();
@@ -186,6 +196,14 @@ public partial class App
DispatcherUnhandledException += OnDispatcherUnhandledException;
_host.Start();
_ = Task.Run(async () =>
{
await _host.Services.GetRequiredService<IAnnotationService>().StartQueueConsumerAsync();
await _host.Services.GetRequiredService<FailsafeAnnotationsProducer>().StartAsync();
await _host.Services.GetRequiredService<IInferenceService>().StartAsync();
});
EventManager.RegisterClassHandler(typeof(UIElement), UIElement.PreviewKeyDownEvent, new RoutedEventHandler(GlobalKeyHandler));
_host.Services.GetRequiredService<MainSuite>().Show();
}
@@ -0,0 +1,65 @@
using Azaion.Common.Services;
using LibVLCSharp.Shared;
namespace Azaion.Suite.Services;
public class VlcMediaPlayerService : IMediaPlayerService
{
private readonly MediaPlayer _mediaPlayer;
private readonly LibVLC _libVlc;
public VlcMediaPlayerService(MediaPlayer mediaPlayer, LibVLC libVlc)
{
_mediaPlayer = mediaPlayer;
_libVlc = libVlc;
_mediaPlayer.Playing += (s, e) => Playing?.Invoke(s, e);
_mediaPlayer.Paused += (s, e) => Paused?.Invoke(s, e);
_mediaPlayer.Stopped += (s, e) => Stopped?.Invoke(s, e);
_mediaPlayer.PositionChanged += (s, e) => PositionChanged?.Invoke(s, e);
_mediaPlayer.LengthChanged += (s, e) => LengthChanged?.Invoke(s, e);
}
public void Play() => _mediaPlayer.Play();
public void Pause() => _mediaPlayer.Pause();
public void Stop() => _mediaPlayer.Stop();
public long Time
{
get => _mediaPlayer.Time;
set => _mediaPlayer.Time = value;
}
public float Position
{
get => _mediaPlayer.Position;
set => _mediaPlayer.Position = value;
}
public int Volume
{
get => _mediaPlayer.Volume;
set => _mediaPlayer.Volume = value;
}
public bool IsPlaying => _mediaPlayer.IsPlaying;
public long Length => _mediaPlayer.Length;
public void SetMedia(string mediaPath)
{
using var media = new Media(_libVlc, mediaPath);
_mediaPlayer.Media = media;
}
public void TakeSnapshot(uint num, string path, uint width, uint height)
{
_mediaPlayer.TakeSnapshot(num, path, width, height);
}
public event EventHandler? Playing;
public event EventHandler? Paused;
public event EventHandler? Stopped;
public event EventHandler? PositionChanged;
public event EventHandler? LengthChanged;
}