public void Terminate() { Terminated = true; Options.Add(new TDSPreLoginOptionToken(TDSPreLoginOptionTokenType.Terminator)); LoggingUtilities.WriteLogVerboseOnly($" Terminating PreLogin message."); }
public static TDSToken ReadTokenFromStream(MemoryStream stream) { var tokenType = (TDSTokenType)stream.ReadByte(); LoggingUtilities.WriteLogVerboseOnly($" Recieved {tokenType.ToString()} token in Login7 response."); switch (tokenType) { case TDSTokenType.Error: { var token = new TDSErrorToken(); token.Unpack(stream); return(token); } case TDSTokenType.EnvChange: { var token = new TDSEnvChangeToken(); token.Unpack(stream); return(token); } default: { IgnoreToken(tokenType, stream); return(null); } } }
/// <summary> /// Add TDS Login7 Option. /// </summary> /// <param name="optionName">Option Name</param> /// <param name="data">Option Data</param> public void AddOption(string optionName, string data) { if (optionName == null || data == null) { throw new ArgumentNullException(); } if (this.Options.Where(opt => opt.Name == optionName).Any()) { throw new Exception("Login7 option already set!"); } if (optionName != "Password" && optionName != "ChangePassword") { LoggingUtilities.WriteLogVerboseOnly($" Adding Login7 option {optionName} [{data}]."); } else { LoggingUtilities.WriteLogVerboseOnly($" Adding Login7 option {optionName}."); } var option = TDSLogin7OptionFactory.CreateOption(optionName, data); this.Options.Add(option); }
// FeatureExt - unsupported public void AddOption(string optionName, ushort length, object data) { if (optionName == null || data == null) { throw new ArgumentNullException(); } OffsetLength.AddOptionPositionInfo(optionName, length); var prevLength = Data != null ? Data.Length : 0; byte[] optionData; if (optionName != "SSPI") { if (!(data is string)) { throw new ArgumentException(); } optionData = Encoding.Unicode.GetBytes((string)data); if (optionName != "Password") { LoggingUtilities.WriteLogVerboseOnly($" Adding Login7 option {optionName} [{(string)data}]."); } else { LoggingUtilities.WriteLogVerboseOnly($" Adding Login7 option {optionName}."); } } else { if (!(data is byte[])) { throw new ArgumentException(); } optionData = (byte[])data; LoggingUtilities.WriteLogVerboseOnly($" Adding Login7 option {optionName}."); } Array.Resize(ref Data, prevLength + optionData.Length); if (optionName == "Password") { for (int i = 0; i < optionData.Length; i++) { var piece0 = (byte)(optionData[i] >> 4); var piece1 = (byte)(optionData[i] & 0x0f); optionData[i] = (byte)((piece0 | (piece1 << 4)) ^ 0xA5); } } Array.Copy(optionData, 0, Data, prevLength, optionData.Length); }
public void AddOption(TDSPreLoginOptionTokenType type, Object data) { if (Terminated) { throw new InvalidOperationException(); } switch (type) { case TDSPreLoginOptionTokenType.Version: { if (data is TDSClientVersion && ClientVersion == null) { ClientVersion = (TDSClientVersion)data; LoggingUtilities.WriteLogVerboseOnly($" Adding PreLogin option {type.ToString()}."); } else { throw new ArgumentException(); } break; } case TDSPreLoginOptionTokenType.Encryption: { if (data is TDSEncryptionOption) { Encryption = (TDSEncryptionOption)data; LoggingUtilities.WriteLogVerboseOnly($" Adding PreLogin option {type.ToString()} [{Encryption.ToString()}]."); } else { throw new ArgumentException(); } break; } case TDSPreLoginOptionTokenType.FedAuthRequired | TDSPreLoginOptionTokenType.MARS: { if (data is bool) { if (type == TDSPreLoginOptionTokenType.FedAuthRequired) { FedAuthRequired = (bool)data; } else { MARS = (bool)data; } LoggingUtilities.WriteLogVerboseOnly($" Adding PreLogin option {type.ToString()} [{(bool)data}]."); } else { throw new ArgumentException(); } break; } case TDSPreLoginOptionTokenType.ThreadID: { if (data is ulong) { ThreadID = (ulong)data; LoggingUtilities.WriteLogVerboseOnly($" Adding PreLogin option {type.ToString()} [{ThreadID}]."); } else { throw new ArgumentException(); } break; } case TDSPreLoginOptionTokenType.TraceID: { if (data is TDSClientTraceID) { TraceID = (TDSClientTraceID)data; LoggingUtilities.WriteLogVerboseOnly($" Adding PreLogin option {type.ToString()}."); } else { throw new ArgumentException(); } break; } case TDSPreLoginOptionTokenType.NonceOpt: { if (data is byte[]) { Nonce = (byte[])data; LoggingUtilities.WriteLogVerboseOnly($" Adding PreLogin option {type.ToString()}."); } else { throw new ArgumentException(); } break; } default: { throw new NotSupportedException(); } } Options.Add(new TDSPreLoginOptionToken(type)); }
/// <summary> /// Adds PreLogin option to the PreLogin packet /// </summary> /// <param name="type">Option type</param> /// <param name="data">Option data</param> public void AddOption(TDSPreLoginOptionTokenType type, object data) { if (this.Terminated) { throw new InvalidOperationException(); } switch (type) { case TDSPreLoginOptionTokenType.Version: { if (data is TDSClientVersion && this.ClientVersion == null) { this.ClientVersion = (TDSClientVersion)data; LoggingUtilities.WriteLogVerboseOnly($" Adding PreLogin option {type}."); } else { throw new ArgumentException(); } break; } case TDSPreLoginOptionTokenType.Encryption: { if (data is TDSEncryptionOption) { this.Encryption = (TDSEncryptionOption)data; LoggingUtilities.WriteLogVerboseOnly($" Adding PreLogin option {type} [{this.Encryption}]."); } else { throw new ArgumentException(); } break; } case TDSPreLoginOptionTokenType.FedAuthRequired: { if (data is bool) { this.FedAuthRequired = (bool)data; LoggingUtilities.WriteLogVerboseOnly($" Adding PreLogin option {type} [{(bool)data}]."); } else { throw new ArgumentException(); } break; } case TDSPreLoginOptionTokenType.MARS: { if (data is bool) { this.MARS = (bool)data; LoggingUtilities.WriteLogVerboseOnly($" Adding PreLogin option {type} [{(bool)data}]."); } else { throw new ArgumentException(); } break; } case TDSPreLoginOptionTokenType.ThreadID: { if (data is uint) { this.ThreadID = (uint)data; LoggingUtilities.WriteLogVerboseOnly($" Adding PreLogin option {type} [{this.ThreadID}]."); } else { throw new ArgumentException(); } break; } case TDSPreLoginOptionTokenType.TraceID: { if (data is TDSClientTraceID) { this.TraceID = (TDSClientTraceID)data; LoggingUtilities.WriteLogVerboseOnly($" Adding PreLogin option {type}."); } else { throw new ArgumentException(); } break; } case TDSPreLoginOptionTokenType.NonceOpt: { if (data is byte[]) { this.Nonce = (byte[])data; LoggingUtilities.WriteLogVerboseOnly($" Adding PreLogin option {type}."); } else { throw new ArgumentException(); } break; } default: { throw new NotSupportedException(); } } this.Options.Add(new TDSPreLoginOptionToken(type)); }