Esempio n. 1
0
        private void VerifyPasswordResult(string correctPassword, string suppliedPassword, bool expectPasswordIsCorrect)
        {
            ReadRequestMessage readRequest = new ReadRequestMessage(new DateTime(0), suppliedPassword);

            using (BookmarkableStream clientStream = ClientRequestToStream(readRequest))
            {
                MockNetworkConnection networkConnection  = new MockNetworkConnection(clientStream);
                MockFolderPackager    mockFolderPackager = new MockFolderPackager();
                MockClock             serverClock        = new MockClock(new DateTime(2007, 5, 25, 15, 27, 03));

                RequestListener folderMonitor = new RequestListener(networkConnection, mockFolderPackager, serverClock, @"c:\fakepath\fakedir", correctPassword);
                folderMonitor.ProcessNextRequest();

                clientStream.ResetToBookmark();
                FarmerMessageSerializer deserializer = new FarmerMessageSerializer();
                ReadResponseMessage     readResponse = (ReadResponseMessage)deserializer.Deserialize(clientStream);

                Assert.AreEqual(expectPasswordIsCorrect, readResponse.IsPasswordCorrect);

                if (expectPasswordIsCorrect)
                {
                    Assert.AreEqual(serverClock.GetCurrentTimeUtc(), readResponse.CurrentServerTimeUtc);
                    Assert.IsNotNull(readResponse.Data);
                }
                else
                {
                    Assert.IsNull(readResponse.Data);
                }
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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;
        }
Esempio n. 6
0
        private void VerifyMonitoring(DateTime startTimestampExpected, byte[] folderDataExpected)
        {
            MockFolderPackager mockFolderPackager = new MockFolderPackager();
            MockClock          serverClock        = new MockClock(new DateTime(2007, 5, 25, 15, 27, 03));

            ReadRequestMessage readRequest = new ReadRequestMessage(startTimestampExpected, CorrectPassword);

            using (BookmarkableStream clientStream = ClientRequestToStream(readRequest))
            {
                MockNetworkConnection networkConnection = new MockNetworkConnection(clientStream);
                RequestListener       folderMonitor     = new RequestListener(networkConnection, mockFolderPackager, serverClock, @"c:\fakepath\fakedir", CorrectPassword);
                folderMonitor.ProcessNextRequest();
                Assert.AreEqual(@"c:\fakepath\fakedir", mockFolderPackager.LastFolderPacked);
                Assert.AreEqual(startTimestampExpected, mockFolderPackager.LastModifiedMinimumRequested);

                clientStream.ResetToBookmark();
                FarmerMessageSerializer deserializer = new FarmerMessageSerializer();
                ReadResponseMessage     response     = (ReadResponseMessage)deserializer.Deserialize(clientStream);

                Assert.AreEqual(serverClock.GetCurrentTimeUtc(), response.CurrentServerTimeUtc);
                Assert.IsTrue(Util.ArraysEqual <byte>(folderDataExpected, response.Data));
            }
        }
Esempio n. 7
0
        private void SendResponse(IFarmerNetworkMessage response)
        {
            FarmerMessageSerializer serializer = new FarmerMessageSerializer();

            serializer.Serialize(_clientStream, response);
        }
Esempio n. 8
0
        private RequestMessageBase ReceiveRequest()
        {
            FarmerMessageSerializer deserializer = new FarmerMessageSerializer();

            return((RequestMessageBase)deserializer.Deserialize(_clientStream));
        }