mirror of
https://github.com/azaion/annotations.git
synced 2026-04-23 00:16:30 +00:00
rework to Azaion.Suite, show tabs with annotator and dataset explorer
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using Azaion.Annotator;
|
||||
using Azaion.Annotator.DTO;
|
||||
using Azaion.Annotator.Extensions;
|
||||
using Azaion.Common;
|
||||
using Azaion.Common.DTO;
|
||||
using Azaion.Common.DTO.Config;
|
||||
using Azaion.Common.Extensions;
|
||||
using Azaion.Common.Services;
|
||||
using Azaion.Suite.Services;
|
||||
using Azaion.Suite.Services.DTO;
|
||||
using Azaion.Dataset;
|
||||
using Azaion.Suite.Services.DTO;
|
||||
using CommandLine;
|
||||
using LibVLCSharp.Shared;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@@ -18,16 +23,53 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using Serilog;
|
||||
|
||||
namespace Azaion.Suite;
|
||||
|
||||
public partial class App : Application
|
||||
public partial class App
|
||||
{
|
||||
private readonly IHost _host;
|
||||
private readonly ILogger<App> _logger;
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
private static readonly List<string> EncryptedResources =
|
||||
[
|
||||
"Azaion.Annotator.dll",
|
||||
"Azaion.Dataset.dll"
|
||||
];
|
||||
|
||||
private static readonly IResourceLoader? ResourceLoader;
|
||||
|
||||
static App()
|
||||
{
|
||||
var result = Parser.Default.ParseArguments<SuiteCommandLineOptions>(Environment.GetCommandLineArgs());
|
||||
if (result.Errors.Any())
|
||||
return;
|
||||
|
||||
var configStr = File.ReadAllText(Constants.CONFIG_PATH);
|
||||
var apiConfig = JsonConvert.DeserializeObject<AppConfig>(configStr)!.ApiConfig;
|
||||
var api = new AzaionApiClient(new HttpClient
|
||||
{
|
||||
BaseAddress = new Uri(apiConfig.Url),
|
||||
Timeout = TimeSpan.FromSeconds(apiConfig.TimeoutSeconds)
|
||||
});
|
||||
var email = result.Value.Email;
|
||||
var password = result.Value.Password;
|
||||
|
||||
api.Login(email, password);
|
||||
|
||||
ResourceLoader = new ResourceLoader(email, password, api, new HardwareService());
|
||||
foreach (var resource in EncryptedResources)
|
||||
{
|
||||
var stream = ResourceLoader.Load(resource).GetAwaiter().GetResult();
|
||||
Assembly.Load(stream.ToArray());
|
||||
}
|
||||
|
||||
new ConfigUpdater().CheckConfig();
|
||||
}
|
||||
|
||||
public App()
|
||||
{
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
@@ -42,21 +84,30 @@ public partial class App : Application
|
||||
_host = Host.CreateDefaultBuilder()
|
||||
.ConfigureAppConfiguration((context, config) => config
|
||||
.AddCommandLine(Environment.GetCommandLineArgs())
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true))
|
||||
.AddJsonFile(Constants.CONFIG_PATH, optional: true, reloadOnChange: true))
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
services.AddSingleton<Loader>();
|
||||
services.AddSingleton<MainSuite>();
|
||||
services.AddSingleton<IHardwareService, HardwareService>();
|
||||
services.AddSingleton<IResourceLoader, ResourceLoader>();
|
||||
services.AddSingleton<IResourceLoader>(ResourceLoader!);
|
||||
|
||||
services.Configure<AppConfig>(context.Configuration);
|
||||
services.ConfigureSection<ApiConfig>(context.Configuration);
|
||||
services.ConfigureSection<DirectoriesConfig>(context.Configuration);
|
||||
services.ConfigureSection<AnnotationConfig>(context.Configuration);
|
||||
services.ConfigureSection<WindowConfig>(context.Configuration);
|
||||
services.ConfigureSection<AIRecognitionConfig>(context.Configuration);
|
||||
services.ConfigureSection<ThumbnailConfig>(context.Configuration);
|
||||
|
||||
services.Configure<ApiConfig>(context.Configuration.GetSection(nameof(ApiConfig)));
|
||||
services.AddSingleton<IConfigUpdater, ConfigUpdater>();
|
||||
|
||||
services.AddSingleton<Annotator.Annotator>();
|
||||
services.AddSingleton<DatasetExplorer>();
|
||||
services.AddSingleton<HelpWindow>();
|
||||
services.AddSingleton<IAIDetector, YOLODetector>();
|
||||
services.AddMediatR(c => c.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
|
||||
services.AddMediatR(c => c.RegisterServicesFromAssemblies(
|
||||
typeof(Annotator.Annotator).Assembly,
|
||||
typeof(DatasetExplorer).Assembly));
|
||||
services.AddSingleton<LibVLC>(_ => new LibVLC());
|
||||
services.AddSingleton<FormState>();
|
||||
services.AddSingleton<MediaPlayer>(sp =>
|
||||
@@ -93,7 +144,7 @@ public partial class App : Application
|
||||
{
|
||||
EventManager.RegisterClassHandler(typeof(UIElement), UIElement.KeyDownEvent, new RoutedEventHandler(GlobalClick));
|
||||
await _host.StartAsync();
|
||||
_host.Services.GetRequiredService<Loader>().Show();
|
||||
_host.Services.GetRequiredService<MainSuite>().Show();
|
||||
|
||||
base.OnStartup(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user