diff --git a/Azaion.Annotator/Annotator.xaml.cs b/Azaion.Annotator/Annotator.xaml.cs
index d5c3507..7a96d2a 100644
--- a/Azaion.Annotator/Annotator.xaml.cs
+++ b/Azaion.Annotator/Annotator.xaml.cs
@@ -76,7 +76,7 @@ public partial class Annotator
_vlcFrameExtractor = vlcFrameExtractor;
_aiDetector = aiDetector;
- VideoView.Loaded += VideoView_Loaded;
+ Loaded += VideoView_Loaded;
Closed += OnFormClosed;
Editor.GetTimeFunc = () => TimeSpan.FromMilliseconds(_mediaPlayer.Time);
diff --git a/Azaion.Annotator/AnnotatorModule.cs b/Azaion.Annotator/AnnotatorModule.cs
index 58a84d5..3b75e36 100644
--- a/Azaion.Annotator/AnnotatorModule.cs
+++ b/Azaion.Annotator/AnnotatorModule.cs
@@ -50,4 +50,6 @@ public class AnnotatorModule : IAzaionModule
";
public Type MainWindowType => typeof(Annotator);
+
+ public WindowEnum WindowEnum => WindowEnum.Annotator;
}
\ No newline at end of file
diff --git a/Azaion.Annotator/Azaion.Annotator.csproj b/Azaion.Annotator/Azaion.Annotator.csproj
index 16b70fe..117bdf4 100644
--- a/Azaion.Annotator/Azaion.Annotator.csproj
+++ b/Azaion.Annotator/Azaion.Annotator.csproj
@@ -41,12 +41,4 @@
Designer
-
-
-
-
- PreserveNewest
-
-
-
diff --git a/Azaion.Annotator/annotator-logo.svg b/Azaion.Annotator/annotator-logo.svg
deleted file mode 100644
index 1321274..0000000
--- a/Azaion.Annotator/annotator-logo.svg
+++ /dev/null
@@ -1,38 +0,0 @@
-
-
-
diff --git a/Azaion.Common/Azaion.Common.csproj b/Azaion.Common/Azaion.Common.csproj
index 66fdfdf..b7bdd7e 100644
--- a/Azaion.Common/Azaion.Common.csproj
+++ b/Azaion.Common/Azaion.Common.csproj
@@ -7,6 +7,7 @@
+
diff --git a/Azaion.Suite/SuiteCommandLineOptions.cs b/Azaion.Common/DTO/ApiCredentials.cs
similarity index 80%
rename from Azaion.Suite/SuiteCommandLineOptions.cs
rename to Azaion.Common/DTO/ApiCredentials.cs
index b825694..2761ede 100644
--- a/Azaion.Suite/SuiteCommandLineOptions.cs
+++ b/Azaion.Common/DTO/ApiCredentials.cs
@@ -1,8 +1,8 @@
using CommandLine;
-namespace Azaion.Suite.Services.DTO;
+namespace Azaion.Common.DTO;
-public class SuiteCommandLineOptions
+public class ApiCredentials
{
[Option('e', "email", Required = true, HelpText = "The email for authorization.")]
public string Email { get; set; } = null!;
diff --git a/Azaion.Common/DTO/IAzaionModule.cs b/Azaion.Common/DTO/IAzaionModule.cs
index 3ae48cb..5a300a4 100644
--- a/Azaion.Common/DTO/IAzaionModule.cs
+++ b/Azaion.Common/DTO/IAzaionModule.cs
@@ -5,4 +5,5 @@ public interface IAzaionModule
string Name { get; }
string SvgIcon { get; }
Type MainWindowType { get; }
+ WindowEnum WindowEnum { get; }
}
\ No newline at end of file
diff --git a/Azaion.Common/Extensions/WindowExtensions.cs b/Azaion.Common/Extensions/WindowExtensions.cs
deleted file mode 100644
index 1507d42..0000000
--- a/Azaion.Common/Extensions/WindowExtensions.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System.Windows;
-using Azaion.Common.DTO;
-
-namespace Azaion.Common.Extensions;
-
-public static class WindowExtensions
-{
- public static WindowEnum GetParentWindow(this FrameworkElement? element)
- {
- while (element != null && element is not Window)
- {
- element = element.Parent as FrameworkElement;
- }
-
- if (element is not Window)
- return WindowEnum.None;
-
- return WindowEnum.Annotator;
- }
-}
\ No newline at end of file
diff --git a/Azaion.Common/Services/AzaionApiClient.cs b/Azaion.Common/Services/AzaionApiClient.cs
index 3e91363..c1a02cf 100644
--- a/Azaion.Common/Services/AzaionApiClient.cs
+++ b/Azaion.Common/Services/AzaionApiClient.cs
@@ -17,13 +17,13 @@ public class AzaionApiClient(HttpClient httpClient) : IDisposable
private SecureString Password { get; set; } = new();
private string JwtToken { get; set; } = null!;
- public void Login(string email, string password)
+ public void EnterCredentials(ApiCredentials credentials)
{
- if (string.IsNullOrWhiteSpace(email) || string.IsNullOrWhiteSpace(password))
+ if (string.IsNullOrWhiteSpace(credentials.Email) || string.IsNullOrWhiteSpace(credentials.Password))
throw new Exception("Email or password is empty!");
- Email = email;
- Password = password.ToSecureString();
+ Email = credentials.Email;
+ Password = credentials.Password.ToSecureString();
}
public async Task GetResource(string fileName, string password, HardwareInfo hardware)
@@ -38,7 +38,7 @@ public class AzaionApiClient(HttpClient httpClient) : IDisposable
private async Task Authorize()
{
if (string.IsNullOrEmpty(Email) || Password.Length == 0)
- throw new Exception("Email or password is empty! Please do Login first!");
+ throw new Exception("Email or password is empty! Please do EnterCredentials first!");
var payload = new
{
@@ -50,7 +50,7 @@ public class AzaionApiClient(HttpClient httpClient) : IDisposable
new StringContent(JsonConvert.SerializeObject(payload), Encoding.UTF8, JSON_MEDIA));
if (!response.IsSuccessStatusCode)
- throw new Exception($"Login failed: {response.StatusCode}");
+ throw new Exception($"EnterCredentials failed: {response.StatusCode}");
var responseData = await response.Content.ReadAsStringAsync();
diff --git a/Azaion.Common/Services/ResourceLoader.cs b/Azaion.Common/Services/ResourceLoader.cs
index 515eaac..82a33f5 100644
--- a/Azaion.Common/Services/ResourceLoader.cs
+++ b/Azaion.Common/Services/ResourceLoader.cs
@@ -1,20 +1,45 @@
using System.IO;
+using System.Reflection;
+using Azaion.Common.DTO;
namespace Azaion.Common.Services;
public interface IResourceLoader
{
Task Load(string fileName, CancellationToken cancellationToken = default);
+ Assembly LoadAssembly(string asmName);
}
-public class ResourceLoader(string email, string password, AzaionApiClient api, IHardwareService hardwareService) : IResourceLoader
+public class ResourceLoader(AzaionApiClient api, ApiCredentials credentials) : IResourceLoader
{
+ private static readonly List EncryptedResources =
+ [
+ "Azaion.Annotator",
+ "Azaion.Dataset"
+ ];
+
+ public Assembly LoadAssembly(string resourceName)
+ {
+ var assemblyName = resourceName.Split(',').First();
+ if (EncryptedResources.Contains(assemblyName))
+ {
+ var stream = Load(assemblyName).GetAwaiter().GetResult();
+ return Assembly.Load(stream.ToArray());
+ }
+
+ var loadedAssembly = AppDomain.CurrentDomain.GetAssemblies()
+ .FirstOrDefault(a => a.GetName().Name == assemblyName);
+
+ return loadedAssembly;
+ }
+
public async Task Load(string fileName, CancellationToken cancellationToken = default)
{
+ var hardwareService = new HardwareService();
var hardwareInfo = await hardwareService.GetHardware();
- var encryptedStream = await api.GetResource(fileName, password, hardwareInfo);
+ var encryptedStream = await api.GetResource(fileName, credentials.Password, hardwareInfo);
- var key = Security.MakeEncryptionKey(email, password, hardwareInfo.Hash);
+ var key = Security.MakeEncryptionKey(credentials.Email, credentials.Password, hardwareInfo.Hash);
var stream = new MemoryStream();
await encryptedStream.DecryptTo(stream, key, cancellationToken);
return stream;
diff --git a/Azaion.Dataset/Azaion.Dataset.csproj b/Azaion.Dataset/Azaion.Dataset.csproj
index b48bab1..3c9880d 100644
--- a/Azaion.Dataset/Azaion.Dataset.csproj
+++ b/Azaion.Dataset/Azaion.Dataset.csproj
@@ -25,10 +25,4 @@
-
-
- C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\System.Drawing.Common.dll
-
-
-
diff --git a/Azaion.Dataset/DatasetExplorer.xaml.cs b/Azaion.Dataset/DatasetExplorer.xaml.cs
index 6159ca4..da37c08 100644
--- a/Azaion.Dataset/DatasetExplorer.xaml.cs
+++ b/Azaion.Dataset/DatasetExplorer.xaml.cs
@@ -3,7 +3,6 @@ using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
-using Azaion.Annotator.Extensions;
using Azaion.Common;
using Azaion.Common.DTO;
using Azaion.Common.DTO.Config;
diff --git a/Azaion.Dataset/DatasetExplorerModule.cs b/Azaion.Dataset/DatasetExplorerModule.cs
index ee2fb91..37a2922 100644
--- a/Azaion.Dataset/DatasetExplorerModule.cs
+++ b/Azaion.Dataset/DatasetExplorerModule.cs
@@ -20,4 +20,6 @@ public class DatasetExplorerModule : IAzaionModule
";
public Type MainWindowType => typeof(DatasetExplorer);
+
+ public WindowEnum WindowEnum => WindowEnum.DatasetExplorer;
}
\ No newline at end of file
diff --git a/Azaion.Suite/App.xaml.cs b/Azaion.Suite/App.xaml.cs
index 4e3f900..0f2dca3 100644
--- a/Azaion.Suite/App.xaml.cs
+++ b/Azaion.Suite/App.xaml.cs
@@ -1,7 +1,7 @@
using System.IO;
using System.Net.Http;
-using System.Reflection;
using System.Windows;
+using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using Azaion.Annotator;
@@ -13,7 +13,6 @@ using Azaion.Common.DTO.Config;
using Azaion.Common.Extensions;
using Azaion.Common.Services;
using Azaion.Dataset;
-using Azaion.Suite.Services.DTO;
using CommandLine;
using LibVLCSharp.Shared;
using MediatR;
@@ -33,24 +32,28 @@ public partial class App
private readonly ILogger _logger;
private readonly IMediator _mediator;
- private static readonly List EncryptedResources =
- [
- "Azaion.Annotator.dll",
- "Azaion.Dataset.dll"
- ];
-
- private static readonly IResourceLoader? ResourceLoader = new ResourceLoader("", "", null!, null!);
+ //Authorize to api and
+ private static readonly IResourceLoader ResourceLoader;
static App()
{
- //Load encrypted dlls
- var result = Parser.Default.ParseArguments(Environment.GetCommandLineArgs());
+ new ConfigUpdater().CheckConfig();
+
+ var result = Parser.Default.ParseArguments(Environment.GetCommandLineArgs());
if (result.Errors.Any())
- return;
+ return;
+ var apiCreds = result.Value;
+
+ ResourceLoader = new ResourceLoader(CreateApiClient(apiCreds), apiCreds);
+ AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => ResourceLoader.LoadAssembly(args.Name);
+ }
+
+ private static AzaionApiClient CreateApiClient(ApiCredentials credentials)
+ {
ApiConfig apiConfig;
try
{
- if (File.Exists(Constants.CONFIG_PATH))
+ if (!File.Exists(Constants.CONFIG_PATH))
throw new FileNotFoundException(Constants.CONFIG_PATH);
var configStr = File.ReadAllText(Constants.CONFIG_PATH);
apiConfig = JsonConvert.DeserializeObject(configStr)!.ApiConfig;
@@ -70,19 +73,9 @@ public partial class App
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();
+ api.EnterCredentials(credentials);
+ return api;
}
public App()
@@ -104,7 +97,7 @@ public partial class App
{
services.AddSingleton();
services.AddSingleton();
- services.AddSingleton(ResourceLoader!);
+ services.AddSingleton(ResourceLoader);
services.Configure(context.Configuration);
services.ConfigureSection(context.Configuration);
@@ -170,10 +163,27 @@ public partial class App
private void GlobalClick(object sender, RoutedEventArgs e)
{
var args = (KeyEventArgs)e;
- var keyEvent = new KeyEvent(sender, args, (sender as FrameworkElement).GetParentWindow());
+ var windowEnum = GetParentWindow(sender as FrameworkElement);
+ if (windowEnum == WindowEnum.None)
+ return;
+ var keyEvent = new KeyEvent(sender, args, windowEnum);
_ = ThrottleExt.Throttle(() => _mediator.Publish(keyEvent), TimeSpan.FromMilliseconds(50));
}
+ private WindowEnum GetParentWindow(FrameworkElement? element)
+ {
+ while (element != null && element is not TabItem)
+ {
+ element = element.Parent as FrameworkElement;
+ }
+
+ if (element is not TabItem || element.Tag == null)
+ return WindowEnum.None;
+
+ return (WindowEnum)element.Tag;
+ }
+
+
protected override async void OnExit(ExitEventArgs e)
{
base.OnExit(e);
diff --git a/Azaion.Suite/AssemblyInfo.cs b/Azaion.Suite/AssemblyInfo.cs
index 4a05c7d..b9d746b 100644
--- a/Azaion.Suite/AssemblyInfo.cs
+++ b/Azaion.Suite/AssemblyInfo.cs
@@ -7,4 +7,4 @@ using System.Windows;
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
-)]
\ No newline at end of file
+)]
diff --git a/Azaion.Suite/MainSuite.xaml b/Azaion.Suite/MainSuite.xaml
index 23d642f..dd1ca2f 100644
--- a/Azaion.Suite/MainSuite.xaml
+++ b/Azaion.Suite/MainSuite.xaml
@@ -4,7 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
- Title="MainSuite" Height="450" Width="800">
+ Title="Azaion Оператор" Height="450" Width="800">