mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 12:56:30 +00:00
rework to Azaion.Suite
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user