consolidate CommonSecurity to Common.dll

This commit is contained in:
Alex Bezdieniezhnykh
2025-06-13 23:06:48 +03:00
parent 904bc688ca
commit 8aa2f563a4
58 changed files with 362 additions and 151 deletions
+54 -4
View File
@@ -1,29 +1,79 @@
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Azaion.CommonSecurity.DTO;
using Microsoft.Extensions.Options;
namespace Azaion.LoaderUI;
public partial class Login
{
public Login()
private readonly IAzaionApi _azaionApi;
private readonly DirectoriesConfig _dirConfig;
public Login(IAzaionApi azaionApi, IOptions<DirectoriesConfig> directoriesConfig)
{
_azaionApi = azaionApi;
_dirConfig = directoriesConfig.Value;
InitializeComponent();
}
private void LoginClick(object sender, RoutedEventArgs e)
{
var creds = new ApiCredentials(TbEmail.Text, TbPassword.Password);
if (!creds.IsValid())
return;
LoginBtn.Cursor = Cursors.Wait;
Cursor = Cursors.Wait;
Process.Start("Azaion.Suite.exe", $"-e {TbEmail.Text} -p {TbPassword.Password}");
_azaionApi.Login(creds);
if (GetInstallerVer() > GetLocalVer())
DownloadAndRunInstaller();
Process.Start(Constants.AZAION_SUITE_EXE, $"-e {creds.Email} -p {creds.Password}");
Close();
}
private void DownloadAndRunInstaller()
{
var (installerName, stream) = _azaionApi.DownloadInstaller(_dirConfig.SuiteInstallerDirectory);
var localFileStream = new FileStream(installerName, FileMode.Create, FileAccess.Write);
stream.CopyTo(localFileStream);
localFileStream.Close();
stream.Close();
var processInfo = new ProcessStartInfo(installerName)
{
UseShellExecute = true,
Verb = "runas"
};
Process.Start(processInfo);
}
private Version GetInstallerVer()
{
var installerName = _azaionApi.GetLastInstallerName(_dirConfig.SuiteInstallerDirectory);
var version = installerName
.Replace("AzaionSuite.Iterative.", "")
.Replace(".exe", "");
return new Version(version);
}
private Version GetLocalVer()
{
var localFileInfo = FileVersionInfo.GetVersionInfo(Constants.AZAION_SUITE_EXE);
if (string.IsNullOrWhiteSpace(localFileInfo.ProductVersion))
throw new Exception($"Can't find {Constants.AZAION_SUITE_EXE} and its version");
return new Version(localFileInfo.FileVersion!);
}
private void CloseClick(object sender, RoutedEventArgs e) => Close();
private void MainMouseMove(object sende0r, MouseEventArgs e)
private void MainMouseMove(object sender, MouseEventArgs e)
{
if (e.OriginalSource is Button || e.OriginalSource is TextBox)
return;