Beispiel #1
0
        public void WriteULongToMemoryStream()
        {
            var stream = new MemoryStream();

            BigEndianUtilities.WriteULong(stream, 0x0123456789abcdef);

            CollectionAssert.AreEqual(new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, stream.ToArray());
        }
Beispiel #2
0
 public void Pack(MemoryStream stream)
 {
     BigEndianUtilities.WriteByteArray(stream, TraceID);
     BigEndianUtilities.WriteByteArray(stream, ActivityID);
     BigEndianUtilities.WriteULong(stream, ActivitySequence);
 }
        public void Pack(MemoryStream stream)
        {
            if (Options.Count == 0 || Options[0].Type != TDSPreLoginOptionTokenType.Version || Options[Options.Count - 1].Type != TDSPreLoginOptionTokenType.Terminator || !Terminated)
            {
                throw new InvalidOperationException();
            }

            var offset = (ushort)((Options.Count - 1) * (2 * sizeof(ushort) + sizeof(byte)) + sizeof(byte));

            foreach (var option in Options)
            {
                // ToDo
                option.Offset = offset;
                option.Pack(stream);
            }

            foreach (var option in Options)
            {
                switch (option.Type)
                {
                case TDSPreLoginOptionTokenType.Encryption:
                {
                    stream.WriteByte((byte)Encryption);
                    break;
                }

                case TDSPreLoginOptionTokenType.FedAuthRequired:
                {
                    if (FedAuthRequired)
                    {
                        stream.WriteByte(0x01);
                    }
                    else
                    {
                        stream.WriteByte(0x00);
                    }
                    break;
                }

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

                case TDSPreLoginOptionTokenType.MARS:
                {
                    if (MARS)
                    {
                        stream.WriteByte(0x01);
                    }
                    else
                    {
                        stream.WriteByte(0x00);
                    }
                    break;
                }

                case TDSPreLoginOptionTokenType.NonceOpt:
                {
                    BigEndianUtilities.WriteByteArray(stream, Nonce);
                    break;
                }

                case TDSPreLoginOptionTokenType.ThreadID:
                {
                    BigEndianUtilities.WriteULong(stream, ThreadID);
                    break;
                }

                case TDSPreLoginOptionTokenType.TraceID:
                {
                    TraceID.Pack(stream);
                    break;
                }

                case TDSPreLoginOptionTokenType.Version:
                {
                    ClientVersion.Pack(stream);
                    break;
                }
                }
            }
        }