/// <summary>
        /// Receive TDS Message from the server.
        /// </summary>
        /// <returns>Returns received TDS Message.</returns>
        public ITDSPacketData ReceiveTDSMessage()
        {
            if (TDSSQLTestClient.flag == TDSEncryptionOption.EncryptOff && this.communicatorState == TDSCommunicatorState.Initial)
            {
                this.communicatorState = TDSCommunicatorState.SentLogin7RecordWithCompleteAuthToken;
            }
            TDSSQLTestClient.flag = TDSEncryptionOption.EncryptOn;
            byte[] resultBuffer = null;
            var    curOffset    = 0;

            if (this.communicatorState == TDSCommunicatorState.SentLogin7RecordWithCompleteAuthToken)
            {
            }
            do
            {
                Array.Resize(ref resultBuffer, curOffset + this.packetSize);
                curOffset += this.innerStream.Read(resultBuffer, curOffset, this.packetSize);
            }while (!this.innerTdsStream.InboundMessageTerminated);

            Array.Resize(ref resultBuffer, curOffset);

            ITDSPacketData result;

            switch (this.communicatorState)
            {
            case TDSCommunicatorState.SentInitialPreLogin:
            {
                result = new TDSPreLoginPacketData();
                result.Unpack(new MemoryStream(resultBuffer));
                break;
            }

            case TDSCommunicatorState.SentLogin7RecordWithCompleteAuthToken:
            {
                result = new TDSTokenStreamPacketData();
                result.Unpack(new MemoryStream(resultBuffer));
                break;
            }

            default:
            {
                throw new InvalidOperationException();
            }
            }

            return(result);
        }
예제 #2
0
        public void LoginResponseUnpacking()
        {
            var bytesJSON  = File.ReadAllText("./Assets/PacketData/LoginResponse_Bytes.json");
            var packetJSON = File.ReadAllText("./Assets/PacketData/LoginResponse_Object.json");

            JsonSerializerSettings settings = new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            };
            var bytes  = JsonConvert.DeserializeObject <byte[]>(bytesJSON, settings);
            var packet = JsonConvert.DeserializeObject <TDSTokenStreamPacketData>(packetJSON, settings);

            var testPacket = new TDSTokenStreamPacketData();

            testPacket.Unpack(new MemoryStream(bytes));

            Assert.AreEqual(packet, testPacket);
        }
예제 #3
0
        public ITDSPacketData ReceiveTDSMessage()
        {
            byte[] resultBuffer = null;
            var    curOffset    = 0;

            do
            {
                Array.Resize(ref resultBuffer, curOffset + PacketSize);
                curOffset += InnerStream.Read(resultBuffer, curOffset, PacketSize);
            }while (!InnerTdsStream.InboundMessageTerminated);

            Array.Resize(ref resultBuffer, curOffset);

            ITDSPacketData result;

            switch (CommunicatorState)
            {
            case TDSCommunicatorState.SentInitialPreLogin:
            {
                result = new TDSPreLoginPacketData();
                result.Unpack(new MemoryStream(resultBuffer));
                break;
            }

            case TDSCommunicatorState.SentLogin7RecordWithCompleteAuthToken:
            {
                result = new TDSTokenStreamPacketData();
                result.Unpack(new MemoryStream(resultBuffer));
                break;
            }

            default:
            {
                throw new InvalidOperationException();
            }
            }

            return(result);
        }