Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
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);
 }