private void AsyncInvokeMethod(MethodInfo method, IModule module, object[] parameters, ModuleCallReturnFunction ReturnFunction) { if (ReturnFunction == null) { Log.Trace("Calling async invoke method in module with no return call"); ReturnFunction = new ModuleCallReturnFunction(NoReturnCall); } object ret = null; if (method.ReturnType.ToString().ToLower() == "void") { Log.Trace("Invoking module method with no return"); method.Invoke(module, parameters); } else { Log.Trace("Invoking module method and collecting return value"); ret = method.Invoke(module, parameters); } Log.Trace("Invoking the return function after the async call"); ReturnFunction.Invoke(ret); }
public void InvokeModuleMethodAsync(string ModuleName, string FunctionName, NameValuePair[] variables, ModuleCallReturnFunction ReturnFunction, bool throwOnError) { object tmp; _InvokeModuleMethod(ModuleName, FunctionName, variables, ReturnFunction, true, throwOnError, out tmp); }
private void _InvokeModuleMethod(string ModuleName, string FunctionName, NameValuePair[] variables, ModuleCallReturnFunction ReturnFunction, bool async, bool throwOnError, out object returnValue) { returnValue = null; Log.Trace("Attempting to invoke method " + FunctionName + " in Module " + ModuleName); bool found = false; foreach (IModule module in _modules) { if (module.ModuleName == ModuleName) { found = true; Log.Trace("Located module " + ModuleName + " in attempt to invoke method"); MethodInfo method = null; object[] parameters = new object[0]; if (variables == null) { Log.Trace("Attempting to locate method " + FunctionName + " in module " + ModuleName + " without any parameters"); method = module.GetType().GetMethod(FunctionName, Type.EmptyTypes); } else { foreach (MethodInfo mi in module.GetType().GetMethods()) { if (mi.Name == FunctionName) { bool contains = true; Log.Trace("Located method " + mi.ToString() + " in module " + ModuleName + ", checking to see if variables were passed."); foreach (ParameterInfo pi in mi.GetParameters()) { bool found_var = false; foreach (NameValuePair nvp in variables) { if (nvp.Name == pi.Name) { found_var = true; break; } } if (!found_var) { contains = false; break; } } if ((contains) && (mi.GetParameters().Length == variables.Length)) { Log.Trace("Located proper method in module invoke using parameters supplied"); method = mi; Log.Trace("Constructing parameter list for module " + ModuleName + " method " + FunctionName); parameters = new object[variables.Length]; int x = 0; foreach (ParameterInfo p in mi.GetParameters()) { foreach (NameValuePair nvp in variables) { if (nvp.Name == p.Name) { parameters[x] = nvp.Value; break; } } x++; } break; } } } } if (method == null) { Log.Error(new ModuleFunctionNotFoundException(ModuleName, FunctionName)); if (throwOnError) { throw new ModuleFunctionNotFoundException(ModuleName, FunctionName); } else { return; } } else { try { if (!async && ReturnFunction == null) { if (method.ReturnType.ToString().ToLower() == "void") { Log.Trace("Invoking module method with no return"); method.Invoke(module, parameters); } else { Log.Trace("Invoking module method and collecting return value"); returnValue = method.Invoke(module, parameters); } } else { InvokeModuleCallFunction asyncCall = new InvokeModuleCallFunction(AsyncInvokeMethod); if (async) { Log.Trace("Attempting to invoke " + FunctionName + " in module " + ModuleName + " asynchronously."); asyncCall.BeginInvoke(method, module, parameters, ReturnFunction, new AsyncCallback(AsyncInvokeMethodComplete), null); } else { Log.Trace("Attempting to invoke " + FunctionName + " in module " + ModuleName + " synchronously."); asyncCall.Invoke(method, module, parameters, ReturnFunction); } } } catch (Exception e) { Log.Error(e); if (throwOnError) { throw new ModuleFunctionCallException(e, ModuleName, FunctionName); } else { return; } } } } } if (!found) { Log.Error(new ModuleNotFoundException(ModuleName)); if (throwOnError) { throw new ModuleNotFoundException(ModuleName); } } }
public void InvokeModuleMethodAsync(string ModuleName, string FunctionName, NameValuePair[] variables, ModuleCallReturnFunction ReturnFunction) { Log.Trace("Calling invoke module method. Module: " + ModuleName + ", function: " + FunctionName + " parameter count: " + variables.Length.ToString() + " asynchronously width return function " + ReturnFunction.ToString()); InvokeModuleMethodAsync(ModuleName, FunctionName, variables, ReturnFunction, true); }
public void InvokeModuleMethodAsync(string ModuleName, string FunctionName, ModuleCallReturnFunction ReturnFunction, bool throwOnError) { Log.Trace("Calling invoke module method. Module: " + ModuleName + ", function: " + FunctionName + " with no parameters asynchronously"); InvokeModuleMethodAsync(ModuleName, FunctionName, null, ReturnFunction, throwOnError); }
private void AsyncInvokeMethod(MethodInfo method,IModule module,object[] parameters, ModuleCallReturnFunction ReturnFunction) { if (ReturnFunction == null) { Log.Trace("Calling async invoke method in module with no return call"); ReturnFunction = new ModuleCallReturnFunction(NoReturnCall); } object ret = null; if (method.ReturnType.ToString().ToLower() == "void") { Log.Trace("Invoking module method with no return"); method.Invoke(module, parameters); } else { Log.Trace("Invoking module method and collecting return value"); ret = method.Invoke(module, parameters); } Log.Trace("Invoking the return function after the async call"); ReturnFunction.Invoke(ret); }
private void _InvokeModuleMethod(string ModuleName,string FunctionName,NameValuePair[] variables,ModuleCallReturnFunction ReturnFunction,bool async,bool throwOnError,out object returnValue) { returnValue = null; Log.Trace("Attempting to invoke method " + FunctionName + " in Module " + ModuleName); bool found = false; foreach (IModule module in _modules) { if (module.ModuleName == ModuleName) { found = true; Log.Trace("Located module " + ModuleName+" in attempt to invoke method"); MethodInfo method = null; object[] parameters = new object[0]; if (variables == null) { Log.Trace("Attempting to locate method " + FunctionName + " in module " + ModuleName + " without any parameters"); method = module.GetType().GetMethod(FunctionName, Type.EmptyTypes); } else { foreach (MethodInfo mi in module.GetType().GetMethods()){ if (mi.Name == FunctionName) { bool contains = true; Log.Trace("Located method " + mi.ToString() + " in module " + ModuleName + ", checking to see if variables were passed."); foreach (ParameterInfo pi in mi.GetParameters()) { bool found_var = false; foreach (NameValuePair nvp in variables) { if (nvp.Name == pi.Name) { found_var = true; break; } } if (!found_var) { contains = false; break; } } if ((contains)&&(mi.GetParameters().Length==variables.Length)) { Log.Trace("Located proper method in module invoke using parameters supplied"); method = mi; Log.Trace("Constructing parameter list for module " + ModuleName + " method " + FunctionName); parameters = new object[variables.Length]; int x = 0; foreach (ParameterInfo p in mi.GetParameters()) { foreach (NameValuePair nvp in variables) { if (nvp.Name == p.Name) { parameters[x] = nvp.Value; break; } } x++; } break; } } } } if (method == null) { Log.Error(new ModuleFunctionNotFoundException(ModuleName, FunctionName)); if (throwOnError) throw new ModuleFunctionNotFoundException(ModuleName, FunctionName); else return; } else { try { if (!async && ReturnFunction == null) { if (method.ReturnType.ToString().ToLower() == "void") { Log.Trace("Invoking module method with no return"); method.Invoke(module, parameters); } else { Log.Trace("Invoking module method and collecting return value"); returnValue = method.Invoke(module, parameters); } } else { InvokeModuleCallFunction asyncCall = new InvokeModuleCallFunction(AsyncInvokeMethod); if (async) { Log.Trace("Attempting to invoke " + FunctionName + " in module " + ModuleName + " asynchronously."); asyncCall.BeginInvoke(method, module, parameters, ReturnFunction, new AsyncCallback(AsyncInvokeMethodComplete), null); } else { Log.Trace("Attempting to invoke " + FunctionName + " in module " + ModuleName + " synchronously."); asyncCall.Invoke(method, module, parameters, ReturnFunction); } } } catch (Exception e) { Log.Error(e); if (throwOnError) throw new ModuleFunctionCallException(e, ModuleName, FunctionName); else return; } } } } if (!found) { Log.Error(new ModuleNotFoundException(ModuleName)); if (throwOnError) throw new ModuleNotFoundException(ModuleName); } }
public void InvokeModuleMethodAsync(string ModuleName, string FunctionName, NameValuePair[] variables, ModuleCallReturnFunction ReturnFunction, bool throwOnError) { object tmp; _InvokeModuleMethod(ModuleName, FunctionName, variables, ReturnFunction, true, throwOnError, out tmp); }
public void InvokeModuleMethodAsync(string ModuleName, string FunctionName, ModuleCallReturnFunction ReturnFunction,bool throwOnError) { Log.Trace("Calling invoke module method. Module: " + ModuleName + ", function: " + FunctionName + " with no parameters asynchronously"); InvokeModuleMethodAsync(ModuleName, FunctionName, null, ReturnFunction, throwOnError); }
public void InvokeModuleMethodAsync(string ModuleName, string FunctionName, NameValuePair[] variables, ModuleCallReturnFunction ReturnFunction) { Log.Trace("Calling invoke module method. Module: " + ModuleName + ", function: " + FunctionName + " parameter count: " + variables.Length.ToString() + " asynchronously width return function "+ReturnFunction.ToString()); InvokeModuleMethodAsync(ModuleName, FunctionName, variables, ReturnFunction,true); }