Files
annotations/Azaion.Suite/Loader.xaml.cs
T
Alex Bezdieniezhnykh 5a592e9dbf rework to Azaion.Suite
2024-11-21 13:41:32 +02:00

59 lines
1.9 KiB
C#

using System.IO;
using System.Reflection;
using System.Runtime.Loader;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Azaion.Suite.Services.DTO;
using Microsoft.Extensions.Options;
namespace Azaion.Suite;
public partial class Loader : Window
{
private readonly IResourceLoader _resourceLoader;
private readonly IOptions<LocalFilesConfig> _localFilesConfig;
public Loader(IResourceLoader resourceLoader, IOptions<LocalFilesConfig> localFilesConfig)
{
_resourceLoader = resourceLoader;
_localFilesConfig = localFilesConfig;
InitializeComponent();
}
private async void RunClick(object sender, RoutedEventArgs e)
{
var stream = new MemoryStream();
await _resourceLoader.LoadAnnotator(TbEmail.Text, TbPassword.Password, stream);
stream.Seek(0, SeekOrigin.Begin);
var loader = new AssemblyLoadContext("DynamicContext", isCollectible: true);
var annotatorAssembly = loader.LoadFromStream(stream);
var appType = annotatorAssembly.GetType("Azaion.Annotator.App");
var appInstance = Activator.CreateInstance(appType);
var runMethod = appType.GetMethod("Run", BindingFlags.Public | BindingFlags.Instance);
if (runMethod != null)
{
runMethod.Invoke(appInstance, null);
}
// var entryPoint = annotatorAssembly.EntryPoint;
// if (entryPoint == null)
// return;
//
// var o = annotatorAssembly.CreateInstance(entryPoint.Name);
// entryPoint.Invoke(o, null);
}
private void CloseClick(object sender, RoutedEventArgs e) => Close();
private void MainMouseMove(object sender, MouseEventArgs e)
{
if (e.OriginalSource is Button || e.OriginalSource is TextBox)
return;
if (e.LeftButton == MouseButtonState.Pressed)
DragMove();
}
}