mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 12:56: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();
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
||||
<PackageReference Include="LibVLCSharp" Version="3.9.1" />
|
||||
<PackageReference Include="LibVLCSharp.WPF" Version="3.9.1" />
|
||||
<PackageReference Include="MediatR" Version="12.4.1" />
|
||||
@@ -40,6 +39,14 @@
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Page Update="Login.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<XamlRuntime>Wpf</XamlRuntime>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="Build">
|
||||
<MakeDir Directories="$(TargetDir)secure" />
|
||||
<Move SourceFiles="$(TargetDir)Azaion.Annotator.dll" DestinationFolder="$(TargetDir)secure" />
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
<Window x:Class="Azaion.Suite.Login"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
WindowStyle="None"
|
||||
AllowsTransparency="True"
|
||||
Background="Transparent"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Title="Azaion Annotator Security"
|
||||
Height="280" Width="350">
|
||||
<Border Width="350"
|
||||
Height="280"
|
||||
Background="DarkGray"
|
||||
CornerRadius="15"
|
||||
MouseMove="MainMouseMove">
|
||||
<Border.Effect>
|
||||
<DropShadowEffect BlurRadius="15"
|
||||
Direction ="-90"
|
||||
RenderingBias ="Quality"
|
||||
ShadowDepth ="2"
|
||||
Color ="Gray" />
|
||||
</Border.Effect>
|
||||
<StackPanel Orientation="Vertical"
|
||||
Margin="20">
|
||||
<Canvas>
|
||||
<Button Padding="5" ToolTip="Закрити" Background="DarkGray" BorderBrush="DarkGray" Canvas.Left="290" Cursor="Hand"
|
||||
Name="CloseBtn"
|
||||
Click="CloseClick">
|
||||
<Path Stretch="Fill" Fill="LightGray" Data="M5.29289 5.29289C5.68342 4.90237 6.31658 4.90237 6.70711 5.29289L12 10.5858L17.2929 5.29289C17.6834 4.90237 18.3166
|
||||
4.90237 18.7071 5.29289C19.0976 5.68342 19.0976 6.31658 18.7071 6.70711L13.4142 12L18.7071 17.2929C19.0976 17.6834 19.0976 18.3166 18.7071 18.7071C18.3166
|
||||
19.0976 17.6834 19.0976 17.2929 18.7071L12 13.4142L6.70711 18.7071C6.31658 19.0976 5.68342 19.0976 5.29289 18.7071C4.90237 18.3166 4.90237 17.6834 5.29289
|
||||
17.2929L10.5858 12L5.29289 6.70711C4.90237 6.31658 4.90237 5.68342 5.29289 5.29289Z" />
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type Button}">
|
||||
<Border Background="{TemplateBinding Background}" BorderThickness="1">
|
||||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
</Button>
|
||||
</Canvas>
|
||||
<TextBlock Text="Вхід"
|
||||
FontSize="25"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top"
|
||||
FontWeight="Bold"
|
||||
/>
|
||||
<Grid VerticalAlignment="Center">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="Email"
|
||||
Grid.Row="0"
|
||||
Margin="0, 20, 0, 5"
|
||||
HorizontalAlignment="Left"/>
|
||||
<TextBox
|
||||
Name="TbEmail"
|
||||
Grid.Row="1"
|
||||
Padding="0,5"
|
||||
Width="300"
|
||||
FontSize="16"
|
||||
Background="DarkGray"
|
||||
BorderBrush="DimGray"
|
||||
BorderThickness="0,0,0,1"
|
||||
HorizontalAlignment="Left"
|
||||
/>
|
||||
<TextBlock Text="Пароль"
|
||||
Grid.Row="2"
|
||||
Margin="0, 20, 0, 5"
|
||||
HorizontalAlignment="Left"/>
|
||||
<PasswordBox Grid.Row="3"
|
||||
Name="TbPassword"
|
||||
FontSize="16"
|
||||
Background="DarkGray"
|
||||
BorderBrush="DimGray"
|
||||
Padding="0,5"
|
||||
Width="300"
|
||||
BorderThickness="0,0,0,1"
|
||||
HorizontalAlignment="Left"/>
|
||||
</Grid>
|
||||
<Button x:Name="LoginBtn"
|
||||
Content="Вхід"
|
||||
Foreground="White"
|
||||
Background="DimGray"
|
||||
Margin="0,25"
|
||||
Height="35"
|
||||
Width="280"
|
||||
Cursor="Hand"
|
||||
Click="LoginClick">
|
||||
<Button.Style>
|
||||
<Style TargetType="Button">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type Button}">
|
||||
<Border x:Name="LoginBorder" Background="{TemplateBinding Background}"
|
||||
CornerRadius="16">
|
||||
<ContentPresenter HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="LightGray" TargetName="LoginBorder" />
|
||||
<Setter Property="TextBlock.Foreground" Value="Black" TargetName="LoginBorder" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Window>
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Azaion.Common.DTO;
|
||||
|
||||
namespace Azaion.Suite;
|
||||
|
||||
public partial class Login
|
||||
{
|
||||
public Login()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public event EventHandler<ApiCredentials>? CredentialsEntered;
|
||||
|
||||
private void LoginClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CredentialsEntered?.Invoke(this, new ApiCredentials(TbEmail.Text, TbPassword.Password));
|
||||
Close();
|
||||
}
|
||||
|
||||
private void CloseClick(object sender, RoutedEventArgs e) => Close();
|
||||
|
||||
private void MainMouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.OriginalSource is Button || e.OriginalSource is TextBox)
|
||||
return;
|
||||
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
DragMove();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user