70 lines
1.3 KiB
C#
70 lines
1.3 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using sharp.tradebot;
|
|
|
|
namespace TradeBot
|
|
{
|
|
public class BotSpecification : MarshalByRefObject
|
|
{
|
|
public string DllPath { get; private set; }
|
|
public string ClassName { get; private set; }
|
|
public object[] Arguments { get; private set; }
|
|
|
|
public string BotSpec { get { return string.Format("{0}:{1}",ClassName,DllPath); } }
|
|
|
|
public bool IsLoaded
|
|
{
|
|
get
|
|
{
|
|
return currentInstance != null;
|
|
}
|
|
}
|
|
public TradingBot CurrentInstance
|
|
{
|
|
get {
|
|
return this.currentInstance;
|
|
}
|
|
}
|
|
|
|
AppDomain Domain;
|
|
Assembly Assembly;
|
|
Type ClassType;
|
|
|
|
TradingBot currentInstance;
|
|
|
|
public BotSpecification(string dllpath,string className,object[] arguments)
|
|
{
|
|
DllPath = dllpath;
|
|
ClassName = className;
|
|
}
|
|
|
|
public void Unload(){
|
|
currentInstance = null;
|
|
ClassType = null;
|
|
Assembly = null;
|
|
AppDomain.Unload(Domain);
|
|
Domain = null;
|
|
}
|
|
public void Load(){
|
|
if (Domain != null){
|
|
Unload();
|
|
}
|
|
|
|
Domain = AppDomain.CreateDomain(DllPath);
|
|
Assembly = Domain.Load(DllPath);
|
|
ClassType = Assembly.GetType(ClassName);
|
|
}
|
|
|
|
TradingBot TradingBot {
|
|
get
|
|
{
|
|
if (currentInstance == null){
|
|
currentInstance = (TradingBot)Activator.CreateInstance(ClassType);
|
|
}
|
|
return currentInstance;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|