/// <summary>
        /// Define the scope and parameters of the synchronization download operation. 
        /// </summary>
        /// <param name="serverId">A 32-bit signed integer represent the Identity of server.</param>
        /// <param name="folderHandleIndex">The server object handle index.</param>
        /// <param name="synchronizationType">The type of synchronization requested: contents or hierarchy.</param>
        /// <param name="option">Defines the parameters of a download operation.</param>
        /// <param name="synchronizationFlag">Flag structure that defines the parameters of the synchronization operation.</param>
        /// <param name="synchronizationExtraFlag">Extra flag structure that defines the parameters of the synchronization operation.</param>
        /// <param name="property">A list of properties and subobjects to exclude or include.</param>
        /// <param name="downloadcontextHandleIndex">Synchronization download context handle index.</param>
        /// <returns>Indicate the result of this ROP operation.</returns>
        public RopResult SynchronizationConfigure(int serverId, int folderHandleIndex, SynchronizationTypes synchronizationType, SendOptionAlls option, SynchronizationFlag synchronizationFlag, SynchronizationExtraFlag synchronizationExtraFlag, Sequence<string> property, out int downloadcontextHandleIndex)
        {
            // Initialize ROP data.
            downloadcontextHandleIndex = -1;
            uint objHandle = this.handleContainer[folderHandleIndex];
            RopSynchronizationConfigureRequest synchronizationConfigureRequest;
            RopResult result = RopResult.InvalidParameter;
            switch (synchronizationType)
            {
                case SynchronizationTypes.Hierarchy:
                    this.streamType = FastTransferStreamType.hierarchySync;
                    break;
                case SynchronizationTypes.Contents:
                    this.streamType = FastTransferStreamType.contentsSync;
                    break;
                default:
                    break;
            }

            PropertyTag[] propertyTags = new PropertyTag[property.Count];
            for (int i = 0; i < property.Count; i++)
            {
                propertyTags[i] = this.propertyTagsDictionary[property[i]];
            }

            this.synchroniztionFlag = synchronizationFlag;
            this.propertyTagForConfigure = propertyTags[0];

            // Construct RopSynchronizationConfigure request.
            synchronizationConfigureRequest.RopId = (byte)RopId.RopSynchronizationConfigure;
            synchronizationConfigureRequest.LogonId = 0x00;
            synchronizationConfigureRequest.InputHandleIndex = 0x00;
            synchronizationConfigureRequest.OutputHandleIndex = 0x01;

            // 0x01,Indicates a contents synchronization.0x02,Indicates a hierarchy synchronization.
            synchronizationConfigureRequest.SynchronizationType = (byte)synchronizationType;
            synchronizationConfigureRequest.SendOptions = (byte)option;

            // Unicode 
            synchronizationConfigureRequest.SynchronizationFlags = (ushort)synchronizationFlag;
            if (synchronizationType == SynchronizationTypes.Contents)
            {
                // Set RestrictionDataSize to 0x0000 to avoid the complex RestrictionData.
                synchronizationConfigureRequest.RestrictionDataSize = 0x0005;

                // If PidTagMessageClass exists 
                synchronizationConfigureRequest.RestrictionData = new byte[] { 0x08, 0x1f, 0x00, 0x1a, 0x00 };
            }
            else
            {
                // Set RestrictionDataSize to 0x0000 to avoid the complex RestrictionData.
                synchronizationConfigureRequest.RestrictionDataSize = 0x0000;
                synchronizationConfigureRequest.RestrictionData = new byte[0];
            }

            synchronizationConfigureRequest.SynchronizationExtraFlags = (byte)synchronizationExtraFlag;
            synchronizationConfigureRequest.PropertyTagCount = (ushort)propertyTags.Length;
            synchronizationConfigureRequest.PropertyTags = propertyTags;

            if (this.Process(serverId, synchronizationConfigureRequest, objHandle) is RopSynchronizationConfigureResponse)
            {
                // Send request and get response.
                RopSynchronizationConfigureResponse synchronizationConfigureResponse = (RopSynchronizationConfigureResponse)this.Process(serverId, synchronizationConfigureRequest, objHandle);
                result = (RopResult)synchronizationConfigureResponse.ReturnValue;

                if (result == RopResult.Success)
                {
                    downloadcontextHandleIndex = AdapterHelper.GetHandleIndex();
                    this.handleContainer.Add(downloadcontextHandleIndex, this.responseSOHs[synchronizationConfigureResponse.OutputHandleIndex]);

                    if ((synchronizationExtraFlag & SynchronizationExtraFlag.OrderByDeliveryTime) != SynchronizationExtraFlag.OrderByDeliveryTime)
                    {
                        this.isOrderByDeliveryTimeExtraFlagNotSet = true;
                    }

                    if (this.lastChangeMadeByServer && (synchronizationExtraFlag & SynchronizationExtraFlag.CN) == SynchronizationExtraFlag.CN)
                    {
                        this.lastChangeMadeByClient = true;
                    }
                }

                // Verify ROP SynchronizationConfigure
                this.VerifyRopSynchronizationConfigure(synchronizationConfigureRequest, synchronizationConfigureResponse);
            }
            else
            {
                // If the response type is not RopSynchronizationConfigureResponse it must be that the process method throughout a FormatException when sending RPC request buffer.
                result = RopResult.RpcFormat;
            }

            return result;
        }
        /// <summary>
        /// Initializes a FastTransfer operation on a folder for downloading content and descendant subobjects for messages identified by a given set of IDs.
        /// </summary>
        /// <param name="serverId">A 32-bit signed integer represent the Identity of server.</param>
        /// <param name="sourceHandleIndex">Folder object handle index. </param>
        /// <param name="copyFlag">Defines parameters of the FastTransfer download operation.</param>
        /// <param name="option">Defines the parameters of a download operation.</param>
        /// <param name="messageIds">The list of MIDs the messages should copy.</param>
        /// <param name="copyMessageHandleIndex">The message handle index.</param>
        /// <returns>Indicate the result of this ROP operation.</returns>
        public RopResult FastTransferSourceCopyMessages(int serverId, int sourceHandleIndex, RopFastTransferSourceCopyMessagesCopyFlags copyFlag, SendOptionAlls option, Sequence<int> messageIds, out int copyMessageHandleIndex)
        {
            // Initialize ROP data
            RopResult result = RopResult.InvalidParameter;
            copyMessageHandleIndex = -1;
            this.streamType = FastTransferStreamType.MessageList;
            RopFastTransferSourceCopyMessagesRequest req;
            uint sourceHandle = this.handleContainer[sourceHandleIndex];
            ushort idcount = (ushort)messageIds.Count;
            ulong[] messageId = new ulong[idcount];
            int index = 0;
            foreach (int mID in messageIds)
            {
                messageId[index++] = this.objectIdContainer[mID];
            }

            // Construct ROP request.
            req.RopId = 0x4B;
            req.LogonId = 0x00;
            req.InputHandleIndex = 0x00;
            req.OutputHandleIndex = 0x01;
            req.MessageIdCount = idcount;
            req.MessageIds = messageId;
            req.CopyFlags = (byte)copyFlag;
            req.SendOptions = (byte)option;

            // Stores message id and copy flag
            this.previousOperation = EnumFastTransferOperation.FastTransferSourceCopyMessage;
            this.messageIdForFastTransferSourceCopyMessages = (long)messageId[0];
            this.copyFlagForFastTransferSourceCopyMessages = copyFlag;

            // Send request and get response.
            RopFastTransferSourceCopyMessagesResponse response = (RopFastTransferSourceCopyMessagesResponse)this.Process(serverId, req, sourceHandle);
            result = (RopResult)response.ReturnValue;

            if (result == RopResult.Success)
            {
                copyMessageHandleIndex = AdapterHelper.GetHandleIndex();
                this.handleContainer.Add(copyMessageHandleIndex, this.responseSOHs[response.OutputHandleIndex]);
            }

            // Verify ROP FastTransferSourceCopyMessages
            this.VerifyRopFastTransferSourceCopyMessages(req, response);

            return result;
        }
        /// <summary>
        /// Initializes a FastTransfer operation to download properties and descendant subobjects for a specified folder.
        /// </summary>
        /// <param name="serverId">A 32-bit signed integer represent the Identity of server.</param>
        /// <param name="sourceHandleIndex">Folder object handle index. </param>
        /// <param name="copyFlag">Defines parameters of the FastTransfer download operation.</param>
        /// <param name="option">Defines the parameters of a download operation.</param>
        /// <param name="copyFolderHandleIndex">The folder handle index.</param>
        /// <returns>Indicate the result of this ROP operation.</returns>
        public RopResult FastTransferSourceCopyFolder(int serverId, int sourceHandleIndex, CopyFolderCopyFlags copyFlag, SendOptionAlls option, out int copyFolderHandleIndex)
        {
            // Initialize return value.
            copyFolderHandleIndex = -1;
            RopResult result = RopResult.InvalidParameter;
            uint targetFolderHandle = this.handleContainer[sourceHandleIndex];

            // Move flag only used in exchangeServer2007
            if (!Common.IsRequirementEnabled(526001, this.Site) && copyFlag == CopyFolderCopyFlags.Move)
            {
                return result;
            }

            this.streamType = FastTransferStreamType.TopFolder;

            // Construct ROP request.
            RopFastTransferSourceCopyFolderRequest fastTransferSourceCopyFolderRequest;
            fastTransferSourceCopyFolderRequest.RopId = 0x4C;
            fastTransferSourceCopyFolderRequest.LogonId = 0x00;
            fastTransferSourceCopyFolderRequest.InputHandleIndex = 0x00;
            fastTransferSourceCopyFolderRequest.OutputHandleIndex = 0x01;
            fastTransferSourceCopyFolderRequest.CopyFlags = (byte)copyFlag;
            fastTransferSourceCopyFolderRequest.SendOptions = (byte)option;

            this.folderCopyFlag = copyFlag;

            // Send request and get response.
            RopFastTransferSourceCopyFolderResponse response = (RopFastTransferSourceCopyFolderResponse)this.Process(serverId, fastTransferSourceCopyFolderRequest, targetFolderHandle);
            result = (RopResult)response.ReturnValue;

            if (result == RopResult.Success)
            {
                copyFolderHandleIndex = AdapterHelper.GetHandleIndex();
                this.handleContainer.Add(copyFolderHandleIndex, this.responseSOHs[response.OutputHandleIndex]);
            }

            // Verify ROP FastTransferSourceCopyFolder
            this.VerifyRopFastTransferSourceCopyFolder(fastTransferSourceCopyFolderRequest, response);

            return result;
        }
        /// <summary>
        /// Initializes a FastTransfer operation to download content from a given messaging object and its descendant subobjects.
        /// </summary>
        /// <param name="serverId">A 32-bit signed integer represent the Identity of server.</param>
        /// <param name="sourceHandleIndex">Folder or message object handle index. </param>
        /// <param name="handleType">Type of object handle </param>
        /// <param name="level">Variable indicate whether copy the descendant subobjects.</param>
        /// <param name="copyFlag">Defines parameters of the FastTransfer download operation.</param>
        /// <param name="option">Defines the parameters of a download operation.</param>
        /// <param name="propertyTags">Array of properties and subobjects to exclude.</param>
        /// <param name="copyToHandleIndex">The properties handle index.</param>
        /// <returns>Indicate the result of this ROP operation.</returns>
        public RopResult FastTransferSourceCopyTo(int serverId, int sourceHandleIndex, InputHandleType handleType, bool level, CopyToCopyFlags copyFlag, SendOptionAlls option, Sequence<string> propertyTags, out int copyToHandleIndex)
        {
            // Initialize ROP returned value.
            RopResult result = RopResult.InvalidParameter;
            copyToHandleIndex = -1;
            ushort propertyCount = (ushort)propertyTags.Count;
            this.currentCopyFlag = copyFlag;

            // Get stream type.
            switch (handleType)
            {
                case InputHandleType.FolderHandle:
                    this.streamType = FastTransferStreamType.folderContent;
                    break;
                case InputHandleType.MessageHandle:
                    this.streamType = FastTransferStreamType.MessageContent;
                    break;
                case InputHandleType.AttachmentHandle:
                    this.streamType = FastTransferStreamType.attachmentContent;
                    break;
                default:
                    break;
            }

            // Initialize input propertyTags
            PropertyTag[] messagePropertyTags = new PropertyTag[propertyCount];
            for (int i = 0; i < propertyCount; i++)
            {
                messagePropertyTags[i] = this.propertyTagsDictionary[propertyTags[i]];
            }

            // Stores the values for further verification
            this.previousOperation = EnumFastTransferOperation.FastTransferSourceCopyTo;
            this.propertyTags = messagePropertyTags;

            // Construct ROP request.
            uint sourceHandle = this.handleContainer[sourceHandleIndex];
            RopFastTransferSourceCopyToRequest request;
            request.RopId = 0x4D;
            request.LogonId = 0X00;
            request.InputHandleIndex = 0x00;
            request.OutputHandleIndex = 0x01;

            // This value specifies the level at which the copy is occurring,Non-Zero: exclude all descendant subobjects from being copied
            request.Level = level ? (byte)1 : (byte)0;
            request.CopyFlags = (uint)copyFlag;
            request.SendOptions = (byte)option;
            request.PropertyTagCount = propertyCount;
            request.PropertyTags = messagePropertyTags;

            // Send request and get response.
            RopFastTransferSourceCopyToResponse response = (RopFastTransferSourceCopyToResponse)this.Process(serverId, request, sourceHandle);
            result = (RopResult)response.ReturnValue;

            if (result == RopResult.Success)
            {
                copyToHandleIndex = AdapterHelper.GetHandleIndex();
                this.handleContainer.Add(copyToHandleIndex, this.responseSOHs[response.OutputHandleIndex]);
            }

            // Verify ROP FastTransferSourceCopyTo
            this.VerifyRopFastTransferSourceCopyTo(request, response);

            return result;
        }
        /// <summary>
        /// Initializes a FastTransfer operation to download content from a given messaging object and its descendant subobjects.
        /// </summary>
        /// <param name="serverId">A 32-bit signed integer represent the Identity of server.</param>
        /// <param name="sourceHandleIndex">Folder or message object handle index. </param>
        /// <param name="handleType">Type of object handle. </param>
        /// <param name="level">Variable indicate whether copy the descendant subobjects.</param>
        /// <param name="copyFlag">Defines parameters of the FastTransfer download operation.</param>
        /// <param name="option">Defines the parameters of a download operation.</param>
        /// <param name="propertyTags">The list of properties and subobjects to exclude.</param>
        /// <param name="copyPropertiesHandleIndex">The properties handle index.</param>
        /// <returns>Indicate the result of this ROP operation.</returns>
        public RopResult FastTransferSourceCopyProperties(int serverId, int sourceHandleIndex, InputHandleType handleType, bool level, CopyPropertiesCopyFlags copyFlag, SendOptionAlls option, Sequence<string> propertyTags, out int copyPropertiesHandleIndex)
        {
            // Initialize ROP data.
            RopResult result = RopResult.InvalidParameter;
            RopFastTransferSourceCopyPropertiesRequest req;
            copyPropertiesHandleIndex = -1;
            uint sourceHandle = this.handleContainer[sourceHandleIndex];

            // Get stream type.
            switch (handleType)
            {
                case InputHandleType.FolderHandle:
                    this.streamType = FastTransferStreamType.folderContent;
                    break;
                case InputHandleType.MessageHandle:
                    this.streamType = FastTransferStreamType.MessageContent;
                    break;
                case InputHandleType.AttachmentHandle:
                    this.streamType = FastTransferStreamType.attachmentContent;
                    break;
                default:
                    break;
            }

            // Initialize input propertyTags.
            ushort propertyCount = (ushort)propertyTags.Count;
            PropertyTag[] messageSamplePropertyTags = new PropertyTag[propertyCount];
            for (int i = 0; i < propertyCount; i++)
            {
                messageSamplePropertyTags[i] = this.propertyTagsDictionary[propertyTags[i]];
            }

            this.previousOperation = EnumFastTransferOperation.FastTransferSourceCopyProperties;
            this.propertyTags = messageSamplePropertyTags;
            this.copySubObjects = !level;

            // Construct ROP request.
            req.RopId = 0x69;
            req.LogonId = 0x00;
            req.InputHandleIndex = 0x00;
            req.OutputHandleIndex = 0x01;

            // This value specifies the level at which the copy is occurring, which is specified in [MS-OXCROPS].
            req.Level = (byte)(level ? 1 : 0);

            req.CopyFlags = (byte)copyFlag;
            req.SendOptions = (byte)option;
            req.PropertyTagCount = propertyCount;
            req.PropertyTags = messageSamplePropertyTags;

            // Send request and get response.
            RopFastTransferSourceCopyPropertiesResponse response = (RopFastTransferSourceCopyPropertiesResponse)this.Process(serverId, req, sourceHandle);
            result = (RopResult)response.ReturnValue;

            if (result == RopResult.Success)
            {
                copyPropertiesHandleIndex = AdapterHelper.GetHandleIndex();
                this.handleContainer.Add(copyPropertiesHandleIndex, this.responseSOHs[response.OutputHandleIndex]);
            }

            // Verify ROP FastTransferSourceCopyProperties
            this.VerifyRopFastTransferSourceCopyProperties(req, response);

            return result;
        }
        public static RopResult SynchronizationConfigure(int serverId, int folderHandleIndex, SynchronizationTypes synchronizationType, SendOptionAlls option, SynchronizationFlag synchronizationFlag, SynchronizationExtraFlag synchronizationExtraFlag, Sequence<string> property, out int downloadcontextHandleIndex)
        {
            // The contractions conditions.
            Condition.IsTrue(connections.Count > 0);
            Condition.IsTrue(connections.Keys.Contains(serverId));
            Condition.IsTrue(connections[serverId].FolderContainer.Count > 0);

            // Initialize return value.
            RopResult result = RopResult.Success;
            downloadcontextHandleIndex = -1;

            if ((option & SendOptionAlls.Invalid) == SendOptionAlls.Invalid && (requirementContainer.ContainsKey(3463) && requirementContainer[3463]))
            {
                result = RopResult.InvalidParameter;
                return result;
            }

            // SynchronizationFlag MUST match the value of the Unicode flag from SendOptions field.
            if ((synchronizationFlag & SynchronizationFlag.Unicode) == SynchronizationFlag.Unicode)
            {
                Condition.IsTrue((option & SendOptionAlls.Unicode) == SendOptionAlls.Unicode);
            }

            // When SynchronizationType is 0X04 then Servers return 0x80070057.
            if (synchronizationType == SynchronizationTypes.InvalidParameter)
            {
                if (requirementContainer.ContainsKey(2695) && requirementContainer[2695])
                {
                    result = RopResult.NotSupported;
                }
                else
                {
                    result = RopResult.InvalidParameter;
                    ModelHelper.CaptureRequirement(2695, "[In Receiving a RopSynchronizationConfigure ROP Request] [SynchronizationType Constraints] Servers MUST return 0x80070057 if SynchronizationType is 0x04.");
                }
            }
            else if ((synchronizationFlag & SynchronizationFlag.Reserved) == SynchronizationFlag.Reserved)
            {
                // When SynchronizationType is Reserved then Servers MUST fail the ROP request.
                result = RopResult.RpcFormat;
                ModelHelper.CaptureRequirement(2180, "[In Receiving a RopSynchronizationConfigure ROP Request] [SynchronizationType Constraints] The server MUST fail the ROP request if the Reserved flag of the SynchronizationFlags field is set.");
            }
            else
            {
                // Get ConnectionData value.
                ConnectionData changeConnection = connections[serverId];

                // Identify whether the CurrentFolder is existent or not.
                bool isCurrentFolderExist = false;

                // Identify whether the Current Folder is existent or not.
                foreach (AbstractFolder tempfolder in changeConnection.FolderContainer)
                {
                    if (tempfolder.FolderHandleIndex == folderHandleIndex)
                    {
                        // Set the value to the variable when the current folder is existent.
                        isCurrentFolderExist = true;
                    }
                }

                // The condition of CurrentFolder is existent.
                if (isCurrentFolderExist)
                {
                    // Initialize the Download information.
                    AbstractDownloadInfo abstractDownloadInfo = new AbstractDownloadInfo
                    {
                        UpdatedState =
                            new AbstractUpdatedState
                            {
                                CnsetRead = new Set<int>(),
                                CnsetSeen = new Set<int>(),
                                CnsetSeenFAI = new Set<int>(),
                                IdsetGiven = new Set<int>()
                            },
                        DownloadHandleIndex = AdapterHelper.GetHandleIndex()
                    };

                    // Get the download Handle for download context.
                    downloadcontextHandleIndex = abstractDownloadInfo.DownloadHandleIndex;
                    ModelHelper.CaptureRequirement(669, "[In RopSynchronizationConfigure ROP Response Buffer]OutputServerObject: This value MUST be the synchronization download context.");

                    // Record the flags.
                    abstractDownloadInfo.Sendoptions = option;
                    abstractDownloadInfo.SynchronizationType = synchronizationType;
                    abstractDownloadInfo.Synchronizationflag = synchronizationFlag;
                    abstractDownloadInfo.SynchronizationExtraflag = synchronizationExtraFlag;

                    // Record the Property.
                    abstractDownloadInfo.Property = property;

                    // Record folder handle of related to the download context. 
                    abstractDownloadInfo.RelatedObjectHandleIndex = folderHandleIndex;
                    switch (synchronizationType)
                    {
                        // Record synchronizationType value for condition of Synchronization type is Contents.
                        case SynchronizationTypes.Contents:
                            abstractDownloadInfo.AbstractFastTransferStreamType = FastTransferStreamType.contentsSync;
                            abstractDownloadInfo.ObjectType = ObjectType.Folder;
                            break;

                        // Record synchronizationType value for condition of Synchronization type is Hierarchy.
                        case SynchronizationTypes.Hierarchy:
                            abstractDownloadInfo.AbstractFastTransferStreamType = FastTransferStreamType.hierarchySync;
                            abstractDownloadInfo.ObjectType = ObjectType.Folder;
                            break;
                        default:

                            // Condition ofsynchronizationType is invalid parameter.
                            result = RopResult.InvalidParameter;
                            break;
                    }

                    // Condition of the operation return success.
                    if (result == RopResult.Success)
                    {
                        // Add the  new value to DownloadContextContainer.
                        changeConnection.DownloadContextContainer = changeConnection.DownloadContextContainer.Add(abstractDownloadInfo);
                        connections[serverId] = changeConnection;
                        priorDownloadOperation = PriorDownloadOperation.RopSynchronizationConfigure;
                        priorOperation = MS_OXCFXICS.PriorOperation.RopSynchronizationConfigure;

                        ModelHelper.CaptureRequirement(
                            641,
                            @"[In RopSynchronizationConfigure] The RopSynchronizationConfigure ROP ([MS-OXCROPS] section 2.2.13.1) is used to define the synchronization scope and parameters of the synchronization download operation.");
                    }
                }
            }

            return result;
        }
        public static RopResult FastTransferSourceCopyFolder(int serverId, int folderHandleIndex, CopyFolderCopyFlags copyFlag, SendOptionAlls option, out int downloadContextHandleIndex)
        {
            // The contraction conditions.
            Condition.IsTrue(connections.Count > 0);
            Condition.IsTrue(connections.Keys.Contains(serverId));

            // Initialize the return value.
            RopResult result = RopResult.InvalidParameter;

            // Modify the logical
            if ((option == SendOptionAlls.Invalid && (requirementContainer.ContainsKey(3487) && requirementContainer[3487])) ||
                (copyFlag == CopyFolderCopyFlags.Invalid && (requirementContainer.ContainsKey(3483) && requirementContainer[3483])))
            {
                // SendOption is Invalid parameter and CopyFolderCopyFlags is Invalid parameter.
                downloadContextHandleIndex = -1;
                return result;
            }
            else if (copyFlag == CopyFolderCopyFlags.Move && (requirementContainer.ContainsKey(526001) && !requirementContainer[526001]))
            {
                downloadContextHandleIndex = -1;
                ModelHelper.CaptureRequirement(
                            526001,
                            @"[In Appendix A: Product Behavior] [CopyFlags] [When the flag name is Move, value is 0x01] Implementation does set the Move flag on a download operation to indicate the following: The server does not output any objects in a FastTransfer stream that the client does not have permissions to delete. <7> Section 2.2.3.1.1.4.1: In Exchange 2007, the Move bit flag is read by the server.");

                return result;
            }
            else
            {
                ConnectionData changeConnection = connections[serverId];

                // Identify whether the current folder is existent or not.
                bool isFolderExist = false;
                foreach (AbstractFolder tempFolder in changeConnection.FolderContainer)
                {
                    if (tempFolder.FolderHandleIndex == folderHandleIndex)
                    {
                        isFolderExist = true;
                    }
                }

                Condition.IsTrue(isFolderExist);

                // Create a new download context.
                AbstractDownloadInfo downloadInfo = new AbstractDownloadInfo();
                downloadContextHandleIndex = AdapterHelper.GetHandleIndex();
                downloadInfo.DownloadHandleIndex = downloadContextHandleIndex;
                connections.Remove(serverId);

                // Record the FastTransferOperation and Stream Type.
                downloadInfo.AbstractFastTransferStreamType = FastTransferStreamType.TopFolder;
                downloadInfo.RelatedFastTransferOperation = EnumFastTransferOperation.FastTransferSourceCopyFolder;
                priorDownloadOperation = PriorDownloadOperation.RopFastTransferSourceCopyFolder;

                // Set value for new download context.
                downloadInfo.CopyFolderCopyFlag = copyFlag;
                downloadInfo.Sendoptions = option;
                downloadInfo.ObjectType = ObjectType.Folder;
                downloadInfo.RelatedObjectHandleIndex = folderHandleIndex;

                // Add new download context to downloadContainer.
                changeConnection.DownloadContextContainer = changeConnection.DownloadContextContainer.Add(downloadInfo);
                connections.Add(serverId, changeConnection);

                result = RopResult.Success;

                // If the server returns success result, it means the RopFastTransferSourceCopyFolder ROP initializes the FastTransfer operation successfully. And then this requirement can be captured.
                ModelHelper.CaptureRequirement(
                            502,
                            @"[In RopFastTransferSourceCopyFolder ROP] The RopFastTransferSourceCopyFolder ROP ([MS-OXCROPS] section 2.2.12.4) initializes a FastTransfer operation to download properties and descendant subobjects for a specified folder.");
            }

            return result;
        }
        public static RopResult FastTransferSourceCopyMessages(int serverId, int objHandleIndex, RopFastTransferSourceCopyMessagesCopyFlags copyFlag, SendOptionAlls option, Sequence<int> messageIds, out int downloadContextHandleIndex)
        {
            // The contraction conditions
            Condition.IsTrue(connections.Count > 0);
            Condition.IsTrue(connections.Keys.Contains(serverId));

            // Initialize the return value.
            RopResult result = RopResult.InvalidParameter;
            if (option == SendOptionAlls.Invalid)
            {
                if (requirementContainer.ContainsKey(3479) && requirementContainer[3479])
                {
                    // SendOption flags value is invalid
                    downloadContextHandleIndex = -1;
                    return result;
                }
            }

            // Modify the logical
            if ((copyFlag & RopFastTransferSourceCopyMessagesCopyFlags.Unused3) == RopFastTransferSourceCopyMessagesCopyFlags.Unused3)
            {
                // CopyFlags is set to Unused3
                downloadContextHandleIndex = -1;
            }
            else
            {
                // Identify whether the current folder is existent or not.
                ConnectionData changeConnection = connections[serverId];
                bool isFolderExist = false;

                foreach (AbstractFolder tempFolder in changeConnection.FolderContainer)
                {
                    if (tempFolder.FolderHandleIndex == objHandleIndex)
                    {
                        isFolderExist = true;
                    }
                }

                Condition.IsTrue(isFolderExist);

                // Set value for new download context.
                AbstractDownloadInfo downloadInfo = new AbstractDownloadInfo();
                downloadContextHandleIndex = AdapterHelper.GetHandleIndex();
                downloadInfo.DownloadHandleIndex = downloadContextHandleIndex;

                connections.Remove(serverId);
                downloadInfo.AbstractFastTransferStreamType = FastTransferStreamType.MessageList;
                downloadInfo.CopyMessageCopyFlag = copyFlag;

                // Record the FastTransferOperation
                downloadInfo.RelatedFastTransferOperation = EnumFastTransferOperation.FastTransferSourceCopyMessage;
                priorDownloadOperation = PriorDownloadOperation.RopFastTransferSourceCopyMessage;

                // Set value for new download context.
                downloadInfo.Sendoptions = option;
                downloadInfo.RelatedObjectHandleIndex = objHandleIndex;
                downloadInfo.ObjectType = ObjectType.Folder;

                // Add new download context to DownloadContextContainer.
                changeConnection.DownloadContextContainer = changeConnection.DownloadContextContainer.Add(downloadInfo);
                connections.Add(serverId, changeConnection);
                priorOperation = MS_OXCFXICS.PriorOperation.RopFastTransferSourceCopyMessage;
                result = RopResult.Success;

                // If the server returns success result, it means the RopFastTransferSourceCopyMessages ROP initializes the FastTransfer operation successfully. And then this requirement can be captured.
                ModelHelper.CaptureRequirement(
                    3125,
                    @"[In RopFastTransferSourceCopyMessages ROP] The RopFastTransferSourceCopyMessages ROP ([MS-OXCROPS] section 2.2.12.5) initializes a FastTransfer operation on a folder for downloading content and descendant subobjects of messages identified by a set of MID structures ([MS-OXCDATA] section 2.2.1.2).");
            }

            return result;
        }
        public static RopResult FastTransferSourceCopyProperties(int serverId, int objHandleIndex, InputHandleType handleType, bool level, CopyPropertiesCopyFlags copyFlag, SendOptionAlls option, Sequence<string> propertyTags, out int downloadContextHandleIndex)
        {
            // The contraction conditions
            Condition.IsTrue(connections.Count > 0);
            Condition.IsTrue(connections.Keys.Contains(serverId));

            // Initialize the return value.
            RopResult result = RopResult.InvalidParameter;

            // SendOptionAll value is Invalid parameter 
            if ((option == SendOptionAlls.Invalid && (requirementContainer.ContainsKey(3470) && requirementContainer[3470])) ||
                (copyFlag == CopyPropertiesCopyFlags.Invalid && (requirementContainer.ContainsKey(3466) && requirementContainer[3466])))
            {
                downloadContextHandleIndex = -1;
            }
            else if (((copyFlag & CopyPropertiesCopyFlags.Move) == CopyPropertiesCopyFlags.Move) && (requirementContainer.ContainsKey(3466) && requirementContainer[3466]))
            {
                // CopyPropertiesCopyFlags value is Move.
                result = RopResult.NotImplemented;
                downloadContextHandleIndex = -1;
            }
            else
            {
                // Create a new download context.
                AbstractDownloadInfo downloadInfo = new AbstractDownloadInfo();
                ConnectionData changeConnection = connections[serverId];
                bool isObjExist = false;

                connections.Remove(serverId);
                if (handleType == InputHandleType.MessageHandle)
                {
                    foreach (AbstractMessage temp in changeConnection.MessageContainer)
                    {
                        if (temp.MessageHandleIndex == objHandleIndex)
                        {
                            isObjExist = true;
                        }
                    }

                    Condition.IsTrue(isObjExist);

                    // Set value for new download context.
                    downloadContextHandleIndex = AdapterHelper.GetHandleIndex();
                    downloadInfo.DownloadHandleIndex = downloadContextHandleIndex;
                    downloadInfo.AbstractFastTransferStreamType = FastTransferStreamType.MessageContent;

                    // Record the FastTransferOperation
                    downloadInfo.RelatedFastTransferOperation = EnumFastTransferOperation.FastTransferSourceCopyProperties;
                    priorDownloadOperation = PriorDownloadOperation.RopFastTransferSourceCopyProperties;

                    // Set value for new download context.
                    downloadInfo.CopyPropertiesCopyFlag = copyFlag;
                    downloadInfo.Property = propertyTags;
                    downloadInfo.Sendoptions = option;
                    downloadInfo.RelatedObjectHandleIndex = objHandleIndex;
                    downloadInfo.ObjectType = ObjectType.Message;
                    downloadInfo.IsLevelTrue = level;

                    // Add new download context to DownloadContextContainer.
                    changeConnection.DownloadContextContainer = changeConnection.DownloadContextContainer.Add(downloadInfo);
                }
                else if (handleType == InputHandleType.FolderHandle)
                {
                    // Find current folder.
                    foreach (AbstractFolder temp in changeConnection.FolderContainer)
                    {
                        if (temp.FolderHandleIndex == objHandleIndex)
                        {
                            isObjExist = true;
                        }
                    }

                    Condition.IsTrue(isObjExist);

                    // Set value for new download context.
                    downloadContextHandleIndex = AdapterHelper.GetHandleIndex();
                    downloadInfo.DownloadHandleIndex = downloadContextHandleIndex;
                    downloadInfo.AbstractFastTransferStreamType = FastTransferStreamType.folderContent;

                    // Record the FastTransferOperation
                    downloadInfo.RelatedFastTransferOperation = EnumFastTransferOperation.FastTransferSourceCopyProperties;
                    priorDownloadOperation = PriorDownloadOperation.RopFastTransferSourceCopyProperties;

                    // Set value for new download context.
                    downloadInfo.CopyPropertiesCopyFlag = copyFlag;
                    downloadInfo.Property = propertyTags;
                    downloadInfo.Sendoptions = option;
                    downloadInfo.RelatedObjectHandleIndex = objHandleIndex;
                    downloadInfo.ObjectType = ObjectType.Folder;

                    // Add new download context to DownloadContextContainer.
                    changeConnection.DownloadContextContainer = changeConnection.DownloadContextContainer.Add(downloadInfo);
                }
                else
                {
                    // Find the current Attachment
                    foreach (AbstractAttachment temp in changeConnection.AttachmentContainer)
                    {
                        if (temp.AttachmentHandleIndex == objHandleIndex)
                        {
                            isObjExist = true;
                        }
                    }

                    Condition.IsTrue(isObjExist);

                    // Set value for new download context.
                    downloadContextHandleIndex = AdapterHelper.GetHandleIndex();
                    downloadInfo.DownloadHandleIndex = downloadContextHandleIndex;
                    downloadInfo.AbstractFastTransferStreamType = FastTransferStreamType.attachmentContent;

                    // Record the FastTransferOperation
                    downloadInfo.RelatedFastTransferOperation = EnumFastTransferOperation.FastTransferSourceCopyProperties;
                    priorDownloadOperation = PriorDownloadOperation.RopFastTransferSourceCopyProperties;

                    // Set value for new download context.
                    downloadInfo.CopyPropertiesCopyFlag = copyFlag;
                    downloadInfo.Property = propertyTags;
                    downloadInfo.Sendoptions = option;
                    downloadInfo.ObjectType = ObjectType.Attachment;
                    downloadInfo.RelatedObjectHandleIndex = objHandleIndex;

                    // Add new download context to DownloadContextContainer.
                    changeConnection.DownloadContextContainer = changeConnection.DownloadContextContainer.Add(downloadInfo);
                }

                connections.Add(serverId, changeConnection);
                result = RopResult.Success;

                // If the server returns success result, it means the RopFastTransferSourceCopyProperties ROP initializes the FastTransfer operation successfully. And then this requirement can be captured.
                ModelHelper.CaptureRequirement(
                    431,
                    @"[In RopFastTransferSourceCopyProperties ROP] The RopFastTransferSourceCopyProperties ROP ([MS-OXCROPS] section 2.2.12.7) initializes a FastTransfer operation to download content from a specified messaging object and its descendant sub objects.");
            }

            return result;
        }
        public static RopResult FastTransferSourceCopyTo(int serverId, int objHandleIndex, InputHandleType handleType, bool level, CopyToCopyFlags copyFlag, SendOptionAlls option, Sequence<string> propertyTags, out int downloadContextHandleIndex)
        {
            // The contraction conditions.
            Condition.IsTrue(connections.Count > 0);
            Condition.IsTrue(connections.Keys.Contains(serverId));

            // Initialize the return value.
            RopResult result = RopResult.InvalidParameter;

            // The copyFlag conditions.
            if (((copyFlag == CopyToCopyFlags.Invalid && (requirementContainer.ContainsKey(3445) && requirementContainer[3445])) || (option == SendOptionAlls.Invalid && (requirementContainer.ContainsKey(3463) && requirementContainer[3463]))) ||
                ((copyFlag & CopyToCopyFlags.Move) == CopyToCopyFlags.Move && (requirementContainer.ContainsKey(3442001) && requirementContainer[3442001])) ||
                ((copyFlag & CopyToCopyFlags.Move) == CopyToCopyFlags.Move && (requirementContainer.ContainsKey(3442003) && requirementContainer[3442003])))
            {
                downloadContextHandleIndex = -1;
                if ((copyFlag & CopyToCopyFlags.Move) == CopyToCopyFlags.Move)
                {
                    // CopyToCopyFlags value is Move.
                    if (requirementContainer.ContainsKey(3442001) && requirementContainer[3442001])
                    {
                        // When the ROP return invalid parameter this requirement verified.
                        ModelHelper.CaptureRequirement(
                        3442001,
                        @"[In Appendix A: Product Behavior] Implementation does not support. <31> Section 3.2.5.8.1.1: Exchange 2010 and Exchange 2013 do not support the Move flag for the RopFastTransferSourceCopyTo ROP (section 2.2.3.1.1.1).");
                    }

                    if (requirementContainer.ContainsKey(3442003) && requirementContainer[3442003])
                    {
                        result = RopResult.InvalidParameter;

                        // When the ROP return invalid parameter this requirement verified.
                        ModelHelper.CaptureRequirement(
                        3442003,
                        @"[In Appendix A: Product Behavior] If the server receives the Move flag, implementation does fail the operation with an error code InvalidParameter (0x80070057).  <31> Section 3.2.5.8.1.1: The server sets the value of the ReturnValue field to InvalidParameter (0x80070057) if it receives this flag [Move flag].(Microsoft Exchange Server 2010, Exchange Server 2013 and  Exchange Server 2016 follow this behavior.)");
                    }
                }

                return result;
            }
            else
            {
                // Create a new download context
                AbstractDownloadInfo downloadInfo = new AbstractDownloadInfo();
                bool isObjExist = false;

                // Get value of ConnectionData
                ConnectionData changeConnection = connections[serverId];
                connections.Remove(serverId);

                // Find current message
                if (handleType == InputHandleType.MessageHandle)
                {
                    foreach (AbstractMessage temp in changeConnection.MessageContainer)
                    {
                        if (temp.MessageHandleIndex == objHandleIndex)
                        {
                            isObjExist = true;
                        }
                    }

                    Condition.IsTrue(isObjExist);

                    // Set value for new download context.
                    downloadInfo.DownloadHandleIndex = AdapterHelper.GetHandleIndex();
                    downloadContextHandleIndex = downloadInfo.DownloadHandleIndex;
                    downloadInfo.Sendoptions = option;
                    downloadInfo.Property = propertyTags;
                    downloadInfo.CopyToCopyFlag = copyFlag;
                    downloadInfo.IsLevelTrue = level;

                    // Record FastTransfer Operation.
                    downloadInfo.RelatedFastTransferOperation = EnumFastTransferOperation.FastTransferSourceCopyTo;
                    downloadInfo.AbstractFastTransferStreamType = FastTransferStreamType.MessageContent;
                    downloadInfo.ObjectType = ObjectType.Message;
                    downloadInfo.RelatedObjectHandleIndex = objHandleIndex;

                    priorDownloadOperation = PriorDownloadOperation.RopFastTransferSourceCopyTo;

                    // Add new download context to downloadContext Container.
                    changeConnection.DownloadContextContainer = changeConnection.DownloadContextContainer.Add(downloadInfo);
                }
                else if (handleType == InputHandleType.FolderHandle)
                {
                    // Find current folder.
                    foreach (AbstractFolder temp in changeConnection.FolderContainer)
                    {
                        if (temp.FolderHandleIndex == objHandleIndex)
                        {
                            isObjExist = true;
                        }
                    }

                    Condition.IsTrue(isObjExist);

                    // Set value for new download context.
                    downloadInfo.DownloadHandleIndex = AdapterHelper.GetHandleIndex();
                    downloadContextHandleIndex = downloadInfo.DownloadHandleIndex;
                    downloadInfo.Sendoptions = option;
                    downloadInfo.Property = propertyTags;
                    downloadInfo.CopyToCopyFlag = copyFlag;

                    // Record FastTransfer Operation
                    downloadInfo.RelatedFastTransferOperation = EnumFastTransferOperation.FastTransferSourceCopyTo;
                    downloadInfo.AbstractFastTransferStreamType = FastTransferStreamType.folderContent;
                    downloadInfo.ObjectType = ObjectType.Folder;
                    downloadInfo.RelatedObjectHandleIndex = objHandleIndex;

                    priorDownloadOperation = PriorDownloadOperation.RopFastTransferSourceCopyTo;

                    // Add new download context to DownloadContextContainer
                    changeConnection.DownloadContextContainer = changeConnection.DownloadContextContainer.Add(downloadInfo);
                }
                else
                {
                    // Find current attachment
                    foreach (AbstractAttachment temp in changeConnection.AttachmentContainer)
                    {
                        if (temp.AttachmentHandleIndex == objHandleIndex)
                        {
                            isObjExist = true;
                        }
                    }

                    Condition.IsTrue(isObjExist);

                    // Set value for new download context.
                    downloadInfo.DownloadHandleIndex = AdapterHelper.GetHandleIndex();
                    downloadContextHandleIndex = downloadInfo.DownloadHandleIndex;
                    downloadInfo.Sendoptions = option;
                    downloadInfo.Property = propertyTags;
                    downloadInfo.CopyToCopyFlag = copyFlag;

                    // Record FastTransfer Operation
                    downloadInfo.RelatedFastTransferOperation = EnumFastTransferOperation.FastTransferSourceCopyTo;
                    downloadInfo.AbstractFastTransferStreamType = FastTransferStreamType.attachmentContent;
                    downloadInfo.ObjectType = ObjectType.Attachment;
                    downloadInfo.RelatedObjectHandleIndex = objHandleIndex;

                    priorDownloadOperation = PriorDownloadOperation.RopFastTransferSourceCopyTo;

                    // Add new download context to DownloadContextContainer
                    changeConnection.DownloadContextContainer = changeConnection.DownloadContextContainer.Add(downloadInfo);
                }

                connections.Add(serverId, changeConnection);

                result = RopResult.Success;
                ModelHelper.CaptureRequirement(
                    361,
                    @"[In RopFastTransferSourceCopyTo ROP] The RopFastTransferSourceCopyTo ROP ([MS-OXCROPS] section 2.2.12.6) initializes a FastTransfer operation to download content from a given messaging object and its descendant subobjects.");

                if ((copyFlag & CopyToCopyFlags.Move) == CopyToCopyFlags.Move)
                {
                    if (requirementContainer.ContainsKey(3442002) && requirementContainer[3442002])
                    {
                        ModelHelper.CaptureRequirement(
                            3442002,
                            @"[In Appendix A: Product Behavior] Implementation does support Move flag [for the RopFastTransferSourceCopyTo ROP]. (Microsoft Exchange Server 2007 follow this behavior.)");
                    }

                    if (requirementContainer.ContainsKey(3442004) && requirementContainer[3442004])
                    {
                        ModelHelper.CaptureRequirement(
                            3442004,
                            @"[In Appendix A: Product Behavior] If the server receives the Move flag, implementation does not fail the operation.(<31> Section 3.2.5.8.1.1: Microsoft Exchange Server 2007 follows this behavior.)");
                    }
                }
            }

            return result;
        }