/// <summary> /// Calls a Method/Function from the <see cref="Assemblies"/> /// </summary> /// <param name="MethodName">The searched Method/Function name</param> /// <param name="Arguments">an <see cref="object[]"/> Array which represents the Arguments</param> /// <param name="Silent">no Error Output?</param> public static bool CallMethod(string MethodName, object[] Arguments, bool Silent) { Assembly Assembly = null; List <MethodInfo> invokeList = new List <MethodInfo>(); string NamespaceName = Namespace; // Any assembly to call from? if (Assemblies == null || Assemblies.Length < 1) { return(false); } // Search for the exact name // TODO: we need some sort of cache, maybe dictionary to call directly without searching for (int i = 0; i < Assemblies.Length; i++) { if ((Assembly = Assemblies[i]) == null) { continue; } Type[] types = Assembly.GetTypes(); for (int t = 0; t < types.Length; t++) { // We only search in scripting namespace if (types[t].Namespace.StartsWith(NamespaceName) == false) { continue; } try { // Search a puplic and static method MethodInfo info = types[t].GetMethod(MethodName, BindingFlags.Static | BindingFlags.Public); if (info != null) { invokeList.Add(info); } } catch { } } } // Found some? Sort them by call priority (custom attribute) if (invokeList.Count > 0) { invokeList.Sort(new CallPriorityComparer()); } else { if (Silent == false) { ServerConsole.ErrorLine("CallMethod \"{0}.{1}\" failed! Method was not found in {2} Assemblies!", NamespaceName, MethodName, Assemblies.Length); } return(false); } for (int i = 0; i < invokeList.Count; i++) { ParameterInfo[] args = invokeList[i].GetParameters(); MethodInvokeHelper inv = new MethodInvokeHelper(invokeList[i]); // Dynamic fill all arguments // Note: if more arguments need then given, null will be used if (args != null && args.Length > 0) { inv.MethodArguments = FillArgList(args, Arguments); } // Start a thread for every execution // TODO: we need some sort of logic here! // if we execute this for 100 player @ a time, 100 threads are running // might by slow and unstable.. Thread thread = new Thread(new ThreadStart(inv.Invoke)); thread.Name = inv.MethodInfo.Name; thread.Start(); } // Garbage invokeList.Clear(); return(true); }
/// <summary> /// Calls a Method/Function from the <see cref="Assemblies"/> /// </summary> /// <param name="MethodName">The searched Method/Function name</param> /// <param name="Arguments">an <see cref="object[]"/> Array which represents the Arguments</param> /// <param name="Silent">no Error Output?</param> public static bool CallMethod(string MethodName, object[] Arguments, bool Silent) { Assembly Assembly = null; List<MethodInfo> invokeList = new List<MethodInfo>(); string NamespaceName = Namespace; // Any assembly to call from? if (Assemblies == null || Assemblies.Length < 1) { return false; } // Search for the exact name // TODO: we need some sort of cache, maybe dictionary to call directly without searching for (int i = 0; i < Assemblies.Length; i++) { if ((Assembly = Assemblies[i]) == null) { continue; } Type[] types = Assembly.GetTypes(); for (int t = 0; t < types.Length; t++) { // We only search in scripting namespace if (types[t].Namespace.StartsWith(NamespaceName) == false) { continue; } try { // Search a puplic and static method MethodInfo info = types[t].GetMethod(MethodName, BindingFlags.Static | BindingFlags.Public); if (info != null) invokeList.Add(info); } catch { } } } // Found some? Sort them by call priority (custom attribute) if (invokeList.Count > 0) { invokeList.Sort(new CallPriorityComparer()); } else { if (Silent == false) { ServerConsole.ErrorLine("CallMethod \"{0}.{1}\" failed! Method was not found in {2} Assemblies!", NamespaceName, MethodName, Assemblies.Length); } return false; } for (int i = 0; i < invokeList.Count; i++) { ParameterInfo[] args = invokeList[i].GetParameters(); MethodInvokeHelper inv = new MethodInvokeHelper(invokeList[i]); // Dynamic fill all arguments // Note: if more arguments need then given, null will be used if (args != null && args.Length > 0) { inv.MethodArguments = FillArgList(args, Arguments); } // Start a thread for every execution // TODO: we need some sort of logic here! // if we execute this for 100 player @ a time, 100 threads are running // might by slow and unstable.. Thread thread = new Thread(new ThreadStart(inv.Invoke)); thread.Name = inv.MethodInfo.Name; thread.Start(); } // Garbage invokeList.Clear(); return true; }
/// <summary> /// Calls a method on each registered <see cref="CompiledAssemblies" /> entry /// </summary> /// <param name="methodName">The searched Method/Function name</param> /// <param name="arguments">an <see cref="object" /> Array which represents the Arguments</param> /// <param name="silent">no Error Output?</param> public bool CallMethod(string methodName, object[] arguments = null, bool silent = true) { var invokeList = new List<MethodInfo>(); var namespaceName = Namespace; // Any assembly to call from? if (CompiledAssemblies == null || CompiledAssemblies.Count < 1) { return false; } // Search for the exact name // @TODO: We need some sort of cache, maybe dictionary to call directly without searching foreach (var assembly in CompiledAssemblies) { if (assembly == null) { continue; } // Catch only types in my namespace? var types = assembly.GetTypes().Where(type => string.IsNullOrEmpty(type.Namespace) == false); if (string.IsNullOrEmpty(namespaceName) == false) { // ReSharper disable once PossibleNullReferenceException types = types.Where(type => type.Namespace.StartsWith(namespaceName)); } foreach (var type in types) { try { // Search a puplic and static method var info = type.GetMethod(methodName, BindingFlags.Static | BindingFlags.Public); if (info != null) { invokeList.Add(info); } } catch { } } } // Found something? if (invokeList.Count == 0) { if (silent == false) { var exMessage = string.Format("CallMethod \"{0}.{1}\" failed! Method was not found in {2} Assemblies!", namespaceName, methodName, CompiledAssemblies.Count); throw new NoAssemblyFoundException(exMessage); } return false; } // Sort by call priority (custom attribute) invokeList.Sort(new CallPriorityComparer()); foreach (var methodInfo in invokeList) { var args = methodInfo.GetParameters(); var inv = new MethodInvokeHelper(methodInfo); // Dynamic fill all arguments // Note: If more arguments needed then given, null will be used if (args.Length > 0) { inv.MethodArguments = FillArgList(args, arguments); } // Start a thread for every execution // @TODO: We need some sort of logic here! // If we execute this for 100 player at a time, 100 threads are running - might by slow and unstable.. var thread = new Thread(inv.Invoke) { Name = inv.MethodInfo.Name }; thread.Start(); } // Garbage invokeList.Clear(); return true; }
/// <summary> /// Calls a Method/Function from the <see cref="Assemblies"/> /// </summary> /// <param name="MethodName">The searched Method/Function name</param> /// <param name="Arguments">an <see cref="object[]"/> Array which represents the Arguments</param> /// <param name="Silent">no Error Output?</param> public static bool CallMethod(string MethodName, object[] Arguments, bool Silent) { Assembly Assembly = null; List <MethodInfo> invokeList = new List <MethodInfo>(); string NamespaceName = "Shaiya.Extended.Server.Scripting"; if (Assemblies == null || Assemblies.Length < 1) { return(false); } for (int i = 0; i < Assemblies.Length; i++) { if ((Assembly = Assemblies[i]) == null) { continue; } Type[] types = Assembly.GetTypes(); for (int t = 0; t < types.Length; t++) { if (types[t].Namespace != NamespaceName) { continue; } try { MethodInfo info = types[t].GetMethod(MethodName, BindingFlags.Static | BindingFlags.Public); if (info != null) { invokeList.Add(info); } } catch { } } } if (invokeList.Count > 0) { invokeList.Sort(new CallPriorityComparer()); } else { if (Silent == false) { CConsole.ErrorLine("CallMethod \"{0}.{1}\" failed! Method was not found in {2} Assemblies!", NamespaceName, MethodName, Assemblies.Length); } return(false); } for (int i = 0; i < invokeList.Count; i++) { ParameterInfo[] args = invokeList[i].GetParameters(); MethodInvokeHelper inv = new MethodInvokeHelper(invokeList[i]); if (args.Length > 0) { inv.MethodArguments = FillArgList(args, Arguments); } Thread thread = new Thread(new ThreadStart(inv.Invoke)); thread.Name = inv.MethodInfo.Name; thread.Start(); } invokeList.Clear(); return(true); }
/// <summary> /// Calls a Method/Function from the <see cref="Assemblies"/> /// </summary> /// <param name="MethodName">The searched Method/Function name</param> /// <param name="Arguments">an <see cref="object[]"/> Array which represents the Arguments</param> /// <param name="Silent">no Error Output?</param> public static bool CallMethod( string MethodName, object[] Arguments, bool Silent ) { Assembly Assembly = null; List<MethodInfo> invokeList = new List<MethodInfo>(); string NamespaceName = "Shaiya.Extended.Server.Scripting"; if( Assemblies == null || Assemblies.Length < 1 ) return false; for( int i = 0; i < Assemblies.Length; i++ ) { if( ( Assembly = Assemblies[ i ] ) == null ) continue; Type[] types = Assembly.GetTypes(); for( int t = 0; t < types.Length; t++ ) { if( types[ t ].Namespace != NamespaceName ) continue; try { MethodInfo info = types[ t ].GetMethod( MethodName, BindingFlags.Static | BindingFlags.Public ); if( info != null ) invokeList.Add( info ); } catch { } } } if( invokeList.Count > 0 ) invokeList.Sort( new CallPriorityComparer() ); else { if( Silent == false ) CConsole.ErrorLine( "CallMethod \"{0}.{1}\" failed! Method was not found in {2} Assemblies!", NamespaceName, MethodName, Assemblies.Length ); return false; } for( int i = 0; i < invokeList.Count; i++ ) { ParameterInfo[] args = invokeList[ i ].GetParameters(); MethodInvokeHelper inv = new MethodInvokeHelper( invokeList[ i ] ); if( args.Length > 0 ) inv.MethodArguments = FillArgList( args, Arguments ); Thread thread = new Thread( new ThreadStart( inv.Invoke ) ); thread.Name = inv.MethodInfo.Name; thread.Start(); } invokeList.Clear(); return true; }
/// <summary> /// Calls a method on each registered <see cref="CompiledAssemblies" /> entry /// </summary> /// <param name="methodName">The searched Method/Function name</param> /// <param name="arguments">an <see cref="object" /> Array which represents the Arguments</param> /// <param name="silent">no Error Output?</param> public bool CallMethod(string methodName, object[] arguments = null, bool silent = true) { var invokeList = new List <MethodInfo>(); var namespaceName = Namespace; // Any assembly to call from? if (CompiledAssemblies == null || CompiledAssemblies.Count < 1) { return(false); } // Search for the exact name // @TODO: We need some sort of cache, maybe dictionary to call directly without searching foreach (var assembly in CompiledAssemblies) { if (assembly == null) { continue; } // Catch only types in my namespace? var types = assembly.GetTypes().Where(type => string.IsNullOrEmpty(type.Namespace) == false); if (string.IsNullOrEmpty(namespaceName) == false) { // ReSharper disable once PossibleNullReferenceException types = types.Where(type => type.Namespace.StartsWith(namespaceName)); } foreach (var type in types) { try { // Search a puplic and static method var info = type.GetMethod(methodName, BindingFlags.Static | BindingFlags.Public); if (info != null) { invokeList.Add(info); } } catch { } } } // Found something? if (invokeList.Count == 0) { if (silent == false) { var exMessage = string.Format("CallMethod \"{0}.{1}\" failed! Method was not found in {2} Assemblies!", namespaceName, methodName, CompiledAssemblies.Count); throw new NoAssemblyFoundException(exMessage); } return(false); } // Sort by call priority (custom attribute) invokeList.Sort(new CallPriorityComparer()); foreach (var methodInfo in invokeList) { var args = methodInfo.GetParameters(); var inv = new MethodInvokeHelper(methodInfo); // Dynamic fill all arguments // Note: If more arguments needed then given, null will be used if (args.Length > 0) { inv.MethodArguments = FillArgList(args, arguments); } // Start a thread for every execution // @TODO: We need some sort of logic here! // If we execute this for 100 player at a time, 100 threads are running - might by slow and unstable.. var thread = new Thread(inv.Invoke) { Name = inv.MethodInfo.Name }; thread.Start(); } // Garbage invokeList.Clear(); return(true); }