using System;
using System.Reflection;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
namespace prBrowser
{
public class RemoteLoader : MarshalByRefObject
{
public string GetValue(string input)
{
//System.Diagnostics.Debugger.Launch();
JObject jObject = new JObject();
string retstring = "";
string directory = "";
try
{
JObject jsonObj = JObject.Parse(input);
string inputDir = "";
string clsName = "";
string funcName = "";
string dllInput = "";
if (jsonObj["inputDir"] != null)
{
inputDir = jsonObj["inputDir"]!.ToString();
directory = inputDir.Replace("/", ".").Replace("\\", ".");
string spcfolder = Application.StartupPath;
spcfolder = spcfolder.Replace("\\", "/");
//inputDir = spcfolder + "/service/plugins/" + inputDir;
//QY 重写GetIP.dll文件路径
if (inputDir.IndexOf("GetIP.dll") !=-1)
{
inputDir = "/GetIP.dll";
}
inputDir = spcfolder + inputDir;
}
if (jsonObj["clsName"] != null)
{
clsName = jsonObj["clsName"]!.ToString();
}
if (jsonObj["funcName"] != null)
{
funcName = jsonObj["funcName"]!.ToString();
}
if (jsonObj["dllInput"] != null)
{
dllInput = jsonObj["dllInput"]!.ToString();
}
object[] temParts = null;
if (dllInput != "")
{
temParts = new object[1] { dllInput };
}
string path = inputDir;
Assembly assem = Assembly.LoadFrom(path);
Type clsType = assem.GetType(clsName);
MethodInfo pMtInfo = clsType.GetMethod(funcName);
object tObj = Activator.CreateInstance(clsType);
retstring = (string)pMtInfo.Invoke(tObj, temParts);
}
catch (Exception ex)
{
jObject.Add("errorCode", (JToken)"-1");
string Messageerr = ex.Message;
if (ex.InnerException != null)
{ Messageerr = ex.InnerException.Message; }
jObject.Add("errorMessage", (JToken)Messageerr);
retstring = jObject.ToString();
}
return retstring;
}
///
///QY 复制文件夹及文件到指定目录
///
///
///
private void CopyDir(string srcPath, string aimPath)
{
try
{
// 检查目标目录是否以目录分割字符结束如果不是则添加
if (aimPath[aimPath.Length - 1] != System.IO.Path.DirectorySeparatorChar)
{
aimPath += System.IO.Path.DirectorySeparatorChar;
}
// 判断目标目录是否存在如果不存在则新建
if (!System.IO.Directory.Exists(aimPath))
{
System.IO.Directory.CreateDirectory(aimPath);
}
// 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组
// 如果你指向copy目标文件下面的文件而不包含目录请使用下面的方法
// string[] fileList = Directory.GetFiles(srcPath);
string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath);
// 遍历所有的文件和目录
foreach (string file in fileList)
{
// 先当作目录处理如果存在这个目录就递归Copy该目录下面的文件
if (System.IO.Directory.Exists(file))
{
CopyDir(file, aimPath + System.IO.Path.GetFileName(file));
}
// 否则直接Copy文件
else
{
System.IO.File.Copy(file, aimPath + System.IO.Path.GetFileName(file), true);
}
}
}
catch (Exception e)
{
throw;
}
}
}
}