/// <summary>
        /// Send TDS Message to the server.
        /// </summary>
        /// <param name="data">TDS Message Data</param>
        public void SendTDSMessage(ITDSPacketData data)
        {
            switch (this.communicatorState)
            {
            case TDSCommunicatorState.Initial:
            {
                if (!(data is TDSPreLoginPacketData))
                {
                    throw new InvalidDataException();
                }

                this.innerTdsStream.CurrentOutboundMessageType = TDSMessageType.PreLogin;
                break;
            }

            case TDSCommunicatorState.SentInitialPreLogin:
            {
                if (!(data is TDSLogin7PacketData))
                {
                    throw new InvalidDataException();
                }

                this.innerTdsStream.CurrentOutboundMessageType = TDSMessageType.TDS7Login;
                break;
            }

            case TDSCommunicatorState.LoggedIn:
            {
                throw new NotSupportedException();
            }

            default:
            {
                throw new InvalidOperationException();
            }
            }

            var buffer = new byte[data.Length()];

            data.Pack(new MemoryStream(buffer));

            this.innerStream.Write(buffer, 0, buffer.Length);

            switch (this.communicatorState)
            {
            case TDSCommunicatorState.Initial:
            {
                this.communicatorState = TDSCommunicatorState.SentInitialPreLogin;
                break;
            }

            case TDSCommunicatorState.SentInitialPreLogin:
            {
                this.communicatorState = TDSCommunicatorState.SentLogin7RecordWithCompleteAuthToken;
                break;
            }
            }
        }
Esempio n. 2
0
        public bool Unpack(MemoryStream stream)
        {
            Header = new TDSPacketHeader();
            Header.Unpack(stream);
            switch (Header.Type)
            {
            case TDSMessageType.AttentionSignal:
            {
                throw new NotSupportedException();
            }

            case TDSMessageType.BulkLoadData:
            {
                throw new NotSupportedException();
            }

            case TDSMessageType.FedAuthToken:
            {
                throw new NotSupportedException();
            }

            case TDSMessageType.PreLogin:
            {
                Data = new TDSPreLoginPacketData();
                Data.Unpack(stream);
                break;
            }

            case TDSMessageType.PreTDS7Login:
            {
                throw new NotSupportedException();
            }

            case TDSMessageType.RPC:
            {
                throw new NotSupportedException();
            }

            case TDSMessageType.SQLBatch:
            {
                throw new NotSupportedException();
            }

            case TDSMessageType.SSPI:
            {
                throw new NotSupportedException();
            }

            case TDSMessageType.TabularResult:
            {
                throw new NotSupportedException();
            }

            case TDSMessageType.TDS7Login:
            {
                throw new NotSupportedException();
            }

            case TDSMessageType.TransactionManagerRequest:
            {
                throw new NotSupportedException();
            }
            }
            return(true);
        }
Esempio n. 3
0
 public TDSPacket(TDSPacketHeader header, ITDSPacketData data)
 {
     Header = header;
     Data   = data;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TDSPacket" /> class.
 /// </summary>
 /// <param name="header">TDS Packet Header</param>
 /// <param name="data">TDS Packet Data</param>
 public TDSPacket(TDSPacketHeader header, ITDSPacketData data)
 {
     this.Header = header;
     this.Data   = data;
 }