Beispiel #1
0
 public Thread invokeASync(MethodInfo methodInfo, Action <object> onMethodExecutionCompletion)
 {
     return(O2Thread.mtaThread(
                () =>
     {
         var result = invokeMethod_Static(methodInfo);
         onMethodExecutionCompletion(result);
     }));
 }
 public static Thread KillCurrentO2Process(int delayBeforeProcessKill)
 {
     return(O2Thread.mtaThread(() =>
     {
         Thread.Sleep(delayBeforeProcessKill);
         PublicDI.log.info("KillCurrentO2Process was invoked, so current process will be killed");
         Process.GetCurrentProcess().Kill();
     }));
 }
Beispiel #3
0
 public object staticInvocation(string assemblyToUse, string typeToLoad, string methodToExecute,
                                object[] methodParams)
 {
     try
     {
         //Assembly assembly = AppDomain.CurrentDomain.Load(assemblyToUse);
         var assembly = assemblyToUse.assembly();
         if (assembly == null)
         {
             PublicDI.log.error("in staticInvocation assembly was null : {0} {1}", assemblyToUse);
         }
         else
         {
             Type type = PublicDI.reflection.getType(assembly, typeToLoad);
             if (type == null)
             {
                 PublicDI.log.error("in staticInvocation type was null : {0} {1}", assembly, typeToLoad);
             }
             else
             {
                 MethodInfo method = PublicDI.reflection.getMethod(type, methodToExecute, methodParams);
                 if (method == null)
                 {
                     PublicDI.log.error("in staticInvocation method was null : {0} {1}", type, methodToExecute);
                 }
                 else
                 {
                     object returnValue = null;
                     if (InvokeInStaThread)
                     {
                         O2Thread.staThread(() =>
                         {
                             returnValue = PublicDI.reflection.invoke(null, method, methodParams);
                         }).Join();
                         return(returnValue);
                     }
                     if (InvokeInMtaThread)
                     {
                         O2Thread.mtaThread(() =>
                         {
                             returnValue = PublicDI.reflection.invoke(null, method, methodParams);
                         }).Join();
                         return(returnValue);
                     }
                     returnValue = PublicDI.reflection.invoke(null, method, methodParams);
                     return(returnValue);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         PublicDI.log.ex(ex, "in instanceInvocation");
     }
     return(null);
 }
Beispiel #4
0
        public static List <String> getListOfAllFilesFromDirectory(String sStartDirectory, bool bSearchRecursively, Action <List <String> > onComplete)
        {
            var lsFiles = new List <string>();

            O2Thread.mtaThread(
                () =>
            {
                getListOfAllFilesFromDirectory(lsFiles, sStartDirectory, bSearchRecursively, "*.*", false);
                onComplete(lsFiles);
            });
            return(lsFiles);
        }
Beispiel #5
0
 public static void nTimesWithDelay(int count, int delay, bool runInMtaThread, Action methodInvoker)
 {
     if (runInMtaThread)
     {
         O2Thread.mtaThread(() => nTimesWithDelay(count, delay, false, methodInvoker));
     }
     else
     {
         for (int i = 0; i < count; i++)
         {
             methodInvoker();
             Processes.Sleep(delay);
         }
     }
 }
Beispiel #6
0
        public void tryToFetchAssemblyFromO2GitHub(string assemblyToLoad, bool useCacheInfo)
        {
            string localFilePath = "";

            if (assemblyToLoad.contains("".tempDir()))       // don't try to fetch temp assemblies
            {
                return;
            }
            var thread  = O2Thread.mtaThread(() => downloadThread(assemblyToLoad, ref localFilePath, useCacheInfo));
            var maxWait = 60;

            if (thread.Join(maxWait * 1000) == false)
            {
                if (File.Exists(localFilePath))
                {
                    "TimeOut (of {1} secs) was reached, but Assembly was sucessfully fetched from O2GitHub: {0}".info(maxWait, localFilePath);
                }
                else
                {
                    "error while tring to fetchAssembly: {0} (max wait of {1} seconds reached)".error(assemblyToLoad, maxWait);
                }
            }
        }
Beispiel #7
0
 public object instanceInvocation(string assemblyToUse, string typeToLoad, string methodToExecute,
                                  object[] methodParams)
 {
     try
     {
         Assembly assembly = AppDomain.CurrentDomain.Load(assemblyToUse);
         if (assembly.isNull())
         {
             PublicDI.log.error("in instanceInvocation assembly was null : {0} {1}", assemblyToUse);
         }
         else
         {
             Type type = PublicDI.reflection.getType(assembly, typeToLoad);
             if (type == null)
             {
                 PublicDI.log.error("in instanceInvocation type was null : {0} {1}", assembly, typeToLoad);
             }
             else
             {
                 object typeObject = PublicDI.reflection.createObject(assembly, type, methodParams);
                 if (typeObject == null)
                 {
                     PublicDI.log.error("in dynamicInvocation typeObject was null : {0} {1}", assembly, type);
                 }
                 else
                 {
                     if (methodToExecute == "")
                     {
                         // means we don't want to execute a method (i.e we called the constructore) so just want the current proxy
                         return(typeObject);
                     }
                     MethodInfo method = PublicDI.reflection.getMethod(type, methodToExecute, methodParams);
                     if (method == null)
                     {
                         PublicDI.log.error("in instanceInvocation method was null : {0} {1}", type, methodToExecute);
                     }
                     else
                     {
                         object returnValue = null;
                         if (InvokeInStaThread)
                         {
                             O2Thread.staThread(() =>
                             {
                                 returnValue = PublicDI.reflection.invoke(typeObject, method, methodParams);
                             }).Join();
                             return(returnValue);
                         }
                         if (InvokeInMtaThread)
                         {
                             O2Thread.mtaThread(() =>
                             {
                                 returnValue = PublicDI.reflection.invoke(typeObject, method, methodParams);
                             }).Join();
                             return(returnValue);
                         }
                         return(PublicDI.reflection.invoke(typeObject, method, methodParams));
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         PublicDI.log.ex(ex, "in instanceInvocation");
     }
     return(null);
 }