InvokePlugin.cs
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using DocumentFormat.OpenXml.Spreadsheet;
using log4net;
using log4net.Repository.Hierarchy;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace BLL
{
public class InvokePlugin
{
static Assembly assembly;
static Type type;
static object instantiation;
static bool isLoadok = false;
private ILog _log=null;
static Dictionary<string, MethodInfo> MethodInfos = new Dictionary<string, MethodInfo>();
public bool LoadDLL(string plugname, ILog log)
{
if (!isLoadok)
{
_log = log;
isLoadok = _LoadDLL(plugname);
}
return isLoadok;
}
private bool _LoadDLL(string plugname)
{
if (!File.Exists("Config\\" + plugname + ".dll"))
{
_log.Error($"LoadDLL 未找到{plugname}.DLL");
return false;
}
try
{
assembly = Assembly.LoadFrom("config\\" + plugname + ".dll");
}
catch (Exception e)
{
_log.Error("LoadDLL", e);
return false;
}
type = assembly.GetType("Plugin.Plugin");
if (type == null)
{
return false;
}
instantiation = Activator.CreateInstance(type);
_log.Info("LoadDLL success");
string[] methods = new string[] { "RequestServer" };
foreach (var meths in methods)
{
var method = type.GetMethod(meths);
if (method != null)
MethodInfos.Add(meths, method);
}
_log.Info("LoadDLL Method:" + string.Join(",", MethodInfos.Keys));
return true;
}
/// <summary>
/// 替换键值对 值的数据
/// </summary>
/// <param name="dic"></param>
/// <param name="httpmaeth">请求方式:0为httpget;1为httppost;2为soappost</param>
/// <returns></returns>
public Dictionary<string, string> RequestServer(Dictionary<string, string> dic,int httpmaeth)
{
if (!MethodInfos.ContainsKey("RequestServer"))
return null;
return (Dictionary<string, string>)MethodInfos["RequestServer"].Invoke(instantiation, new object[] { dic, httpmaeth });
}
}
}