Example #1
0
        object Invoke(ITransport transport, string methodName, bool isReturn, params object[] parameters)
        {
            ReflectInvokePacket packet = new ReflectInvokePacket();

            packet.state      = ReflectInvokePacket.State.Invoke;
            packet.methodName = methodName;
            packet.parameters = parameters;
            packet.randomID   = isReturn ? new Random().Next():-1;
            transport.Send(packet);
            if (isReturn)
            {
                waitingResultThreads.Add(packet.randomID, Thread.CurrentThread);
                try
                {
                    Thread.Sleep(100);
                }
                catch (Exception)
                {
                    ReflectInvokePacket returnPacket = returnValuePacketPool[packet.randomID];
                    returnValuePacketPool.Remove(returnPacket.randomID);
                    return(returnPacket.returnValue);
                }
            }
            return(null);
        }
Example #2
0
 internal void InvokeMethod(ITransport transport, ReflectInvokePacket packet)
 {
     if (packet.state == ReflectInvokePacket.State.Invoke)
     {
         try
         {
             MethodInfo method = invokedClass.GetMethod(packet.methodName);
             method.Invoke(null, packet.parameters);
             return;
         }
         catch (Exception)
         {
             SendError(transport, packet);
         }
     }
     else if (packet.state == ReflectInvokePacket.State.InvokeReturnMethod)
     {
         try
         {
             MethodInfo method      = invokedClass.GetMethod(packet.methodName);
             object     returnValue = method.Invoke(null, packet.parameters);
             packet.state       = ReflectInvokePacket.State.Return;
             packet.parameters  = null;
             packet.returnValue = returnValue;
             transport.Send(packet);
             return;
         }
         catch (Exception)
         {
             SendError(transport, packet);
         }
     }
 }
Example #3
0
 void SendError(ITransport transport, ReflectInvokePacket packet)
 {
     packet.state      = ReflectInvokePacket.State.NoMethodOrError;
     packet.parameters = null;
     transport.Send(packet);
 }