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) : 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; } }