提交
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using System.Web.UI.WebControls;
|
||||
using UFIDA.U8.Framework.Api.ControlObject.Models;
|
||||
|
||||
namespace UFIDA.U8.Framework.Api.Unit
|
||||
{
|
||||
internal class AssemblyDynamicLoader
|
||||
{
|
||||
private long taskId;
|
||||
private AppDomain appDomain;
|
||||
private RemoteLoader remoteLoader;
|
||||
|
||||
internal AssemblyDynamicLoader(long taskId)
|
||||
{
|
||||
var basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"Bin");
|
||||
var binPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"U8M{taskId}");
|
||||
|
||||
Directory.CreateDirectory(binPath);
|
||||
|
||||
var setup = new AppDomainSetup
|
||||
{
|
||||
ApplicationName = $"U8M_{taskId}",
|
||||
ApplicationBase = basePath,
|
||||
PrivateBinPath = binPath,
|
||||
ShadowCopyFiles = "true"
|
||||
};
|
||||
setup.CachePath = setup.ApplicationBase;
|
||||
setup.ShadowCopyDirectories = setup.ApplicationBase;
|
||||
|
||||
appDomain = AppDomain.CreateDomain($"U8M_{taskId}", null, setup);
|
||||
|
||||
var name = Assembly.GetExecutingAssembly().GetName().FullName;
|
||||
remoteLoader = (RemoteLoader)appDomain.CreateInstanceAndUnwrap(name, typeof(RemoteLoader).FullName ?? throw new InvalidOperationException());
|
||||
}
|
||||
|
||||
internal BaseResult<string> Save(LoginParamter paramter, string cCardNum, Dictionary<string, object> input)
|
||||
{
|
||||
remoteLoader._paramter = paramter;
|
||||
|
||||
return remoteLoader.Save(cCardNum, input);
|
||||
}
|
||||
|
||||
internal BaseResult<string> Save(LoginParamter paramter, string cCardNum, List<Dictionary<string, object>> inputs)
|
||||
{
|
||||
remoteLoader._paramter = paramter;
|
||||
|
||||
return remoteLoader.Save(cCardNum, inputs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 卸载应用程序域
|
||||
/// </summary>
|
||||
internal void Unload()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (appDomain == null) return;
|
||||
AppDomain.Unload(appDomain);
|
||||
appDomain = null;
|
||||
remoteLoader = null;
|
||||
}
|
||||
catch (CannotUnloadAppDomainException ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user