public static T BuildMessageFromResponse <T> (DDPMessage ddpMessage) where T : DDPBaseModel, new() { try { return(Util.FromDDPMessageResult <T> (ddpMessage)); } catch (Exception e) { // This is the sad consequence of the server using different data types for the field Result. // Sometimes that field can be a boolean, others a string, and others a json object (in which case it // is handled in the try block). Here we just assign the value to a generic object type and let the // client handle it appropriately. if (True.Equals(ddpMessage.Result)) { return(new T() { Result = true, DDPMessageData = ddpMessage.DDPMessageData }); } else if (False.Equals(ddpMessage.Result)) { return(new T() { Result = false }); } else { return(new T() { Result = ddpMessage.Result, DDPMessageData = ddpMessage.DDPMessageData }); } } }
/// <summary> /// 当客户端登录后,进行Ip信息的过滤,然后触发本方法,也就是说之后的客户端需要 /// </summary> /// <param name="socket">网络套接字</param> /// <param name="endPoint">终端节点</param> protected override void ThreadPoolLoginAfterClientCheck(Socket socket, System.Net.IPEndPoint endPoint) { // 接收注册包 DDPMessage dDPMessage = new DDPMessage(); OperateResult<byte[]> read = ReceiveByMessage(socket, int.MaxValue, dDPMessage);//5000 时间延长 if (!read.IsSuccess) return; string str = SoftBasic.ByteToSegmentation(read.Content); //OperateResult send = Send(socket, SoftBasic.HexStringToBytes("")); //if (!send.IsSuccess) return; // 开始接收数据信息 AppSession appSession = new AppSession(); appSession.IpEndPoint = endPoint; appSession.WorkSocket = socket; try { socket.BeginReceive(new byte[0], 0, 0, SocketFlags.None, new AsyncCallback(SocketAsyncCallBack), appSession); AddClient(appSession); } catch { socket.Close(); LogNet?.WriteDebug(ToString(), string.Format(StringResources.Language.ClientOfflineInfo, endPoint)); } }
public static T FromDDPMessageField <T> (DDPMessage ddpMessage) where T : DDPBaseModel, new() { if (ddpMessage == null) { throw new ArgumentNullException("ddpMessage"); } T response = null; if (ddpMessage.Fields != null) { response = JsonConvert.DeserializeObject <T> (ddpMessage.Fields); } else { response = new T(); } response.DDPMessageData = ddpMessage.DDPMessageData; return(response); }