public static void Execute(DomainAdapter adapter, Action<object[]> callback, params object[] args) { if (adapter != null && callback != null) { adapter.Execute(callback, args); } }
public static AppDomain CreateDomain(string name, string path, bool iscache = false) { if (!path.EndsWith("\\")) { path += "\\"; } var domain = AppDomain.CreateDomain(name, AppDomain.CurrentDomain.Evidence, path, path, false); if (iscache) { cache[name] = new DomainAdapter(domain); } return domain; }
public static DomainAdapter Use(string name, string path = null, bool isreset = false) { if (cache.ContainsKey(name)) { var rlt = cache[name]; if (isreset) { rlt.Reset(); } return rlt; } if (path == null) { path = AppDomain.CurrentDomain.BaseDirectory; } var domain = CreateDomain(name, path); var adapter = new DomainAdapter(domain); cache[name] = adapter; return adapter; }
public static void Load(string dll, Action<Assembly> callback, DomainAdapter adapter = null) { if (!File.Exists(dll)) { log.e($"Unable to find dll: {dll}"); return; } if (adapter == null) { var dir = dll.PathWithoutFilename(); var name = dll.PathWithoutFilename(true); adapter = Use(name, dir); } Execute(adapter, (args) => { var func = (Action<Assembly>) args[0]; var file = (string)args[1]; var asm = Assembly.LoadFile(file); func(asm); }, callback, dll); }