/// <summary>
        /// Update SMB_COM_NT_CREATE_ANDX response.
        /// </summary>
        /// <param name="connection">It represents the SMB connection.</param>
        /// <param name="messageId">This is used to associate a response with a request.</param>
        /// <param name="fId">The SMB file identifier of the target directory.</param>
        /// <param name="createAction">The action taken for the specified file.</param>
        public static void UpdateCreateResponse(
            SmbConnection connection,
            int messageId,
            int fId,
            List <CreateAction> createAction)
        {
            CreateRequest request  = (CreateRequest)connection.sentRequest[messageId];
            bool          isOpened = false;

            if (createAction.Contains(CreateAction.FileCreated) || createAction.Contains(CreateAction.FileSuperseded))
            {
                isOpened = false;
            }
            else if (createAction.Contains(CreateAction.FileOpened) ||
                     createAction.Contains(CreateAction.FileOverwritten))
            {
                isOpened = true;
            }

            switch (request.shareType)
            {
            case ShareType.Disk:
                SmbFile file = new SmbFile(
                    request.shareType,
                    request.name,
                    request.treeId,
                    request.desiredAccess,
                    isOpened);
                Console.WriteLine(fId);
                connection.openedFiles.Add(fId, file);
                break;

            case ShareType.NamedPipe:
                if (Parameter.pipeNames.Contains(request.name))
                {
                    SmbPipe pipe = new SmbPipe(
                        request.shareType,
                        request.name,
                        request.treeId,
                        request.desiredAccess,
                        isOpened);
                    connection.openedPipes.Add(fId, pipe);
                    connection.openedPipes[fId].isRequireReadModePipeState = Parameter.isMessageModePipe;
                }
                else if (Parameter.mailslotNames.Contains(request.name))
                {
                    SmbMailslot mailslot = new SmbMailslot(
                        request.shareType,
                        request.name,
                        request.treeId,
                        request.desiredAccess,
                        isOpened);
                    connection.openedMailslots.Add(fId, mailslot);
                }
                break;

            default:
                break;
            }

            connection.SutSendSequenceNumber.Remove(messageId);
            connection.sentRequest.Remove(messageId);
            connection.SutNextReceiveSequenceNumber++;
            connection.fId++;
        }
        public static void Trans2FindNext2Response(
            int messageId,
            int sessionId,
            int treeId,
            bool isSigned,
            bool isFileIdEqualZero,
            MessageStatus messageStatus)
        {
            Trans2FindNext2Request request = null;
            Checker.CheckResponse<Microsoft.Protocol.TestSuites.Smb.Trans2FindNext2Request>(
                smbConnection,
                messageId,
                sessionId,
                treeId,
                isSigned,
                messageStatus,
                out request,
                MessageStatus.Success);
            Condition.IsTrue(request.command == Command.TransFindNext2);

            if (messageStatus == MessageStatus.Success)
            {
                ModelHelper.CaptureRequirement(
                    9287,
                    "[In response. Extensions]The server MUST send a TRANS2_FIND_NEXT2 response in reply to a client " +
                    "TRANS2_FIND_NEXT2 subcommand request when the request is successful.");
            }
            Condition.IsTrue(request.treeId == treeId);
            Condition.IsTrue(request.gmtTokenIndex != -1);

            //[Flags2 (2 bytes): SMB_FLAGS2_KNOWS_LONG_NAMES]If a client does not support long names
            // (i.e. SMB2_FLAGS2_KNOWS_LONG_NAMES is not set), than any TRANS_FIND_FIRST2/FIND_NEXT2 request with an
            // information level other than SMB_INFO_STANDARD MUST be failed with STATUS_INVALID_PARAMETER.
            if (request.informationLevel != InformationLevel.SmbInfoStandard)
            {
                Condition.IsTrue(request.isFlagsKnowsLongNameSet);
            }

            SmbFile file = new SmbFile();
            foreach (SmbFile searchFile in smbConnection.openedFiles.Values)
            {
                foreach (int i in searchFile.previousVersionToken)
                {
                    if (request.gmtTokenIndex == i)
                    {
                        file = searchFile;
                        file.searchHandlerList.Remove(request.searchHandlerId);
                        break;
                    }
                }
            }

            switch (request.informationLevel)
            {
                case InformationLevel.SmbFindFileIdFullDirectoryInfo:
                    // Parameter.isSupportUniqueFileId is configured in ServerSetup action, and the SUT is configured
                    // according to this.
                    if (!Parameter.isSupportUniqueFileId)
                    {
                        Condition.IsTrue(isFileIdEqualZero);
                    }
                    break;
                case InformationLevel.SmbFindFileIdBothDirectoryInfo:
                    // Parameter.isSupportUniqueFileId is configured in ServerSetup action, and the SUT is configured
                    // according to this.
                    if (!Parameter.isSupportUniqueFileId)
                    {
                        Condition.IsTrue(isFileIdEqualZero);
                    }
                    break;
                default:
                    break;
            }
            Update.UpdateResponse(smbConnection, messageId);
        }
        public static void Trans2FindFirst2Response(
            int messageId,
            int sessionId,
            int treeId,
            bool isSigned,
            bool isFileIdEqualZero,
            int searchHandlerId,
            bool isReturnEnumPreviousVersion,
            MessageStatus messageStatus,
            bool isRs2398Implemented,
            bool isRs4899Implemented)
        {
            Trans2FindFirst2Request request;
            Checker.CheckResponse<Microsoft.Protocol.TestSuites.Smb.Trans2FindFirst2Request>(
                smbConnection,
                messageId,
                sessionId,
                treeId,
                isSigned,
                messageStatus,
                out request,
                MessageStatus.Success);
            Condition.IsTrue(request.command == Command.TransFindFirst2);
            Condition.IsTrue(request.treeId == treeId);
            Condition.IsTrue(request.gmtTokenIndex != -1);

            // [Flags2 (2 bytes): SMB_FLAGS2_KNOWS_LONG_NAMES]If a client does not support long names
            // (i.e. SMB2_FLAGS2_KNOWS_LONG_NAMES is not set), then any TRANS_FIND_FIRST2/FIND_NEXT2 request with an
            // information level other than SMB_INFO_STANDARD MUST be failed with STATUS_INVALID_PARAMETER.
            if (request.informationLevel != InformationLevel.SmbInfoStandard)
            {
                Condition.IsTrue(request.isFlagsKnowsLongNameSet);
            }

            if (request.informationLevel == InformationLevel.SmbFindFileIdFullDirectoryInfo
                    || request.informationLevel == InformationLevel.SmbFindFileIdBothDirectoryInfo)
            {
                ModelHelper.CaptureRequirement(
                    30038,
                    @"[InReceiving a TRANS2_FIND_FIRST2 Request New Information Levels] <123> Section 3.3.5.9.2:
                    Windows servers support these new Information Levels for directory queries.");
            }
            if (messageStatus == MessageStatus.Success)
            {
                ModelHelper.CaptureRequirement(
                    9281,
                    "[In  response. Extensions]A server MUST send a TRANS2_FIND_FIRST2 response in reply to a client " +
                    "TRANS2_FIND_FIRST2 subcommand request when the request is successful, as specified in [MS-CIFS] " +
                    "section 2.2.6.2.2.");
            }

            SmbFile file = new SmbFile();
            foreach (SmbFile searchFile in smbConnection.openedFiles.Values)
            {
                foreach (int i in searchFile.previousVersionToken)
                {
                    if (request.gmtTokenIndex == i)
                    {
                        file = searchFile;
                        Condition.IsTrue(searchHandlerId == i);
                        file.searchHandlerList.Add(searchHandlerId);
                        smbConnection.searchHandlerContainer.Add(searchHandlerId, request.gmtTokenIndex);
                        break;
                    }
                }
            }
            if (request.informationLevel == InformationLevel.SmbFindFileBothDirectoryInfo && request.isGmtPatten)
            {
                if (Parameter.sutPlatform != Platform.NonWindows
                        && Parameter.sutPlatform != Platform.Win2K3
                        && Parameter.sutPlatform != Platform.Win2K3R2
                        && Parameter.sutPlatform != Platform.Win2K8
                        && Parameter.sutPlatform != Platform.Win2K8R2)
                {
                    if (isRs4899Implemented && !isReturnEnumPreviousVersion)
                    {
                        // Though it doesn't return enumeration of the previous version, the operation also succeeds,
                        // and we can determine the SUT process as a normal FindFirst operation.
                        ModelHelper.CaptureRequirement(
                            4899,
                            "[In Receiving a TRANS2_FIND_FIRST2 Request Enumerating the previous versions]If a scan for " +
                            "the previous version tokens (section 3.3.5.1.1) reveals that the FileName of the " +
                            "TRANS_FIND_FIRST2 request contains the search pattern @GMT-* and the requested Information " +
                            "Level is SMB_FIND_FILE_BOTH_DIRECTORY_INFO, then the server MAY<125> choose to return an " +
                            "enumeration of the previous versions that are valid for the share.");
                    }
                }
            }
            else
            {
                if (!isReturnEnumPreviousVersion)
                {
                    ModelHelper.CaptureRequirement(
                        2402,
                        "[In Receiving a TRANS2_FIND_FIRST2 Request Enumerating the previous versions]If the server " +
                        "chooses not to do this [return an enumeration of the previous versions valid for the share], " +
                        "then the enumeration MUST be processed as a normal TRANS2_FIND_FIRST2 operation.");
                }
            }

            switch (request.informationLevel)
            {
                case InformationLevel.SmbFindFileIdFullDirectoryInfo:
                    // Parameter.isSupportUniqueFileId is configured in ServerSetup action, and the SUT is configured
                    // according to this.
                    if (!Parameter.isSupportUniqueFileId)
                    {
                        Condition.IsTrue(isFileIdEqualZero);
                    }
                    if (Parameter.sutPlatform == Platform.WinNt
                            || Parameter.sutPlatform == Platform.Win2K
                            || Parameter.sutPlatform == Platform.Win2K3
                            || Parameter.sutPlatform == Platform.Win2K8
                            || Parameter.sutPlatform == Platform.Win2K8R2)
                    {
                        if (isRs2398Implemented)
                        {
                            ModelHelper.CaptureRequirement(
                                2398,
                                @"[In Receiving a TRANS2_FIND_FIRST2 Request New Information Levels]The server SHOULD
                                allow for the new Information Levels, as specified in section 2.2.2.3.1.");
                        }
                    }
                    break;
                case InformationLevel.SmbFindFileIdBothDirectoryInfo:
                    // Parameter.isSupportUniqueFileId is configured in ServerSetup action, and the SUT is configured
                    // according to this.
                    if (!Parameter.isSupportUniqueFileId)
                    {
                        Condition.IsTrue(isFileIdEqualZero);
                    }
                    if (Parameter.sutPlatform == Platform.WinNt
                        || Parameter.sutPlatform == Platform.Win2K
                        || Parameter.sutPlatform == Platform.Win2K3
                        || Parameter.sutPlatform == Platform.Win2K8
                        || Parameter.sutPlatform == Platform.Win2K8R2)
                    {
                        if (isRs2398Implemented)
                        {
                            ModelHelper.CaptureRequirement(
                                2398,
                                @"[In Receiving a TRANS2_FIND_FIRST2 Request New Information Levels]The server SHOULD
                                allow for the new Information Levels, as specified in section 2.2.2.3.1.");

                            if (Parameter.sutPlatform != Platform.NonWindows)
                            {
                                ModelHelper.CaptureRequirement(
                                    102398,
                                    @"[In Receiving a TRANS2_FIND_FIRST2 Request New Information Levels]The server
                                    allows for the new Information Levels, as specified in section 2.2.2.3.1 in
                                    Windows.");
                            }
                        }
                    }
                    Requirement.AssumeCaptured(
                        "FileIndex (4 bytes): This field MUST be set to 0 when sending a response");
                    break;
                case InformationLevel.SmbFindFileBothDirectoryInfo:
                    break;
                default:
                    break;
            }
            Update.UpdateResponse(smbConnection, messageId);
        }
        /// <summary>
        /// Update SMB_COM_NT_CREATE_ANDX response.
        /// </summary>
        /// <param name="connection">It represents the SMB connection.</param>
        /// <param name="messageId">This is used to associate a response with a request.</param>
        /// <param name="fId">The SMB file identifier of the target directory.</param>
        /// <param name="createAction">The action taken for the specified file.</param>
        public static void UpdateCreateResponse(
            SmbConnection connection, 
            int messageId, 
            int fId, 
            Set<CreateAction> createAction)
        {
            CreateRequest request = (CreateRequest)connection.sentRequest[messageId];
            bool isOpened = false;
            if(createAction.Contains(CreateAction.FileCreated) || createAction.Contains(CreateAction.FileSuperseded))
            {
                isOpened = false;
            }
            else if(createAction.Contains(CreateAction.FileOpened)
                        || createAction.Contains(CreateAction.FileOverwritten ))
            {
                isOpened = true;
            }

            switch (request.shareType)
            {
                case ShareType.Disk:
                    SmbFile file = new SmbFile(
                        request.shareType,
                        request.name,
                        request.treeId,
                        request.desiredAccess,
                        isOpened);
                    Console.WriteLine(fId);
                    connection.openedFiles.Add(fId, file);
                    break;
                case ShareType.NamedPipe:
                    if(Parameter.pipeNames.Contains(request.name))
                    {
                        SmbPipe pipe = new SmbPipe(
                            request.shareType,
                            request.name,
                            request.treeId,
                            request.desiredAccess,
                            isOpened);
                        connection.openedPipes.Add(fId, pipe);
                        connection.openedPipes[fId].isRequireReadModePipeState = Parameter.isMessageModePipe;
                    }
                    else if(Parameter.mailslotNames.Contains(request.name))
                    {
                        SmbMailslot mailslot = new SmbMailslot(
                            request.shareType,
                            request.name,
                            request.treeId,
                            request.desiredAccess,
                            isOpened);
                        connection.openedMailslots.Add(fId,mailslot);
                    }
                    break;
                default:
                    break;
            }

            connection.SutSendSequenceNumber.Remove(messageId);
            connection.sentRequest.Remove(messageId);
            connection.SutNextReceiveSequenceNumber++;
            connection.fId++;
        }