bool LoadLibrary()
{
string path = config[CONF_APPLICATION_LIBRARY];
try
{
//appDomain = AppDomain.CreateDomain(path);
var scripts = Directory.GetFiles(config[CONF_APPLICATION_DIRECTORY], "*.cs");
if (scripts.Count() == 0)
{
libHandler = Assembly.LoadFrom(path);
}
else
{
var cr = objCSharpCodePrivoder.CompileAssemblyFromFile(objCompilerParameters, scripts);
if (!cr.Errors.HasErrors)
{
libHandler = cr.CompiledAssembly;
}
else
{
string strErrorMsg = cr.Errors.Count + " Errors:";
for (int x = 0; x < cr.Errors.Count; x++)
{
strErrorMsg = strErrorMsg + "/r/nLine: " +
cr.Errors[x].Line + " - " +
cr.Errors[x].ErrorText;
}
WARN(strErrorMsg);
libHandler = Assembly.LoadFrom(path);
}
}
//appDomain.Load(libHandler.GetName());
}
catch (Exception ex)
{
FATAL("Unable to open library {0} Error was: {1}",path,ex.Message);
return false;
}
string functionName = config[CONF_APPLICATION_INIT_FACTORY_FUNCTION];
var appType = libHandler.GetTypes().SingleOrDefault(y => y.BaseType == typeof (BaseClientApplication));
if (appType == null)
{
FATAL("Unable to find class {0}", functionName);
return false;
}
getApplication = x => (BaseClientApplication)Activator.CreateInstance(appType, new object[] { x });
//functionName = config[Defines.CONF_APPLICATION_INIT_FACTORY_FUNCTION];
var factory = libHandler.GetTypes().SingleOrDefault(x => x.BaseType == typeof(BaseProtocolFactory));
if(factory!=null)
getFactory = x => (BaseProtocolFactory)Activator.CreateInstance(factory, x);
INFO("Module {0} loaded",path);
return true;
}