提交
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using log4net;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UFIDA.U8.Framework.Api.ControlObject.Models;
|
||||
using UFIDA.U8.Framework.Api.ControlObject.U8M;
|
||||
|
||||
namespace UFIDA.U8.Framework.Api.Unit
|
||||
{
|
||||
/// <summary>
|
||||
/// 跨域加载
|
||||
/// </summary>
|
||||
internal class RemoteLoader : MarshalByRefObject
|
||||
{
|
||||
public LoginParamter _paramter;
|
||||
private readonly ILog _logInfo = LogManager.GetLogger("logInfo");
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="paramter">登录参数</param>
|
||||
internal RemoteLoader(LoginParamter paramter)
|
||||
{
|
||||
_paramter = paramter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存
|
||||
/// </summary>
|
||||
/// <param name="cCardNum">单据类型编码</param>
|
||||
/// <param name="input">数据包</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
internal BaseResult<string> Save(string cCardNum, Dictionary<string, object> input)
|
||||
{
|
||||
try
|
||||
{
|
||||
IBaseBF bf;
|
||||
|
||||
switch (cCardNum)
|
||||
{
|
||||
case "FC90":
|
||||
case "FC91":
|
||||
case "FC92":
|
||||
bf = new MoRoutingBill();
|
||||
break;
|
||||
default:
|
||||
bf = null;
|
||||
break;
|
||||
}
|
||||
|
||||
if (bf == null)
|
||||
{
|
||||
throw new Exception("不支持的单据");
|
||||
}
|
||||
|
||||
var baseLogin = new BaseLogin();
|
||||
|
||||
baseLogin.Init(_paramter);
|
||||
|
||||
return bf.Save(cCardNum, input);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logInfo.Error(ex.Message, ex);
|
||||
return new BaseResult<string> { bSuccess = false, message = ex.Message, result = ex.StackTrace };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量保存
|
||||
/// </summary>
|
||||
/// <param name="cCardNum">单据类型编码</param>
|
||||
/// <param name="inputs">数据包</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
internal BaseResult<string> Save(string cCardNum, List<Dictionary<string, object>> inputs)
|
||||
{
|
||||
try
|
||||
{
|
||||
IBaseBF bf;
|
||||
|
||||
switch (cCardNum)
|
||||
{
|
||||
case "FC90":
|
||||
case "FC91":
|
||||
case "FC92":
|
||||
bf = new MoRoutingBill();
|
||||
break;
|
||||
default:
|
||||
bf = null;
|
||||
break;
|
||||
}
|
||||
|
||||
if (bf == null)
|
||||
{
|
||||
throw new Exception("不支持的单据");
|
||||
}
|
||||
|
||||
var baseLogin = new BaseLogin();
|
||||
|
||||
baseLogin.Init(_paramter);
|
||||
|
||||
return bf.Save(cCardNum, inputs);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logInfo.Error(ex.Message, ex);
|
||||
return new BaseResult<string> { bSuccess = false, message = ex.Message, result = ex.StackTrace };
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user