public static Primitive CallAsync(Primitive dll, Primitive extension, Primitive obj, Primitive method, Primitive arguments)
{
try
{
Type type;
string callName = "";
if (dll == "" && extension == "" && obj == "" && arguments == "")
{
type = mainModule;
}
else
{
string path = Path.GetDirectoryName(entryAssembly.Location) + "\\" + dll;
if (!System.IO.File.Exists(path)) return dll + " dll not found";
Assembly assembly = Assembly.LoadFrom(path);
type = assembly.GetType(extension + "." + obj, false, true);
if (null == type) return extension + "." + obj + " extension not found";
callName += extension + "." + obj + ".";
}
MethodInfo methodInfo = type.GetMethod((string)method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
if (null == methodInfo) return method + " method not found";
int numArgs = 0;
Object[] args = null;
callName += method + "(";
if (SBArray.IsArray(arguments))
{
numArgs = SBArray.GetItemCount(arguments);
args = new Object[numArgs];
Primitive indices = SBArray.GetAllIndices(arguments);
for (int i = 1; i <= numArgs; i++)
{
args[i - 1] = arguments[indices[i]];
callName += arguments[indices[i]];
if (i < numArgs) callName += ",";
}
}
else if (arguments != "")
{
args = new Object[1] { arguments };
callName += arguments;
}
callName += ")";
Thread thread = new Thread(new ParameterizedThreadStart(DoCall));
thread.Start(new Object[] { methodInfo, args, callName });
//while (!thread.IsAlive) Thread.Sleep(1); //delay to let async call get started
return "PENDING";
}
catch (Exception ex)
{
Utilities.OnError(Utilities.GetCurrentMethod(), ex);
return ex.Message;
}
}