mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 10:16:30 +00:00
write logs for inference and loader to file
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Serilog;
|
||||
|
||||
namespace Azaion.LoaderUI;
|
||||
@@ -29,7 +28,7 @@ public partial class App
|
||||
var host = Host.CreateDefaultBuilder()
|
||||
.ConfigureAppConfiguration((_, config) => config
|
||||
.AddCommandLine(Environment.GetCommandLineArgs())
|
||||
.AddJsonFile(Constants.CONFIG_JSON_FILE))
|
||||
.AddJsonFile(Constants.CONFIG_JSON_FILE, optional: true))
|
||||
.UseSerilog()
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ApplicationIcon>..\logo.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -22,9 +23,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="loaderconfig.json" />
|
||||
<Content Include="loaderconfig.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace Azaion.LoaderUI;
|
||||
public interface IAzaionApi
|
||||
{
|
||||
void Login(ApiCredentials credentials);
|
||||
string GetLastInstallerName(string folder);
|
||||
(string name, Stream stream) DownloadInstaller(string folder);
|
||||
Task<string> GetLastInstallerName(string folder);
|
||||
Task<(string name, Stream stream)> DownloadInstaller(string folder);
|
||||
}
|
||||
|
||||
public class AzaionApi(HttpClient client) : IAzaionApi
|
||||
@@ -25,39 +25,39 @@ public class AzaionApi(HttpClient client) : IAzaionApi
|
||||
_credentials = credentials;
|
||||
}
|
||||
|
||||
public string GetLastInstallerName(string folder)
|
||||
public async Task<string> GetLastInstallerName(string folder)
|
||||
{
|
||||
var res = Get<List<string>>($"/resources/list/{folder}");
|
||||
var res = await Get<List<string>>($"/resources/list/{folder}");
|
||||
return res?.FirstOrDefault() ?? "";
|
||||
}
|
||||
|
||||
public (string name, Stream stream) DownloadInstaller(string folder)
|
||||
public async Task<(string name, Stream stream)> DownloadInstaller(string folder)
|
||||
{
|
||||
var response = Send(new HttpRequestMessage(HttpMethod.Get, $"resources/get-installer/{folder}"));
|
||||
var fileStream = response.Content.ReadAsStream();
|
||||
var response = await Send(new HttpRequestMessage(HttpMethod.Get, $"resources/get-installer/{folder}"));
|
||||
var fileStream = await response.Content.ReadAsStreamAsync();
|
||||
var fileName = response.Content.Headers.ContentDisposition?.FileName?.Trim('"') ?? "installer.exe";
|
||||
return (fileName, fileStream);
|
||||
}
|
||||
|
||||
private HttpResponseMessage Send(HttpRequestMessage request)
|
||||
private async Task<HttpResponseMessage> Send(HttpRequestMessage request)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_jwtToken))
|
||||
Authorize();
|
||||
await Authorize();
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _jwtToken);
|
||||
var response = client.Send(request);
|
||||
var response = await client.SendAsync(request);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
Authorize();
|
||||
await Authorize();
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _jwtToken);
|
||||
response = client.Send(request);
|
||||
response = await client.SendAsync(request);
|
||||
}
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
return response;
|
||||
|
||||
var stream = response.Content.ReadAsStream();
|
||||
var content = new StreamReader(stream).ReadToEnd();
|
||||
var stream = await response.Content.ReadAsStreamAsync();
|
||||
var content = await new StreamReader(stream).ReadToEndAsync();
|
||||
if (response.StatusCode == HttpStatusCode.Conflict)
|
||||
{
|
||||
var result = JsonConvert.DeserializeObject<BusinessExceptionDto>(content);
|
||||
@@ -66,23 +66,23 @@ public class AzaionApi(HttpClient client) : IAzaionApi
|
||||
throw new Exception($"Failed: {response.StatusCode}! Result: {content}");
|
||||
}
|
||||
|
||||
private T? Get<T>(string url)
|
||||
private async Task<T?> Get<T>(string url)
|
||||
{
|
||||
var response = Send(new HttpRequestMessage(HttpMethod.Get, url));
|
||||
var stream = response.Content.ReadAsStream();
|
||||
var json = new StreamReader(stream).ReadToEnd();
|
||||
var response = await Send(new HttpRequestMessage(HttpMethod.Get, url));
|
||||
var stream = await response.Content.ReadAsStreamAsync();
|
||||
var json = await new StreamReader(stream).ReadToEndAsync();
|
||||
return JsonConvert.DeserializeObject<T>(json);
|
||||
}
|
||||
|
||||
private void Put<T>(string url, T obj)
|
||||
private async Task Put<T>(string url, T obj)
|
||||
{
|
||||
Send(new HttpRequestMessage(HttpMethod.Put, url)
|
||||
await Send(new HttpRequestMessage(HttpMethod.Put, url)
|
||||
{
|
||||
Content = new StringContent(JsonConvert.SerializeObject(obj), Encoding.UTF8, APP_JSON)
|
||||
});
|
||||
}
|
||||
|
||||
private void Authorize()
|
||||
private async Task Authorize()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -95,13 +95,13 @@ public class AzaionApi(HttpClient client) : IAzaionApi
|
||||
password = _credentials.Password
|
||||
}), Encoding.UTF8, APP_JSON);
|
||||
var message = new HttpRequestMessage(HttpMethod.Post, "login") { Content = content };
|
||||
var response = client.Send(message);
|
||||
var response = await client.SendAsync(message);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
throw new Exception($"EnterCredentials failed: {response.StatusCode}");
|
||||
|
||||
var stream = response.Content.ReadAsStream();
|
||||
var json = new StreamReader(stream).ReadToEnd();
|
||||
var stream = await response.Content.ReadAsStreamAsync();
|
||||
var json = await new StreamReader(stream).ReadToEndAsync();
|
||||
var result = JsonConvert.DeserializeObject<LoginResponse>(json);
|
||||
|
||||
if (string.IsNullOrEmpty(result?.Token))
|
||||
|
||||
@@ -3,6 +3,7 @@ namespace Azaion.LoaderUI;
|
||||
public static class Constants
|
||||
{
|
||||
public const string CONFIG_JSON_FILE = "loaderconfig.json";
|
||||
public const string API_URL = "http://localhost:5219"; //"https://api.azaion.com";
|
||||
public const string API_URL = "https://api.azaion.com";
|
||||
public const string AZAION_SUITE_EXE = "Azaion.Suite.exe";
|
||||
public const string SUITE_FOLDER = "suite";
|
||||
}
|
||||
+41
-32
@@ -23,7 +23,7 @@
|
||||
Color ="Gray" />
|
||||
</Border.Effect>
|
||||
<StackPanel Orientation="Vertical"
|
||||
Margin="20">
|
||||
Margin="15">
|
||||
<Canvas>
|
||||
<Button Padding="5" ToolTip="Закрити" Background="DarkGray" BorderBrush="DarkGray" Canvas.Left="290" Cursor="Hand"
|
||||
Name="CloseBtn"
|
||||
@@ -59,6 +59,8 @@
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="Email"
|
||||
Grid.Row="0"
|
||||
@@ -90,38 +92,45 @@
|
||||
BorderThickness="0,0,0,1"
|
||||
HorizontalAlignment="Left"
|
||||
Password=""/>
|
||||
|
||||
<Button x:Name="LoginBtn"
|
||||
Grid.Row="4"
|
||||
Content="Вхід"
|
||||
Foreground="White"
|
||||
Background="DimGray"
|
||||
Margin="0,15"
|
||||
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>
|
||||
<TextBlock Name="TbStatus"
|
||||
Text=""
|
||||
Grid.Row="5"
|
||||
Margin="0, -10, 0, 5"
|
||||
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>
|
||||
|
||||
@@ -3,23 +3,27 @@ using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
|
||||
namespace Azaion.LoaderUI;
|
||||
|
||||
public partial class Login
|
||||
{
|
||||
private readonly IAzaionApi _azaionApi;
|
||||
private readonly DirectoriesConfig _dirConfig;
|
||||
private readonly ILogger<Login> _logger;
|
||||
private readonly DirectoriesConfig? _dirConfig;
|
||||
|
||||
public Login(IAzaionApi azaionApi, IOptions<DirectoriesConfig> directoriesConfig)
|
||||
public Login(IAzaionApi azaionApi, IOptions<DirectoriesConfig> directoriesConfig, ILogger<Login> logger)
|
||||
{
|
||||
_azaionApi = azaionApi;
|
||||
_logger = logger;
|
||||
_dirConfig = directoriesConfig.Value;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void LoginClick(object sender, RoutedEventArgs e)
|
||||
private async void LoginClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var creds = new ApiCredentials(TbEmail.Text, TbPassword.Password);
|
||||
if (!creds.IsValid())
|
||||
@@ -30,33 +34,43 @@ public partial class Login
|
||||
|
||||
_azaionApi.Login(creds);
|
||||
|
||||
if (GetInstallerVer() > GetLocalVer())
|
||||
DownloadAndRunInstaller();
|
||||
var installerVersion = await GetInstallerVer();
|
||||
var localVersion = GetLocalVer();
|
||||
|
||||
if (installerVersion > localVersion)
|
||||
{
|
||||
TbStatus.Text = $"Updating from {localVersion} to {installerVersion}...";
|
||||
await DownloadAndRunInstaller();
|
||||
TbStatus.Text = $"Installed {installerVersion}!";
|
||||
}
|
||||
else
|
||||
TbStatus.Text = $"Your version is up to date!";
|
||||
|
||||
Process.Start(Constants.AZAION_SUITE_EXE, $"-e {creds.Email} -p {creds.Password}");
|
||||
Close();
|
||||
}
|
||||
|
||||
private void DownloadAndRunInstaller()
|
||||
private async Task DownloadAndRunInstaller()
|
||||
{
|
||||
var (installerName, stream) = _azaionApi.DownloadInstaller(_dirConfig.SuiteInstallerDirectory);
|
||||
var (installerName, stream) = await _azaionApi.DownloadInstaller(_dirConfig?.SuiteInstallerDirectory ?? "");
|
||||
var localFileStream = new FileStream(installerName, FileMode.Create, FileAccess.Write);
|
||||
stream.CopyTo(localFileStream);
|
||||
await stream.CopyToAsync(localFileStream);
|
||||
localFileStream.Close();
|
||||
stream.Close();
|
||||
|
||||
var processInfo = new ProcessStartInfo(installerName)
|
||||
{
|
||||
UseShellExecute = true,
|
||||
Verb = "runas"
|
||||
Arguments = "/VERYSILENT"
|
||||
};
|
||||
|
||||
Process.Start(processInfo);
|
||||
var process = Process.Start(processInfo);
|
||||
await process!.WaitForExitAsync();
|
||||
}
|
||||
|
||||
private Version GetInstallerVer()
|
||||
private async Task<Version> GetInstallerVer()
|
||||
{
|
||||
var installerName = _azaionApi.GetLastInstallerName(_dirConfig.SuiteInstallerDirectory);
|
||||
TbStatus.Text = "Checking for the newer version...";
|
||||
var installerName = await _azaionApi.GetLastInstallerName(_dirConfig?.SuiteInstallerDirectory ?? Constants.SUITE_FOLDER);
|
||||
var version = installerName
|
||||
.Replace("AzaionSuite.Iterative.", "")
|
||||
.Replace(".exe", "");
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"DirectoriesConfig":
|
||||
{
|
||||
"SuiteInstallerDirectory": ""
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user