private void CallPackRun(CallPack pack) { if (Module.ModuleDiy.ContainsKey(pack.CmdTag)) { IAsyncMethodDef method = Module.ModuleDiy[pack.CmdTag]; object[] args = null; int argcount = 0; if (pack.Arguments != null) { argcount = pack.Arguments.Count; } if (!method.IsNotRefAsyncArg) { if (method.ArgsType.Length > 0 && method.ArgsType.Length == (argcount + 1)) { args = new object[method.ArgsType.Length]; args[0] = this; int x = 1; for (int i = 0; i < (method.ArgsType.Length - 1); i++) { x = i + 1; args[x] = Serialization.UnpackSingleObject(method.ArgsType[x], pack.Arguments[i]); } } if (args == null) { Log.ErrorFormat("Server Call To Me-> Cmd:{0} ArgsCount:{1} Args count is Error", pack.CmdTag, argcount); } if (method.IsAsync) { if (!method.IsRet) { AsyncCalls _calls_ = new AsyncCalls(this.LoggerFactory, pack.Id, pack.CmdTag, this, method.Obj, method.MethodInfo, args, false); args[0] = _calls_; _calls_.CallSend += SendData; _calls_.ExceptionOut = this.ExceptionOut; _calls_.Run(); AsyncCallDiy.AddOrUpdate(pack.Id, _calls_, (a, b) => _calls_); } else { AsyncCalls _calls_ = new AsyncCalls(this.LoggerFactory, pack.Id, pack.CmdTag, this, method.Obj, method.MethodInfo, args, true); args[0] = _calls_; _calls_.CallSend += SendData; _calls_.Complete += RetrunResultData; _calls_.ExceptionOut = this.ExceptionOut; _calls_.Run(); AsyncCallDiy.AddOrUpdate(pack.Id, _calls_, (a, b) => _calls_); } } else //SYNC { if (!method.IsRet) { method.MethodInfo.Invoke(method.Obj, args); } else { try { object res = method.MethodInfo.Invoke(method.Obj, args); if (res != null) { var tmp = new Result(res) { Id = pack.Id }; RetrunResultData(tmp); } } catch (Exception er) { RetrunResultData(GetExceptionResult(er, pack.Id)); if (PushException(er)) { Log.Error($"Cmd:{pack.CmdTag} ERROR:{er.ToString()}"); } } } } } else { if (method.ArgsType.Length > 0 && method.ArgsType.Length == argcount) { args = new object[method.ArgsType.Length]; for (int i = 0; i < method.ArgsType.Length; i++) { args[i] = Serialization.UnpackSingleObject(method.ArgsType[i], pack.Arguments[i]); } } if (method.IsAsync) { if (!method.IsRet) { AsyncCalls _calls_ = new AsyncCalls(this.LoggerFactory, pack.Id, pack.CmdTag, this, method.Obj, method.MethodInfo, args, false); _calls_.CallSend += SendData; _calls_.ExceptionOut = this.ExceptionOut; _calls_.Run(); AsyncCallDiy.AddOrUpdate(pack.Id, _calls_, (a, b) => _calls_); } else { AsyncCalls _calls_ = new AsyncCalls(this.LoggerFactory, pack.Id, pack.CmdTag, this, method.Obj, method.MethodInfo, args, true); _calls_.CallSend += SendData; _calls_.Complete += RetrunResultData; _calls_.ExceptionOut = this.ExceptionOut; _calls_.Run(); AsyncCallDiy.AddOrUpdate(pack.Id, _calls_, (a, b) => _calls_); } } else //SYNC { if (!method.IsRet) { method.MethodInfo.Invoke(method.Obj, args); } else { try { object res = method.MethodInfo.Invoke(method.Obj, args); if (res != null) { var tmp = new Result(res) { Id = pack.Id }; RetrunResultData(tmp); } } catch (Exception er) { RetrunResultData(GetExceptionResult(er, pack.Id)); if (PushException(er)) { Log.Error($"Cmd:{pack.CmdTag} ERROR:{er.ToString()}"); } } } } } } else { Log.Error($"Server Call To Me-> Cmd:{pack.CmdTag} Not Find Cmd"); } }
private void CallPackRun(CallPack pack) { if (Module.ModuleDiy.ContainsKey(pack.CmdTag)) { AsyncMethodDef method = Module.ModuleDiy[pack.CmdTag]; object[] args = null; int argcount = 0; if (pack.Arguments != null) { argcount = pack.Arguments.Count; } if (method.ArgsType.Length > 0 && method.ArgsType.Length == (argcount + 1)) { args = new object[method.ArgsType.Length]; args[0] = this; int x = 1; for (int i = 0; i < (method.ArgsType.Length - 1); i++) { x = i + 1; args[x] = Serialization.UnpackSingleObject(method.ArgsType[x], pack.Arguments[i]); } } if (args == null) { LogAction.Log(LogType.Err, "Server Call To Me-> Cmd:{0} ArgsCount:{1} Args count is Error", pack.CmdTag, argcount); } if (method.IsAsync) { if (!method.IsOut) { AsyncCalls _calls_ = new AsyncCalls(pack.Id, pack.CmdTag, this, method.Obj, method.methodInfo, args, false); args[0] = _calls_; _calls_.CallSend += SendData; _calls_.Run(); AsyncCallDiy.AddOrUpdate(pack.Id, _calls_, (a, b) => _calls_); } else { AsyncCalls _calls_ = new AsyncCalls(pack.Id, pack.CmdTag, this, method.Obj, method.methodInfo, args, true); args[0] = _calls_; _calls_.CallSend += SendData; _calls_.Complete += RetrunResultData; _calls_.Run(); AsyncCallDiy.AddOrUpdate(pack.Id, _calls_, (a, b) => _calls_); } } else //SYNC { if (!method.IsOut) { method.methodInfo.Invoke(method.Obj, args); } else { try { object res = method.methodInfo.Invoke(method.Obj, args); if (res != null) { ReturnResult tmp = new ReturnResult(res); tmp.Id = pack.Id; RetrunResultData(tmp); } } catch (Exception er) { ReturnResult tmp = new ReturnResult(); tmp.Id = pack.Id; RetrunResultData(tmp); LogAction.Log(LogType.Err, "Cmd:{0} ERROR:" + er.ToString(), pack.CmdTag); } } } } else { LogAction.Log(LogType.Err, "Server Call To Me-> Cmd:{0} Not Find Cmd", pack.CmdTag); } }