Пример #1
0
 public bool Unpack(MemoryStream stream)
 {
     TraceID          = BigEndianUtilities.ReadByteArray(stream, 16);
     ActivityID       = BigEndianUtilities.ReadByteArray(stream, 16);
     ActivitySequence = BigEndianUtilities.ReadULong(stream);
     return(true);
 }
Пример #2
0
        public void ReadByteArrayFromMemoryStream()
        {
            var stream = new MemoryStream();

            stream.Write(new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef });
            stream.Seek(0, SeekOrigin.Begin);

            var res = BigEndianUtilities.ReadByteArray(stream, 8);

            CollectionAssert.AreEqual(new byte[] { 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01 }, res);
        }
        public bool Unpack(MemoryStream stream)
        {
            {
                TDSPreLoginOptionToken option;
                do
                {
                    option = new TDSPreLoginOptionToken();
                    option.Unpack(stream);
                    Options.Add(option);
                }while (option.Type != TDSPreLoginOptionTokenType.Terminator);
            }
            foreach (var option in Options)
            {
                switch (option.Type)
                {
                case TDSPreLoginOptionTokenType.Encryption:
                {
                    Encryption = (TDSEncryptionOption)stream.ReadByte();
                    break;
                }

                case TDSPreLoginOptionTokenType.FedAuthRequired:
                {
                    FedAuthRequired = stream.ReadByte() == 1;
                    break;
                }

                case TDSPreLoginOptionTokenType.InstOpt:
                {
                    throw new NotSupportedException();
                }

                case TDSPreLoginOptionTokenType.MARS:
                {
                    MARS = stream.ReadByte() == 1;
                    break;
                }

                case TDSPreLoginOptionTokenType.NonceOpt:
                {
                    Nonce = BigEndianUtilities.ReadByteArray(stream, 32);
                    break;
                }

                case TDSPreLoginOptionTokenType.ThreadID:
                {
                    ThreadID = BigEndianUtilities.ReadULong(stream);
                    break;
                }

                case TDSPreLoginOptionTokenType.TraceID:
                {
                    TraceID = new TDSClientTraceID();
                    TraceID.Unpack(stream);
                    break;
                }

                case TDSPreLoginOptionTokenType.Version:
                {
                    ClientVersion = new TDSClientVersion();
                    ClientVersion.Unpack(stream);
                    break;
                }

                case TDSPreLoginOptionTokenType.Terminator:
                {
                    break;
                }
                }
            }
            Terminated = true;
            return(true);
        }
Пример #4
0
        /// <summary>
        /// Used to unpack IPackageable from a stream.
        /// </summary>
        /// <param name="stream">MemoryStream from which to unpack IPackageable.</param>
        /// <returns>Returns true if successful.</returns>
        public bool Unpack(MemoryStream stream)
        {
            {
                TDSPreLoginOptionToken option;
                do
                {
                    option = new TDSPreLoginOptionToken();
                    option.Unpack(stream);
                    this.Options.Add(option);
                }while (option.Type != TDSPreLoginOptionTokenType.Terminator);
            }

            foreach (var option in this.Options)
            {
                switch (option.Type)
                {
                case TDSPreLoginOptionTokenType.Encryption:
                {
                    this.Encryption = (TDSEncryptionOption)stream.ReadByte();
                    break;
                }

                case TDSPreLoginOptionTokenType.FedAuthRequired:
                {
                    this.FedAuthRequired = stream.ReadByte() == 1;
                    break;
                }

                case TDSPreLoginOptionTokenType.InstOpt:
                {
                    this.Instance = new byte[option.Length];
                    stream.Read(this.Instance, 0, option.Length);

                    break;
                }

                case TDSPreLoginOptionTokenType.MARS:
                {
                    this.MARS = stream.ReadByte() == 1;
                    break;
                }

                case TDSPreLoginOptionTokenType.NonceOpt:
                {
                    this.Nonce = BigEndianUtilities.ReadByteArray(stream, 32);
                    break;
                }

                case TDSPreLoginOptionTokenType.ThreadID:
                {
                    this.ThreadID = BigEndianUtilities.ReadUInt(stream);
                    break;
                }

                case TDSPreLoginOptionTokenType.TraceID:
                {
                    this.TraceID = new TDSClientTraceID();
                    this.TraceID.Unpack(stream);
                    break;
                }

                case TDSPreLoginOptionTokenType.Version:
                {
                    this.ClientVersion = new TDSClientVersion();
                    this.ClientVersion.Unpack(stream);
                    break;
                }

                case TDSPreLoginOptionTokenType.Terminator:
                {
                    break;
                }
                }
            }

            this.Terminated = true;
            return(true);
        }