public void ThenSerializaionAndDeserializationWorksForPerLineDiffResult() { var serialized = XmlSerializationHelper.Serialize(_perLineDiffResultSource); var deserialized = XmlSerializationHelper.DeSerialize <List <PerLineDiffResult> >(serialized); Assert.IsTrue(_perLineDiffResultSource.Count == deserialized.Count); Assert.IsTrue(_perLineDiffResultSource.First().Equals(deserialized.First())); }
private object DeSerializeRequest(string requestTypeString, string requestString) { Type requestType = ReflectionHelper.FindType(requestTypeString); if (requestType != null) { return(XmlSerializationHelper.DeSerialize(requestString, requestType)); } return(null); }
private void ProcessResponse(ResponseHeader header, string rawRequestString) { if (header.MessageHeader.EncryptionHeader.EncryptionType != EncryptionTypes.None) { DHPublicKeyParameters publicKey = new DHPublicKeyParameters( ((DHPublicKeyParameters)PublicKeyFactory.CreateKey(_serverPublicKey)).Y, _serverAuthority.Parameters); BigInteger agreementValue = _serverAuthority.GenerateAgreementValue(publicKey); RijndaelCrypto crypto = new RijndaelCrypto(); rawRequestString = crypto.Decrypt(rawRequestString, agreementValue.ToString(16)); } switch (header.ResponseType) { case ResponseTypes.LoginResponse: { LoginResponse response = XmlSerializationHelper.DeSerialize <LoginResponse>(rawRequestString); OnServerResponse(new ServerResponseEventArgs() { Response = response }); } break; case ResponseTypes.JoinRoomEvent: { JoinRoomEvent evt = XmlSerializationHelper.DeSerialize <JoinRoomEvent>(rawRequestString); OnServerEvent(new ServerEventEventArgs() { ServerEvent = evt }); } break; case ResponseTypes.RoomUserUpdateEvent: { RoomUserUpdateEvent evt = XmlSerializationHelper.DeSerialize <RoomUserUpdateEvent>(rawRequestString); OnServerEvent(new ServerEventEventArgs() { ServerEvent = evt }); } break; } }
protected void PumpMessages() { var serverDown = false; int step = 0; ResponseHeader header = null; while (!serverDown && !_serverDisconnectedEvent.WaitOne(0)) { IList readList = new List <Socket> { _socket.RawSocket }; // now let's wait for messages Socket.Select(readList, null, null, 100); // there is only one socket in the poll list // so if the count is greater than 0 then // the only one available should be the client socket if (readList.Count > 0) { // if socket is selected, and if available byes is 0, // then socket has been closed serverDown = _socket.RawSocket.Available == 0; if (!serverDown) { byte[] data = _socket.ReceiveData(); buffer.Write(data); bool done = false; while (!done) { done = true; MemoryStream stream = new MemoryStream(buffer.Buffer); switch (step) { case 0: /* reading header */ { string utfString = stream.ReadUTF(); if (utfString != null) { //TextReader reader = new StringReader(utfString); header = XmlSerializationHelper .DeSerialize <ResponseHeader>(utfString); step++; } } break; case 1: { string rawRequestString = stream.ReadUTF(); if (!string.IsNullOrEmpty(rawRequestString) && header != null) { ProcessResponse(header, rawRequestString); step = 0; } } break; } // fix up buffers buffer = new ClientBuffer(); // if any data left, fix up buffers if (stream.Length > stream.Position) { // left over bytes byte[] leftover = stream.Read((int)(stream.Length - stream.Position)); buffer.Write(leftover); done = false; } } } } } _serverDisconnectedEvent.Set(); }