/// <summary>
        /// The HandleSession_Logon method is invoked to handle
        /// a logon message that has been received from the peer
        /// session that this session is communicating with.
        /// </summary>
        /// <param name="msg">
        /// The FIX logon message received from the peer.
        /// </param>
        private void HandleSession_Logon(FixMessage msg)
        {
            // REC: Ensure that we're in the appropriate state
            // to handle a logon message:
            if (_currentState == SessionStates.Session_Pending || _currentState == SessionStates.Session_Closed)
            {
                // REC: Retrieve the FIX SenderCompID of the peer
                // from the logon message:
                FixField fldSenderCompID = msg.Header.GetField(49);
                if (fldSenderCompID != null)
                {
                    string rxSenderCompID = fldSenderCompID.Content;
                    if (string.IsNullOrEmpty(rxSenderCompID))
                    {
                        // HELP: Should the session send a reject message
                        // in this case, given that the peer didn't send
                        // its FIX SenderCompID, or should this throw an
                        // argument exception?
                    }

                    // REC: Transition to the opened state:
                    _currentState = SessionStates.Session_Opened;

                    // REC: Notify the session's owner that the session
                    // has received the logon response from the server:
                    _handler.OnSessionLogon(this, msg);
                }
                else
                {
                    // REC: Throw an exception since the session has not
                    // yet been established and there will be no handler
                    // at the application level that can deal with this:
                    throw new ArgumentException("Logon message missing required field - SenderCompID.");
                }
            }
            else
            {
                // REC: Notify the session handler that an
                // administrative message has been received
                // from the peer session:
                _handler.OnSessionRxAdmMessage(this, msg);

                // REC: Throw an exception that indicates the
                // session is not in the appropriate state to
                // handle the received message:
                throw new InvalidOperationException("Session state invalid for received message.");
            }
        }
        /// <summary>
        /// The HandleSession_Logon method is invoked to handle
        /// a logon message that has been received from the peer
        /// session that this session is communicating with.
        /// </summary>
        /// <param name="msg">
        /// The FIX logon message received from the peer.
        /// </param>
        private void HandleSession_Logon(FixMessage msg)
        {
            // REC: Ensure that we're in the appropriate state
            // to handle a logon message:
            if (_currentState == SessionStates.Session_Pending || _currentState == SessionStates.Session_Closed)
            {
                // REC: Retrieve the FIX SenderCompID of the peer
                // from the logon message:
                FixField fldSenderCompID = msg.Header.GetField(49);
                if (fldSenderCompID != null)
                {
                    // REC: The SenderCompID from the peer becomes the
                    // session's TargetCompID for outgoing messages:
                    _fixTargetCompID = fldSenderCompID.Content;

                    // REC: Now that the FIX SenderCompID of the peer
                    // session is known, it is used to construct the
                    // identifier for the session - used to retrieve
                    // the session's details from the database:
                    _sessionId = string.Format("{0}-{1}", _fixSenderCompID, _fixTargetCompID);

                    // REC: Attempt to retrieve the session details
                    // from the session database:
                    if (_fixDatabase != null)
                    {
                        // REC: Note that once a session record is acquired
                        // from the database, it must be released when it is
                        // no longer needed by the session instance...
                        _sessionRecord = _fixDatabase.AcquireSession(_sessionId);
                        if (this._resetSequence == true)
                        {
                            _sessionRecord.RxSequence = 1;
                            _sessionRecord.TxSequence = 1;
                        }
                    }

                    // REC: Register the peer session's SenderCompID as
                    // the TargetCompID for outgoing messages:
                    _fixAssembler.SetField(new FixField(56, _fixTargetCompID));

                    // REC: Assemble the response message:
                    FixMessage response = _fixAssembler.CreateMessage(_sxVersion, _axVersion, "A");

                    // REC: Handle the sequence number reset flag
                    // if it is present in the logon message:
                    FixField fieldReset = msg.GetField(141);
                    if (fieldReset != null)
                    {
                        response.AddField(new FixField(141, "Y"));
                    }

                    // REC: Transition to the opened state:
                    _currentState = SessionStates.Session_Opened;

                    // REC: Notify the session's owner that the peer
                    // session has sent the logon request:
                    _handler.OnSessionLogon(this, msg);

                    // REC: Dispatch the administrative message out
                    // to the session's owner:
                    Dispatch_AdmMessage(response);
                }
                else
                {
                    // REC: Throw an exception since the session has not
                    // yet been established and there will be no handler
                    // at the application level that can deal with this:
                    throw new ArgumentException("Logon message missing required field - SenderCompID.");
                }
            }
            else
            {
                // REC: Notify the session handler that an
                // administrative message has been received
                // from the peer session:
                _handler.OnSessionRxAdmMessage(this, msg);

                // REC: Throw an exception that indicates the
                // session is not in the appropriate state to
                // handle the received message:

                //throw new InvalidOperationException("Session state invalid for received message.");
            }
        }