Example #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);
                }
            }
        }
Example #2
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);
        }
Example #3
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;
        }
Example #4
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));
            }
        }
Example #5
0
        private RequestMessageBase ReceiveRequest()
        {
            FarmerMessageSerializer deserializer = new FarmerMessageSerializer();

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