/// <summary> /// Inflate the token /// NOTE: This operation is not continuable and assumes that the entire token is available in the stream /// </summary> /// <param name="source">Stream to inflate the token from</param> /// <returns>TRUE if inflation is complete</returns> public override bool Inflate(Stream source) { // We skip the token identifier because it is read by token factory // Read token length ushort tokenLength = TDSUtilities.ReadUShort(source); // Check if length can accomodate at least the type if (tokenLength == 0) { // We're done inflating this token return true; } // Read the token type Type = (TDSEnvChangeTokenType)source.ReadByte(); // Update the token length left tokenLength--; // Check if we can squeez anything else if (tokenLength == 0) { // We're done inflating this token return true; } // Read the rest of the token based on the token type switch (Type) { case TDSEnvChangeTokenType.Database: case TDSEnvChangeTokenType.Language: case TDSEnvChangeTokenType.CharacterSet: case TDSEnvChangeTokenType.PacketSize: case TDSEnvChangeTokenType.RealTimeLogShipping: { // Read new value length byte valueLength = (byte)source.ReadByte(); // Update token length tokenLength--; // Read string of the specified size NewValue = TDSUtilities.ReadString(source, (ushort)(valueLength * 2)); // Update token length tokenLength -= (ushort)(valueLength * 2); // Check if old value can fit in if (tokenLength == 0) { // Old value won't fit in break; } // Read old value length valueLength = (byte)source.ReadByte(); // Update token length tokenLength--; // Read string of the specified size OldValue = TDSUtilities.ReadString(source, (ushort)(valueLength * 2)); // Update token length tokenLength -= (ushort)(valueLength * 2); // Inflation is complete break; } case TDSEnvChangeTokenType.Routing: { // Read the new value length ushort valueLength = TDSUtilities.ReadUShort(source); // Update token length tokenLength -= 2; // sizeof(ushort) // Instantiate new value NewValue = new TDSRoutingEnvChangeTokenValue(); // Inflate new value if (!(NewValue as TDSRoutingEnvChangeTokenValue).Inflate(source)) { // We should never reach this point throw new Exception("Routing information inflation failed"); } // Read always-zero old value unsigned short if (TDSUtilities.ReadUShort(source) != 0) { // We should never reach this point throw new Exception("Non-zero old value for routing information"); } break; } case TDSEnvChangeTokenType.SQLCollation: { // Read new value length byte valueLength = (byte)source.ReadByte(); // Update token length tokenLength--; // Check if old value can fit in if (tokenLength == 0) { // Old value won't fit in break; } // Allocate the buffer byte[] byteValue = new byte[valueLength]; // Read bytes off the wire source.Read(byteValue, 0, byteValue.Length); // Set new value NewValue = byteValue; // Update token length tokenLength -= valueLength; // Check if old value can fit in if (tokenLength == 0) { // Old value won't fit in break; } // Read old value length valueLength = (byte)source.ReadByte(); // Update token length tokenLength--; // Check if old value can fit in if (tokenLength == 0) { // Old value won't fit in break; } // Allocate the buffer byteValue = new byte[valueLength]; // Read bytes off the wire source.Read(byteValue, 0, byteValue.Length); // Set old value OldValue = byteValue; // Update token length tokenLength -= valueLength; // Inflation is complete break; } default: { // Skip the rest of the token byte[] tokenData = new byte[tokenLength]; source.Read(tokenData, 0, tokenData.Length); break; } } return true; }
/// <summary> /// Create a new instance of the routing token that instructs client according to the routing destination URL /// </summary> protected TDSPacketToken CreateRoutingToken() { // Cast to routing server arguments RoutingTDSServerArguments ServerArguments = Arguments as RoutingTDSServerArguments; // Construct routing token value TDSRoutingEnvChangeTokenValue routingInfo = new TDSRoutingEnvChangeTokenValue(); // Read the values and populate routing info routingInfo.Protocol = (TDSRoutingEnvChangeTokenValueType)ServerArguments.RoutingProtocol; routingInfo.ProtocolProperty = ServerArguments.RoutingTCPPort; routingInfo.AlternateServer = ServerArguments.RoutingTCPHost; // Construct routing token return new TDSEnvChangeToken(TDSEnvChangeTokenType.Routing, routingInfo); }