Example #1
0
        public void invokeASync(object oLiveObject, MethodInfo methodInfo, object[] methodParameters, Action <object> onMethodExecutionCompletion)
        {
            O2Kernel_O2Thread.mtaThread(
                () =>
            {
                try
                {
                    //var result = invoke(oLiveObject, methodInfo, methodParameters);
                    var result = methodInfo.Invoke(oLiveObject, methodParameters);
                    onMethodExecutionCompletion(result);
                }
                catch (Exception ex)
                {
                    //PublicDI.log.ex(ex, "in reflection.invokeASync", true);
                    PublicDI.log.error("in reflection.invokeASync: {0}", ex.Message);

                    var exceptionMessage = "Exception occured during invocation of method: " + methodInfo.Name;
                    exceptionMessage    += "      Exception.Message: " + ex.Message;
                    if (ex.InnerException != null)
                    {
                        exceptionMessage += "     InnerException.Message: " + ex.InnerException.Message;
                    }

                    onMethodExecutionCompletion(exceptionMessage);
                }
            });
        }
        public bool startHost()
        {
            try
            {
                O2Kernel_O2Thread.mtaThread(() =>
                {
                    using (var host = new ServiceHost(WcfImplementation))
                    {
                        host.AddServiceEndpoint(typeof(WcfInterface), WcfBinding, WcfBindingAddress);

                        //host.ChannelDispatchers[0].Listener.max

                        host.Open();
                        WCF_DI.log.info("Wcf Host has started on: {0}", WcfBindingAddress);
                        hostIsReady.Set();
                        terminateHost.WaitOne();
                        WCF_DI.log.info("terminateHost is set, so terminating thread with Wcf Host");
                        host.Close();
                        WCF_DI.log.info("Host Closed");
                        hostClosed.Set();
                    }
                });
                hostIsReady.WaitOne();
                return(true);
            }
            catch (Exception ex)
            {
                WCF_DI.log.ex(ex, "in O2GenericWcfHost.startHost");
                return(false);
            }
        }
Example #3
0
 public static void info(object _object)
 {
     O2Kernel_O2Thread.mtaThread(
         () =>
     {
         if (_object != null)
         {
             var propertyGrid = open.viewAscx("ascx_ShowInfo", _object.typeName(), 300, 300);
             propertyGrid.invoke("show", _object);
         }
     });
 }
        public void sendMessageSync(IO2Message messageToSend)
        {
            var messageSent = new AutoResetEvent(false);

            O2Kernel_O2Thread.mtaThread((() =>
            {
                var messageThread = sendMessage(messageToSend);
                messageThread.Join();
                messageSent.Set();
            }));
            messageSent.WaitOne();
        }
 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)
         {
             DI.log.error("in staticInvocation assembly was null : {0} {1}", assemblyToUse);
         }
         else
         {
             Type type = DI.reflection.getType(assembly, typeToLoad);
             if (type == null)
             {
                 DI.log.error("in staticInvocation type was null : {0} {1}", assembly, typeToLoad);
             }
             else
             {
                 MethodInfo method = DI.reflection.getMethod(type, methodToExecute, methodParams);
                 if (method == null)
                 {
                     DI.log.error("in staticInvocation method was null : {0} {1}", type, methodToExecute);
                 }
                 else
                 {
                     if (InvokeInStaThread)
                     {
                         O2Kernel_O2Thread.staThread(
                             () => DI.reflection.invoke(null, method, methodParams));
                     }
                     else if (InvokeInMtaThread)
                     {
                         O2Kernel_O2Thread.mtaThread(
                             () => DI.reflection.invoke(null, method, methodParams));
                     }
                     else
                     {
                         return(DI.reflection.invoke(null, method, methodParams));
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         DI.log.ex(ex, "in instanceInvocation");
     }
     return(null);
 }
Example #6
0
 public void invokeASync(MethodInfo methodInfo, Action <object> onMethodExecutionCompletion)
 {
     try
     {
         O2Kernel_O2Thread.mtaThread(
             () =>
         {
             var result = invokeMethod_Static(methodInfo);
             onMethodExecutionCompletion(result);
         });
     }
     catch (Exception ex)
     {
         //PublicDI.log.error(ex, "in reflection.invokeASync", true);
         PublicDI.log.error("in reflection.invokeASync: {0}", ex.Message);
     }
 }
        public object instanceInvocation(string assemblyToUse, string typeToLoad, string methodToExecute,
                                         object[] methodParams)
        {
            try
            {
                Assembly assembly = AppDomain.CurrentDomain.Load(assemblyToUse);
                if (assembly == null)
                {
                    DI.log.error("in instanceInvocation assembly was null : {0} {1}", assemblyToUse);
                }
                else
                {
                    Type type = DI.reflection.getType(assembly, typeToLoad);
                    if (type == null)
                    {
                        DI.log.error("in instanceInvocation type was null : {0} {1}", assembly, typeToLoad);
                    }
                    else
                    {
                        object typeObject = DI.reflection.createObject(assembly, type, methodParams);
                        if (typeObject == null)
                        {
                            DI.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 = DI.reflection.getMethod(type, methodToExecute, methodParams);
                            if (method == null)
                            {
                                DI.log.error("in instanceInvocation method was null : {0} {1}", type, methodToExecute);
                            }
                            else
                            {
                                if (InvokeInStaThread)
                                {
                                    return(O2Kernel_O2Thread.staThread(
                                               () => DI.reflection.invoke(typeObject, method, methodParams)));
                                }
                                if (InvokeInMtaThread)
                                {
                                    return(O2Kernel_O2Thread.mtaThread(
                                               () => DI.reflection.invoke(typeObject, method, methodParams)));
                                }

                                return(DI.reflection.invoke(typeObject, method, methodParams));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DI.log.ex(ex, "in instanceInvocation");
            }
            return(null);
        }