protected virtual Task SendNotRunType(MethodRegister service, long id, int runtype) { Log.WarnFormat("{service} call async service:{RemoteEndPoint} not find RunType:{runtype}" , service , FiberRw?.Async?.AcceptSocket?.RemoteEndPoint?.ToString() ?? "null" , runtype); return(SendError(id, $"call async service:{service} not find RunType:{runtype}", ErrorType.NotRunType)); }
protected virtual async Task RunControllerService(MethodRegister service, AsyncController controller, int cmd, long id, int runType, List <IMemoryOwner <byte> > memoryOwners, params object[] args) { switch (service.ReturnMode) { case ReturnTypeMode.Null: if (runType == 0) { controller.Runs__Make(cmd, args); Dispose_table(memoryOwners); return; } break; case ReturnTypeMode.Task: if (runType == 1) { await(dynamic) controller.Runs__Make(cmd, args); Dispose_table(memoryOwners); await SendResult(id); return; } break; case ReturnTypeMode.TaskValue: if (runType == 2) { var ret_value = await(dynamic) controller.Runs__Make(cmd, args); Dispose_table(memoryOwners); switch (ret_value) { case Result result: { result.Id = id; await SendResult(result); return; } default: { await SendResult(id, ret_value); return; } } } break; } SendNotRunType(service, id, runType); }
/// <summary> /// 注册命令 /// </summary> /// <param name="cmd">命令</param> /// <param name="instanceType">实例类型</param> /// <param name="methodInfo">方法</param> private bool IsRegisterCmd(int cmd, Type instanceType, MethodInfo methodInfo) { if (TypeHelper.IsTypeOfBaseTypeIs(methodInfo.ReturnType, typeof(Task)) || methodInfo.ReturnType == typeof(void) || methodInfo.ReturnType == null) { var sr = new MethodRegister(instanceType, methodInfo); AsyncServicesRegisterDict.AddOrUpdate(cmd, sr, (a, b) => sr); return(true); } else { throw new NetxException("RegisterService Return Type Err:{ 0 },Use void, Task or Task<T>", ErrorType.RegisterCmdErr); } }
protected virtual async void RunCall(MethodRegister service, int cmd, long id, int runtype, List <IMemoryOwner <byte> > memoryOwners, params object[] args) { try { var controller = GetInstance(id, cmd, service.InstanceType); if (controller != null) { await RunControllerService(service, controller, cmd, id, runtype, memoryOwners, args); } } catch (System.Net.Sockets.SocketException) { } catch (Exception er) { Log.Error("Async Server Err:", er); SendError(id, $"Async Server Err:{er.Message}", ErrorType.CallErr); } }
protected virtual Task SendNotRunType(MethodRegister service, long id, int runtype) { Log.WarnFormat("call method:{0} not find runtype:{1} ", service, runtype); return(SendError(id, $"call method:{service} not find runtype:{runtype}", ErrorType.NotRunType)); }
// Use this for initialization void Start() { MethodRegister.ResetOrientation(MethodRegister.PORTRAIT); NetWorkScript nws = NetWorkScript.Instance; }