rework to Azaion.Suite

This commit is contained in:
Alex Bezdieniezhnykh
2024-11-21 13:41:32 +02:00
parent 2cf69f4e4e
commit 5a592e9dbf
76 changed files with 1739 additions and 882 deletions
+38
View File
@@ -0,0 +1,38 @@
using System.IO;
using System.Reflection;
using Azaion.Suite.Services;
using Azaion.Suite.Services.DTO;
using Microsoft.Extensions.Options;
namespace Azaion.Suite;
public interface IResourceLoader
{
Task LoadAnnotator(string email, string password, Stream outStream, CancellationToken cancellationToken = default);
Assembly LoadAssembly(string name, CancellationToken cancellationToken = default);
}
public class ResourceLoader(AzaionApiClient azaionApi, IHardwareService hardwareService, IOptions<LocalFilesConfig> localFilesConfig) : IResourceLoader
{
public async Task LoadAnnotator(string email, string password, Stream outStream, CancellationToken cancellationToken = default)
{
var hardwareInfo = await hardwareService.GetHardware();
azaionApi.Login(email, password);
var key = Security.MakeEncryptionKey(email, password, hardwareInfo.Hash);
var encryptedStream = await azaionApi.GetResource(password, hardwareInfo, ResourceEnum.AnnotatorDll);
await encryptedStream.DecryptTo(outStream, key, cancellationToken);
//return Assembly.Load(stream.ToArray());
}
public Assembly LoadAssembly(string name, CancellationToken cancellationToken = default)
{
var dllValues = name.Split(",");
var dllName = $"{dllValues[0]}.dll";
var currentLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
var asm = Assembly.LoadFile(Path.Combine(currentLocation, localFilesConfig.Value.DllPath, dllName));
return asm;
}
}