public void BinaryInput(byte[] data) { ReadBytes read = new ReadBytes(data); int lengt; int cmd; if (read.ReadInt32(out lengt) && read.Length == lengt && read.ReadInt32(out cmd)) { switch (cmd) { case 1001001: { Result_Have_Return val; if (read.ReadObject <Result_Have_Return>(out val)) { RPC_Call.SetReturnValue(val); } } break; case 1001000: { ThreadPool.QueueUserWorkItem((o) => { RPCCallPack tmp; ReadBytes pread = (ReadBytes)o; if (pread.ReadObject <RPCCallPack>(out tmp)) { object returnValue; try { if (RPC_Call.RunModule(tmp, tmp.NeedReturn, out returnValue)) { if (tmp.NeedReturn) { Result_Have_Return var = new Result_Have_Return() { Id = tmp.Id, Arguments = tmp.Arguments }; if (returnValue != null) { var.Return = Serialization.PackSingleObject(returnValue.GetType(), returnValue); } Client.BeginSendData(BufferFormat.FormatFCA(var)); } } } catch (Exception er) { LogAction.Err(er.ToString()); } } }, read); } break; default: { if (DataOn != null) { DataOn(cmd, read); } } break; } } }
public object CallMethod(string tag, string methodName, Type[] argTypelist, List <byte[]> arglist, out object[] args, Type returnType) { args = null; RPCCallPack call = new RPCCallPack() { Tag = tag, Method = methodName, Arguments = arglist, NeedReturn = true }; WaitReturnValue var = new WaitReturnValue(); lock (ReturnValueDiy) { call.Id = Make.GetID(); ReturnValueDiy.Add(call.Id, var); } byte[] data = BufferFormat.FormatFCA(call); if (CallBufferOutSend != null) { CallBufferOutSend(data); } if (var.waitHandle.WaitOne(OutTime)) { Result_Have_Return returnx = var.returnvalue; if (returnx.Arguments != null && returnx.Arguments.Count > 0 && arglist.Count == returnx.Arguments.Count) { args = new object[returnx.Arguments.Count]; for (int i = 0; i < argTypelist.Length; i++) { args[i] = Serialization.UnpackSingleObject(argTypelist[i], returnx.Arguments[i]); } } if (returnx.Return != null) { object returnobj = Serialization.UnpackSingleObject(returnType, returnx.Return); return(returnobj); } else { return(null); } } else { lock (ReturnValueDiy) { ReturnValueDiy.Remove(call.Id); } LogAction.Warn(tag + "->" + methodName + " out time,Please set the timeout time."); return(null); } }