public void Unload() { try { if (status == PluginStatus.Active) { mainBot.CommandManager.UnregisterPlugin(this); } if (proxy != null) { proxy.Stop(); } if (domain != null) { AppDomain.Unload(domain); } } finally { proxy = null; domain = null; status = PluginStatus.Off; } }
public PluginResponse Prepare() { try { if (file.Extension != ".cs" && file.Extension != ".dll" && file.Extension != ".exe") { return(PluginResponse.UnsupportedFile); } //todo test shadowcopying domain = AppDomain.CreateDomain( "Plugin_" + file.Name, AppDomain.CurrentDomain.Evidence, new AppDomainSetup { ApplicationBase = ts3File.Directory.FullName, PrivateBinPath = "Plugin/..;Plugin", PrivateBinPathProbe = "" }); domain.UnhandledException += (s, e) => Unload(); proxy = (PluginProxy)domain.CreateInstanceAndUnwrap( proxType.Assembly.FullName, proxType.FullName); PluginResponse result; if (file.Extension == ".cs") { result = PrepareSource(); } else if (file.Extension == ".dll" || file.Extension == ".exe") { result = proxy.LoadAssembly(domain, file); } else { throw new InvalidProgramException(); } if (result == PluginResponse.Ok) { status = PluginStatus.Ready; } return(result); } catch (Exception ex) { Log.Write(Log.Level.Warning, "Possible plugin failed to load: ", ex); return(PluginResponse.Crash); } }
public WrappedCommand(int invNum, PluginProxy wrapParent, CommandBuildInfo data) : base(data) { proxy = wrapParent; mId = invNum; }
public void Unload() { try { if (status == PluginStatus.Active) mainBot.CommandManager.UnregisterPlugin(this); if (proxy != null) proxy.Stop(); if (domain != null) AppDomain.Unload(domain); } finally { proxy = null; domain = null; status = PluginStatus.Off; } }
public PluginResponse Prepare() { try { if (file.Extension != ".cs" && file.Extension != ".dll" && file.Extension != ".exe") return PluginResponse.UnsupportedFile; //todo test shadowcopying domain = AppDomain.CreateDomain( "Plugin_" + file.Name, AppDomain.CurrentDomain.Evidence, new AppDomainSetup { ApplicationBase = ts3File.Directory.FullName, PrivateBinPath = "Plugin/..;Plugin", PrivateBinPathProbe = "" }); domain.UnhandledException += (s, e) => Unload(); proxy = (PluginProxy)domain.CreateInstanceAndUnwrap( proxType.Assembly.FullName, proxType.FullName); PluginResponse result; if (file.Extension == ".cs") result = PrepareSource(); else if (file.Extension == ".dll" || file.Extension == ".exe") result = proxy.LoadAssembly(domain, file); else throw new InvalidProgramException(); if (result == PluginResponse.Ok) status = PluginStatus.Ready; return result; } catch (Exception ex) { Log.Write(Log.Level.Warning, "Possible plugin failed to load: ", ex); return PluginResponse.Crash; } }