mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 11:06:30 +00:00
rework to have only 1 exe!
This commit is contained in:
+48
-61
@@ -1,10 +1,8 @@
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
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;
|
||||
@@ -12,7 +10,6 @@ using Azaion.Common.DTO.Config;
|
||||
using Azaion.Common.Extensions;
|
||||
using Azaion.Common.Services;
|
||||
using Azaion.Dataset;
|
||||
using CommandLine;
|
||||
using LibVLCSharp.Shared;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@@ -22,31 +19,19 @@ using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using Serilog;
|
||||
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
||||
|
||||
namespace Azaion.Suite;
|
||||
|
||||
public partial class App
|
||||
{
|
||||
private readonly IHost _host;
|
||||
private readonly ILogger<App> _logger;
|
||||
private readonly IMediator _mediator;
|
||||
private IHost _host = null!;
|
||||
private ILogger<App> _logger = null!;
|
||||
private IMediator _mediator = null!;
|
||||
private FormState _formState = null!;
|
||||
|
||||
//Authorize to api and
|
||||
private static readonly IResourceLoader ResourceLoader;
|
||||
|
||||
static App()
|
||||
{
|
||||
new ConfigUpdater().CheckConfig();
|
||||
|
||||
var result = Parser.Default.ParseArguments<ApiCredentials>(Environment.GetCommandLineArgs());
|
||||
|
||||
var apiCreds = !result.Errors.Any()
|
||||
? result.Value
|
||||
: new ApiCredentials();
|
||||
|
||||
ResourceLoader = new ResourceLoader(CreateApiClient(apiCreds), apiCreds);
|
||||
AppDomain.CurrentDomain.AssemblyResolve += (_, args) => ResourceLoader.LoadAssembly(args.Name);
|
||||
}
|
||||
private AzaionApiClient _apiClient = null!;
|
||||
private IResourceLoader _resourceLoader = null!;
|
||||
|
||||
private static AzaionApiClient CreateApiClient(ApiCredentials credentials)
|
||||
{
|
||||
@@ -68,6 +53,7 @@ public partial class App
|
||||
TimeoutSeconds = 40
|
||||
};
|
||||
}
|
||||
|
||||
var api = new AzaionApiClient(new HttpClient
|
||||
{
|
||||
BaseAddress = new Uri(apiConfig.Url),
|
||||
@@ -78,7 +64,40 @@ public partial class App
|
||||
return api;
|
||||
}
|
||||
|
||||
public App()
|
||||
|
||||
private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
|
||||
{
|
||||
_logger.LogError(e.Exception, e.Exception.Message);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
StartLogin();
|
||||
}
|
||||
|
||||
private void StartLogin()
|
||||
{
|
||||
new ConfigUpdater().CheckConfig();
|
||||
var login = new Login();
|
||||
login.CredentialsEntered += async (s, args) =>
|
||||
{
|
||||
_apiClient = CreateApiClient(args);
|
||||
_resourceLoader = new ResourceLoader(_apiClient, args);
|
||||
AppDomain.CurrentDomain.AssemblyResolve += (_, a) => _resourceLoader.LoadAssembly(a.Name);
|
||||
|
||||
StartMain();
|
||||
|
||||
EventManager.RegisterClassHandler(typeof(UIElement), UIElement.KeyDownEvent, new RoutedEventHandler(GlobalClick));
|
||||
await _host.StartAsync();
|
||||
_host.Services.GetRequiredService<MainSuite>().Show();
|
||||
};
|
||||
|
||||
login.ShowDialog();
|
||||
}
|
||||
|
||||
private void StartMain()
|
||||
{
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.Enrich.FromLogContext()
|
||||
@@ -97,7 +116,9 @@ public partial class App
|
||||
{
|
||||
services.AddSingleton<MainSuite>();
|
||||
services.AddSingleton<IHardwareService, HardwareService>();
|
||||
services.AddSingleton(ResourceLoader);
|
||||
|
||||
services.AddSingleton(_apiClient);
|
||||
services.AddSingleton(_resourceLoader);
|
||||
|
||||
services.Configure<AppConfig>(context.Configuration);
|
||||
services.ConfigureSection<ApiConfig>(context.Configuration);
|
||||
@@ -141,31 +162,15 @@ public partial class App
|
||||
.Build();
|
||||
_mediator = _host.Services.GetRequiredService<IMediator>();
|
||||
_logger = _host.Services.GetRequiredService<ILogger<App>>();
|
||||
_formState = _host.Services.GetRequiredService<FormState>();
|
||||
DispatcherUnhandledException += OnDispatcherUnhandledException;
|
||||
}
|
||||
|
||||
private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
|
||||
{
|
||||
_logger.LogError(e.Exception, e.Exception.Message);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
protected override async void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
EventManager.RegisterClassHandler(typeof(UIElement), UIElement.KeyDownEvent, new RoutedEventHandler(GlobalClick));
|
||||
await _host.StartAsync();
|
||||
_host.Services.GetRequiredService<MainSuite>().Show();
|
||||
|
||||
base.OnStartup(e);
|
||||
}
|
||||
|
||||
private void GlobalClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var args = (KeyEventArgs)e;
|
||||
var windowEnum = GetParentWindow(sender as FrameworkElement);
|
||||
if (windowEnum == WindowEnum.None)
|
||||
return;
|
||||
var keyEvent = new KeyEvent(sender, args, windowEnum);
|
||||
|
||||
var keyEvent = new KeyEvent(sender, args, _formState.ActiveWindow);
|
||||
_ = ThrottleExt.Throttle(() => _mediator.Publish(keyEvent), TimeSpan.FromMilliseconds(50));
|
||||
}
|
||||
|
||||
@@ -176,27 +181,9 @@ public partial class App
|
||||
{ "Azaion.Dataset.DatasetExplorer", WindowEnum.DatasetExplorer }
|
||||
};
|
||||
|
||||
private WindowEnum GetParentWindow(FrameworkElement? element)
|
||||
{
|
||||
while (element != null)
|
||||
{
|
||||
var windowEnum = _uiElementToWindowEnum!.GetValueOrDefault(element.GetType().FullName);
|
||||
|
||||
if (windowEnum != WindowEnum.None)
|
||||
return windowEnum;
|
||||
|
||||
element = (element.Parent ?? element.TemplatedParent) as FrameworkElement;
|
||||
}
|
||||
|
||||
return WindowEnum.None;
|
||||
}
|
||||
|
||||
|
||||
protected override async void OnExit(ExitEventArgs e)
|
||||
{
|
||||
base.OnExit(e);
|
||||
|
||||
await _host.StopAsync();
|
||||
//_host.Dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user