/// <summary> /// Inflate from stream /// </summary> public virtual bool Inflate(Stream source) { // Create options collection Options = new List<TDSSessionStateOption>(); // Current position in the stream InflationSize = 0; // Read the total length uint totalLength = TDSUtilities.ReadUInt(source); // Check if we still have space to read if (InflationSize >= totalLength) { // Inflation is complete return true; } // Read the length of the string byte byteLength = (byte)source.ReadByte(); // Update offset InflationSize += sizeof(byte); // Check if we still have space to read if (InflationSize >= totalLength) { // Inflation is complete return true; } // Read the string Database = TDSUtilities.ReadString(source, (ushort)(byteLength * 2)); // Update offset InflationSize += ((uint)byteLength * 2); // one character is 2 bytes long // Check if we still have space to read if (InflationSize >= totalLength) { // Inflation is complete return true; } // Read the length of the collation byteLength = (byte)source.ReadByte(); // Update offset InflationSize += sizeof(byte); // Check if we still have space to read if (InflationSize >= totalLength) { // Inflation is complete return true; } // Check if we have a collation if (byteLength > 0) { // Allocate collation Collation = new byte[5]; // Read collation int readBytes = source.Read(Collation, 0, Collation.Length); // Update offset InflationSize += (uint)readBytes; // Check if we still have space to read if (InflationSize >= totalLength) { // Inflation is complete return true; } } // Read the length of the string byteLength = (byte)source.ReadByte(); // Update offset InflationSize += sizeof(byte); // Check if we still have space to read if (InflationSize >= totalLength) { // Inflation is complete return true; } // Read the string Language = TDSUtilities.ReadString(source, (ushort)(byteLength * 2)); // Update offset InflationSize += ((uint)byteLength * 2); // one character is 2 bytes long // Read while we have data while (totalLength > InflationSize) { // Read a byte that identifies the session state slot byte stateID = (byte)source.ReadByte(); // Update current position InflationSize += sizeof(byte); // Option being inflated TDSSessionStateOption option = null; // Dispatch inflation based on the state switch (stateID) { // UserOptionAll case TDSSessionStateUserOptionsOption.ID: { // Create a new option option = new TDSSessionStateUserOptionsOption(); break; } // DateFirstDateFormat case TDSSessionStateDateFirstDateFormatOption.ID: { // Create a new option option = new TDSSessionStateDateFirstDateFormatOption(); break; } // DbDeadlockPri case TDSSessionStateDeadlockPriorityOption.ID: { // Create a new option option = new TDSSessionStateDeadlockPriorityOption(); break; } // LockTimeout case TDSSessionStateLockTimeoutOption.ID: { // Create a new option option = new TDSSessionStateLockTimeoutOption(); break; } // IsoFips case TDSSessionStateISOFipsOption.ID: { // Create a new option option = new TDSSessionStateISOFipsOption(); break; } // TextSize case TDSSessionStateTextSizeOption.ID: { // Create a new option option = new TDSSessionStateTextSizeOption(); break; } // ContextInfo case TDSSessionStateContextInfoOption.ID: { // Create a new option option = new TDSSessionStateContextInfoOption(); break; } default: { // Create a new option option = new TDSSessionStateGenericOption(stateID); break; } } // Inflate the option option.Inflate(source); // Register option with the collection Options.Add(option); // Update current length with the inflation size of the data InflationSize += option.InflationSize; } // Inflation is complete return true; }
/// <summary> /// Inflate from stream /// </summary> public virtual bool Inflate(Stream source) { // Create options collection Options = new List <TDSSessionStateOption>(); // Current position in the stream InflationSize = 0; // Read the total length uint totalLength = TDSUtilities.ReadUInt(source); // Check if we still have space to read if (InflationSize >= totalLength) { // Inflation is complete return(true); } // Read the length of the string byte byteLength = (byte)source.ReadByte(); // Update offset InflationSize += sizeof(byte); // Check if we still have space to read if (InflationSize >= totalLength) { // Inflation is complete return(true); } // Read the string Database = TDSUtilities.ReadString(source, (ushort)(byteLength * 2)); // Update offset InflationSize += ((uint)byteLength * 2); // one character is 2 bytes long // Check if we still have space to read if (InflationSize >= totalLength) { // Inflation is complete return(true); } // Read the length of the collation byteLength = (byte)source.ReadByte(); // Update offset InflationSize += sizeof(byte); // Check if we still have space to read if (InflationSize >= totalLength) { // Inflation is complete return(true); } // Check if we have a collation if (byteLength > 0) { // Allocate collation Collation = new byte[5]; // Read collation int readBytes = source.Read(Collation, 0, Collation.Length); // Update offset InflationSize += (uint)readBytes; // Check if we still have space to read if (InflationSize >= totalLength) { // Inflation is complete return(true); } } // Read the length of the string byteLength = (byte)source.ReadByte(); // Update offset InflationSize += sizeof(byte); // Check if we still have space to read if (InflationSize >= totalLength) { // Inflation is complete return(true); } // Read the string Language = TDSUtilities.ReadString(source, (ushort)(byteLength * 2)); // Update offset InflationSize += ((uint)byteLength * 2); // one character is 2 bytes long // Read while we have data while (totalLength > InflationSize) { // Read a byte that identifies the session state slot byte stateID = (byte)source.ReadByte(); // Update current position InflationSize += sizeof(byte); // Option being inflated TDSSessionStateOption option = null; // Dispatch inflation based on the state switch (stateID) { // UserOptionAll case TDSSessionStateUserOptionsOption.ID: { // Create a new option option = new TDSSessionStateUserOptionsOption(); break; } // DateFirstDateFormat case TDSSessionStateDateFirstDateFormatOption.ID: { // Create a new option option = new TDSSessionStateDateFirstDateFormatOption(); break; } // DbDeadlockPri case TDSSessionStateDeadlockPriorityOption.ID: { // Create a new option option = new TDSSessionStateDeadlockPriorityOption(); break; } // LockTimeout case TDSSessionStateLockTimeoutOption.ID: { // Create a new option option = new TDSSessionStateLockTimeoutOption(); break; } // IsoFips case TDSSessionStateISOFipsOption.ID: { // Create a new option option = new TDSSessionStateISOFipsOption(); break; } // TextSize case TDSSessionStateTextSizeOption.ID: { // Create a new option option = new TDSSessionStateTextSizeOption(); break; } // ContextInfo case TDSSessionStateContextInfoOption.ID: { // Create a new option option = new TDSSessionStateContextInfoOption(); break; } default: { // Create a new option option = new TDSSessionStateGenericOption(stateID); break; } } // Inflate the option option.Inflate(source); // Register option with the collection Options.Add(option); // Update current length with the inflation size of the data InflationSize += option.InflationSize; } // Inflation is complete return(true); }
/// <summary> /// Serialize session state into a collection of options /// </summary> /// <returns></returns> public virtual IList<TDSSessionStateOption> Deflate() { // Prepare options list IList<TDSSessionStateOption> options = new List<TDSSessionStateOption>(); // Create user options option TDSSessionStateUserOptionsOption userOptionsOption = new TDSSessionStateUserOptionsOption(); // Transfer properties from the session onto the session state userOptionsOption.AnsiWarnings = AnsiWarnings; userOptionsOption.AnsiNulls = AnsiNulls; userOptionsOption.CursorCloseOnCommit = CursorCloseOnCommit; userOptionsOption.QuotedIdentifier = QuotedIdentifier; userOptionsOption.ConcatNullYieldsNull = ConcatNullYieldsNull; userOptionsOption.AnsiNullDefaultOn = AnsiNullDefaultOn; userOptionsOption.AnsiPadding = AnsiPadding; userOptionsOption.ArithAbort = ArithAbort; userOptionsOption.TransactionAbortOnError = TransactionAbortOnError; userOptionsOption.NoCount = NoCount; userOptionsOption.ArithIgnore = ArithIgnore; userOptionsOption.ImplicitTransactions = ImplicitTransactions; userOptionsOption.NumericRoundAbort = ImplicitTransactions; // Register option with the collection options.Add(userOptionsOption); // Create date first/date format option TDSSessionStateDateFirstDateFormatOption dateFirstDateFormatOption = new TDSSessionStateDateFirstDateFormatOption(); // Transfer properties from the session onto the session state dateFirstDateFormatOption.DateFirst = DateFirst; dateFirstDateFormatOption.DateFormat = DateFormat; // Register option with the collection options.Add(dateFirstDateFormatOption); // Allocate deadlock priority option TDSSessionStateDeadlockPriorityOption deadlockPriorityOption = new TDSSessionStateDeadlockPriorityOption(); // Transfer properties from the session onto the session state deadlockPriorityOption.Value = (sbyte)DeadlockPriority; // Register option with the collection options.Add(deadlockPriorityOption); // Allocate lock timeout option TDSSessionStateLockTimeoutOption lockTimeoutOption = new TDSSessionStateLockTimeoutOption(); // Transfer properties from the session onto the session state lockTimeoutOption.Value = LockTimeout; // Register option with the collection options.Add(lockTimeoutOption); // Allocate ISO fips option TDSSessionStateISOFipsOption isoFipsOption = new TDSSessionStateISOFipsOption(); // Transfer properties from the session onto the session state isoFipsOption.TransactionIsolationLevel = TransactionIsolationLevel; // Register option with the collection options.Add(isoFipsOption); // Allocate text size option TDSSessionStateTextSizeOption textSizeOption = new TDSSessionStateTextSizeOption(); // Transfer properties from the session onto the session state textSizeOption.Value = TextSize; // Register option with the collection options.Add(textSizeOption); // Check if context info is specified if (ContextInfo != null) { // Allocate context info option TDSSessionStateContextInfoOption contextInfoOption = new TDSSessionStateContextInfoOption(); // Transfer properties from the session onto the session state contextInfoOption.Value = ContextInfo; // Register option with the collection options.Add(isoFipsOption); } return options; }
/// <summary> /// Inflate the token /// </summary> /// <param name="source">Stream to inflate the token from</param> public override bool Inflate(Stream source) { // We skip the token identifier because it is read by token factory // Current inflation offset uint inflationOffset = 0; // Read the length of the token uint tokenLength = TDSUtilities.ReadUInt(source); // NOTE: Length is excluded from the token length // Check if we still have space left to read if (inflationOffset >= tokenLength) { // We read the whole token return(true); } // Read sequence number SequenceNumber = (int)TDSUtilities.ReadUInt(source); // Update inflation offset inflationOffset += sizeof(uint); // Check if we still have space left to read if (inflationOffset >= tokenLength) { // We read the whole token return(true); } // Read status byte status = (byte)source.ReadByte(); // Update inflation offset inflationOffset += sizeof(byte); // Check if we still have space left to read if (inflationOffset >= tokenLength) { // We read the whole token return(true); } // Parse status IsRecoverable = ((status & 0x01) != 0); // Read while we have data while (tokenLength > inflationOffset) { // Read a byte that identifies the session state slot byte stateID = (byte)source.ReadByte(); // Update current position inflationOffset += sizeof(byte); // Option being inflated TDSSessionStateOption option = null; // Dispatch inflation based on the state switch (stateID) { // UserOptionAll case TDSSessionStateUserOptionsOption.ID: { // Create a new option option = new TDSSessionStateUserOptionsOption(); break; } // DateFirstDateFormat case TDSSessionStateDateFirstDateFormatOption.ID: { // Create a new option option = new TDSSessionStateDateFirstDateFormatOption(); break; } // DbDeadlockPri case TDSSessionStateDeadlockPriorityOption.ID: { // Create a new option option = new TDSSessionStateDeadlockPriorityOption(); break; } // LockTimeout case TDSSessionStateLockTimeoutOption.ID: { // Create a new option option = new TDSSessionStateLockTimeoutOption(); break; } // IsoFips case TDSSessionStateISOFipsOption.ID: { // Create a new option option = new TDSSessionStateISOFipsOption(); break; } // TextSize case TDSSessionStateTextSizeOption.ID: { // Create a new option option = new TDSSessionStateTextSizeOption(); break; } // ContextInfo case TDSSessionStateContextInfoOption.ID: { // Create a new option option = new TDSSessionStateContextInfoOption(); break; } default: { // Create a new option option = new TDSSessionStateGenericOption(stateID); break; } } // Inflate the option option.Inflate(source); // Register option with the collection Options.Add(option); // Update current length with the inflation size of the data inflationOffset += option.InflationSize; } return(true); }
/// <summary> /// Inflate from stream /// </summary> public override bool Inflate(Stream source) { // Create options collection Options = new List<TDSSessionStateOption>(); // We skip feature ID because it was read by construction factory // Read the total length uint totalLength = TDSUtilities.ReadUInt(source); // Current position in the stream uint currentLength = 0; // Read while we have data while (totalLength > currentLength) { // Read a byte that identifies the session state slot byte stateID = (byte)source.ReadByte(); // Update current position currentLength += sizeof(byte); // Option being inflated TDSSessionStateOption option = null; // Dispatch inflation based on the state switch (stateID) { // UserOptionAll case TDSSessionStateUserOptionsOption.ID: { // Create a new option option = new TDSSessionStateUserOptionsOption(); break; } // DateFirstDateFormat case TDSSessionStateDateFirstDateFormatOption.ID: { // Create a new option option = new TDSSessionStateDateFirstDateFormatOption(); break; } // DbDeadlockPri case TDSSessionStateDeadlockPriorityOption.ID: { // Create a new option option = new TDSSessionStateDeadlockPriorityOption(); break; } // LockTimeout case TDSSessionStateLockTimeoutOption.ID: { // Create a new option option = new TDSSessionStateLockTimeoutOption(); break; } // IsoFips case TDSSessionStateISOFipsOption.ID: { // Create a new option option = new TDSSessionStateISOFipsOption(); break; } // TextSize case TDSSessionStateTextSizeOption.ID: { // Create a new option option = new TDSSessionStateTextSizeOption(); break; } // ContextInfo case TDSSessionStateContextInfoOption.ID: { // Create a new option option = new TDSSessionStateContextInfoOption(); break; } default: { // Create a new option option = new TDSSessionStateGenericOption(stateID); break; } } // Inflate the option option.Inflate(source); // Register option with the collection Options.Add(option); // Update current length with the inflation size of the data currentLength += option.InflationSize; } // Inflation is complete return true; }
/// <summary> /// Inflate the token /// </summary> /// <param name="source">Stream to inflate the token from</param> public override bool Inflate(Stream source) { // We skip the token identifier because it is read by token factory // Current inflation offset uint inflationOffset = 0; // Read the length of the token uint tokenLength = TDSUtilities.ReadUInt(source); // NOTE: Length is excluded from the token length // Check if we still have space left to read if (inflationOffset >= tokenLength) { // We read the whole token return true; } // Read sequence number SequenceNumber = (int)TDSUtilities.ReadUInt(source); // Update inflation offset inflationOffset += sizeof(uint); // Check if we still have space left to read if (inflationOffset >= tokenLength) { // We read the whole token return true; } // Read status byte status = (byte)source.ReadByte(); // Update inflation offset inflationOffset += sizeof(byte); // Check if we still have space left to read if (inflationOffset >= tokenLength) { // We read the whole token return true; } // Parse status IsRecoverable = ((status & 0x01) != 0); // Read while we have data while (tokenLength > inflationOffset) { // Read a byte that identifies the session state slot byte stateID = (byte)source.ReadByte(); // Update current position inflationOffset += sizeof(byte); // Option being inflated TDSSessionStateOption option = null; // Dispatch inflation based on the state switch (stateID) { // UserOptionAll case TDSSessionStateUserOptionsOption.ID: { // Create a new option option = new TDSSessionStateUserOptionsOption(); break; } // DateFirstDateFormat case TDSSessionStateDateFirstDateFormatOption.ID: { // Create a new option option = new TDSSessionStateDateFirstDateFormatOption(); break; } // DbDeadlockPri case TDSSessionStateDeadlockPriorityOption.ID: { // Create a new option option = new TDSSessionStateDeadlockPriorityOption(); break; } // LockTimeout case TDSSessionStateLockTimeoutOption.ID: { // Create a new option option = new TDSSessionStateLockTimeoutOption(); break; } // IsoFips case TDSSessionStateISOFipsOption.ID: { // Create a new option option = new TDSSessionStateISOFipsOption(); break; } // TextSize case TDSSessionStateTextSizeOption.ID: { // Create a new option option = new TDSSessionStateTextSizeOption(); break; } // ContextInfo case TDSSessionStateContextInfoOption.ID: { // Create a new option option = new TDSSessionStateContextInfoOption(); break; } default: { // Create a new option option = new TDSSessionStateGenericOption(stateID); break; } } // Inflate the option option.Inflate(source); // Register option with the collection Options.Add(option); // Update current length with the inflation size of the data inflationOffset += option.InflationSize; } return true; }