private Stream ServerResponseToStream(ReadResponseMessage responseMessage) { ReadingStream responseStream = new ReadingStream(); FarmerMessageSerializer serializer = new FarmerMessageSerializer(); serializer.Serialize(responseStream, responseMessage); responseStream.Seek(0, SeekOrigin.Begin); responseStream.StopProcessingWrites(); return(responseStream); }
private BookmarkableStream ClientRequestToStream(ReadRequestMessage requestMessage) { BookmarkableStream requestStream = new BookmarkableStream(); FarmerMessageSerializer serializer = new FarmerMessageSerializer(); serializer.Serialize(requestStream, requestMessage); requestStream.SetBookmark(); requestStream.Seek(0, SeekOrigin.Begin); return(requestStream); }
public void SerializeDeserializeTest() { ReadRequestMessage messageOriginal = new ReadRequestMessage(new DateTime(2012, 5, 27), ""); FarmerMessageSerializer serializer = new FarmerMessageSerializer(); MemoryStream stream = new MemoryStream(); serializer.Serialize(stream, messageOriginal); stream.Seek(0, SeekOrigin.Begin); ReadRequestMessage messageDeserialized = (ReadRequestMessage)serializer.Deserialize(stream); Assert.AreEqual(messageOriginal, messageDeserialized); }
public void Pull(Stream serverStream, string destinationFolder) { ReadRequestMessage readRequest = new ReadRequestMessage(LastPullTime, _serverPassword); FarmerMessageSerializer messageSerializer = new FarmerMessageSerializer(); messageSerializer.Serialize(serverStream, readRequest); ReadResponseMessage readResponse = (ReadResponseMessage)messageSerializer.Deserialize(serverStream); if (!readResponse.IsPasswordCorrect) { Console.WriteLine("Error: Incorrect password."); return; } Console.WriteLine("Server check time was {0}", readResponse.CurrentServerTimeUtc.ToLocalTime()); Console.WriteLine("Read {0}", FormatByteCount(readResponse.Data.Length)); _folderUnpacker.UnpackFolder(destinationFolder, readResponse.Data); LastPullTime = readResponse.CurrentServerTimeUtc; }
private void SendResponse(IFarmerNetworkMessage response) { FarmerMessageSerializer serializer = new FarmerMessageSerializer(); serializer.Serialize(_clientStream, response); }