cowdude
Active Member
- Joined
- Feb 17, 2010
- Messages
- 337
Hi,
I am currently working on a small http server plugin (=> using threads) for HB and had some trouble detecting when the user forced a re-compilation of its plugins. I tried to use a class deconstructor which did not work at all, hence I coded a small and dirty class as a workaround.
Why would it be great to be able to hook it or implement class destruction ?
That won't work at all, and there is no OnRecompile delegate as far as I know... Because of this, you'll have many onBotStart/onBotStop callbacks registered that will be ALL called when the bot is starting or stopping if you recompiled your plugins....
Anyway, here is my (awful) workaround:
I am currently working on a small http server plugin (=> using threads) for HB and had some trouble detecting when the user forced a re-compilation of its plugins. I tried to use a class deconstructor which did not work at all, hence I coded a small and dirty class as a workaround.
Why would it be great to be able to hook it or implement class destruction ?
Code:
class Foo : HBPlugin {
public Foo () {
Styx.FiniteStateMachine.Engine.OnEngineStart += onBotStart;
Styx.FiniteStateMachine.Engine.OnEngineStop += onBotStop;
}
~Foo {
Styx.FiniteStateMachine.Engine.OnEngineStart -= onBotStart;
Styx.FiniteStateMachine.Engine.OnEngineStop -= onBotStop;
}
}
That won't work at all, and there is no OnRecompile delegate as far as I know... Because of this, you'll have many onBotStart/onBotStop callbacks registered that will be ALL called when the bot is starting or stopping if you recompiled your plugins....
Anyway, here is my (awful) workaround:
Code:
class RecompileHelper
{
public delegate void Callback();
Callback callback;
string hook = null;
public RecompileHelper(string h, Callback cb)
{
hook = h;
callback = cb;
Logging.Write(hook);
Logging.OnWrite += ReadLog;
}
void ReadLog(string line, System.Drawing.Color c)
{
if (line == hook)
{
Logging.OnWrite -= ReadLog;
Logging.Write("Recompile detected.");
callback();
}
}
}
public class Foo : HBPlugin {
...
public Foo () {
Styx.FiniteStateMachine.Engine.OnEngineStart += onBotStart;
Styx.FiniteStateMachine.Engine.OnEngineStop += onBotStop;
recompileHelper = new RecompileHelper("My Foo plugin is launching.", Cleaner);
}
void Cleaner () {
Styx.FiniteStateMachine.Engine.OnEngineStart -= onBotStart;
Styx.FiniteStateMachine.Engine.OnEngineStop -= onBotStop;
}
}