/// <summary> /// 添加一个任务到队列 /// </summary> /// <param name="info">信息</param> /// <param name="socket">远程连接</param> /// <returns></returns> public RemoteCallEntrity AddTaskQueue(RequestExecutiveInformation info, FRPCEasyClient socket) { var result = new RemoteCallEntrity(info.ID, info, ReceiveMessageState.Wait, DateTime.Now.AddSeconds(OvertimeSecond), socket); MethodCallQueues.TryAdd(info.ID, result); return(result); }
/// <summary> /// 执行RPC的调用 /// </summary> /// <param name="info">信息</param> /// <param name="requestInfo">基础信息</param> async void ImplementFunc(RequestExecutiveInformation info, RequestBaseInfo requestInfo) { await Task.Yield(); //接收RPC的请求 if (ServiceProvider.GetService(info.FullName, EasySocket, info, requestInfo, EasySocket.UnityContainer, info.RequestClientSession, out object executionObj, out var iServerType)) { var methodType = iServerType.GetMethod(info.MethodName); List <object> attribtes = new List <object>(); attribtes.AddRange(iServerType.CustomAttributes.Select(d => d.Constructor.Invoke(null)).Where(d => d is RequestFilterAttribte).ToArray()); attribtes.AddRange(methodType.GetCustomAttributes(true).Where(d => d is RequestFilterAttribte).ToArray()); //Filter前 object result = null; if (executionObj is BaseProvideServices) { if (!BeforeExecutionAttribte(attribtes, (BaseProvideServices)executionObj, ref result, methodType.ReturnType)) { return; } } List <object> paraList = new List <object>(); var paras = methodType.GetParameters(); for (int i = 0; i < info.Arguments.Count; i++) { paraList.Add(JsonConvert.DeserializeObject(info.Arguments[i], paras[i].ParameterType)); } try { result = result ?? methodType.Invoke(executionObj, paraList.ToArray()); } catch (Exception e) { info.ReturnValue = null; Console.WriteLine("处理请求时候出现异常:" + e); EasySocket.Requestexception?.HandleException(e); } if (executionObj is BaseProvideServices) { if (AfterxecutionExecutionAttribte(attribtes, (BaseProvideServices)executionObj, ref result, methodType.ReturnType)) { info.ReturnValue = JsonConvert.SerializeObject(result); var msg = JsonConvert.SerializeObject(info); EasySocket.SendMessage(msg); } } else { info.ReturnValue = JsonConvert.SerializeObject(result); var msg = JsonConvert.SerializeObject(info); EasySocket.SendMessage(msg); } }