Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        private void SendResponse(IFarmerNetworkMessage response)
        {
            FarmerMessageSerializer serializer = new FarmerMessageSerializer();

            serializer.Serialize(_clientStream, response);
        }