Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <summary>
        /// Inflate recovery data
        /// </summary>
        private void _InflateRecoveryData(TDSSessionRecoveryData data)
        {
            // Check if database is available
            if (data.Database != null)
            {
                // Apply database
                Database = data.Database;
            }

            // Check if language is available
            if (data.Language != null)
            {
                // Apply language
                Language = LanguageString.ToEnum(data.Language);
            }

            // Check if collation is available
            if (data.Collation != null)
            {
                Collation = data.Collation;
            }

            // Traverse all session states and inflate each separately
            foreach (TDSSessionStateOption option in data.Options)
            {
                // Check on the options
                if (option is TDSSessionStateUserOptionsOption)
                {
                    // Cast to specific option
                    TDSSessionStateUserOptionsOption specificOption = option as TDSSessionStateUserOptionsOption;

                    // Transfer properties from the session state onto the session
                    AnsiWarnings            = specificOption.AnsiWarnings;
                    AnsiNulls               = specificOption.AnsiNulls;
                    CursorCloseOnCommit     = specificOption.CursorCloseOnCommit;
                    QuotedIdentifier        = specificOption.QuotedIdentifier;
                    ConcatNullYieldsNull    = specificOption.ConcatNullYieldsNull;
                    AnsiNullDefaultOn       = specificOption.AnsiNullDefaultOn;
                    AnsiPadding             = specificOption.AnsiPadding;
                    ArithAbort              = specificOption.ArithAbort;
                    TransactionAbortOnError = specificOption.TransactionAbortOnError;
                    NoCount              = specificOption.NoCount;
                    ArithIgnore          = specificOption.ArithIgnore;
                    ImplicitTransactions = specificOption.ImplicitTransactions;
                    NumericRoundAbort    = specificOption.NumericRoundAbort;
                }
                else if (option is TDSSessionStateDateFirstDateFormatOption)
                {
                    // Cast to specific option
                    TDSSessionStateDateFirstDateFormatOption specificOption = option as TDSSessionStateDateFirstDateFormatOption;

                    // Transfer properties from the session state onto the session
                    DateFirst  = specificOption.DateFirst;
                    DateFormat = specificOption.DateFormat;
                }
                else if (option is TDSSessionStateDeadlockPriorityOption)
                {
                    // Cast to specific option
                    TDSSessionStateDeadlockPriorityOption specificOption = option as TDSSessionStateDeadlockPriorityOption;

                    // Transfer properties from the session state onto the session
                    DeadlockPriority = specificOption.Value;
                }
                else if (option is TDSSessionStateLockTimeoutOption)
                {
                    // Cast to specific option
                    TDSSessionStateLockTimeoutOption specificOption = option as TDSSessionStateLockTimeoutOption;

                    // Transfer properties from the session state onto the session
                    LockTimeout = specificOption.Value;
                }
                else if (option is TDSSessionStateISOFipsOption)
                {
                    // Cast to specific option
                    TDSSessionStateISOFipsOption specificOption = option as TDSSessionStateISOFipsOption;

                    // Transfer properties from the session state onto the session
                    TransactionIsolationLevel = specificOption.TransactionIsolationLevel;
                }
                else if (option is TDSSessionStateTextSizeOption)
                {
                    // Cast to specific option
                    TDSSessionStateTextSizeOption specificOption = option as TDSSessionStateTextSizeOption;

                    // Transfer properties from the session state onto the session
                    TextSize = specificOption.Value;
                }
                else if (option is TDSSessionStateContextInfoOption)
                {
                    // Cast to specific option
                    TDSSessionStateContextInfoOption specificOption = option as TDSSessionStateContextInfoOption;

                    // Transfer properties from the session state onto the session
                    ContextInfo = specificOption.Value;
                }
            }
        }
Пример #3
0
        /// <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);
        }