/// <summary>
        /// This method is used to initialize the table
        /// </summary>
        /// <param name="tableType">Identify the table type</param>
        public void InitializeTable(TableType tableType)
        {
            this.tableType = tableType; // Record the type of table.

            // Connect to the server.
            string serverName = string.Empty;
            serverName = Common.GetConfigurationPropertyValue("SutComputerName", this.Site);
            this.Connect(serverName);

            // Log on to the server.
            RopLogonResponse logonResponse = this.Logon(out this.inputObjHandle);

            // Initial the folder to Inbox.
            this.folderID = logonResponse.FolderIds[4];

            // Initial the sign to true.
            this.sign = true;

            // Prepare the table variable
            this.PrepareTable(this.tableType);

            this.userDefinedBookmark = new byte[] { 0x00 };
            this.userDefinedBookmarkPosition = 0;
            this.userDefinedBookmarkSize = 1;

            this.collapseState = new byte[] { 0x00 };
            this.collapseStateSize = 1;

            this.latestSortOrder = SortOrderFlag.NotSort;
            this.latestSuccessSortOrder = SortOrderFlag.NotSort;
            this.latestRestrict = RestrictFlag.NotRestrict;
            this.latestSuccessRestrict = RestrictFlag.NotRestrict;
        }
        /// <summary>
        /// This method is used to sort table
        /// </summary>
        /// <param name="reqId">Identify the request ID</param>
        /// <param name="validHandle">Identify whether the InputHandleIndex is valid, this is used to trigger the error code in sort table</param>
        /// <param name="multipleSortOrders">Indicate whether the sort order array contains more than one SortOrder structure</param>
        /// <param name="isMaximumCategory">Indicate whether the sort order array contains a SortOrder structure with the order set to MaximumCategory</param>
        /// <param name="allSortOrdersUsedAsCategory">Identify whether all sort orders used as category</param>
        /// <param name="allCategoryExpanded">Identify whether all categories are expanded</param>
        /// <param name="newOrder">Identify whether to change the current sort order</param>
        /// <param name="isSortTableAsynchronous">Indicate whether RopSortTable Rop is to be performed asynchronously</param>
        /// <returns>Table ROP return value</returns>
        public TableRopReturnValues RopSortTable(uint reqId, bool validHandle, bool multipleSortOrders, bool isMaximumCategory, bool allSortOrdersUsedAsCategory, bool allCategoryExpanded, bool newOrder, bool isSortTableAsynchronous)
        {
            RopSortTableRequest sortTableRequest;
            RopSortTableResponse sortTableResponse;
            SortOrder[] sortOrders;

            if (!newOrder && this.sign)
            {
                sortOrders = this.CreateSampleSortOrdersAscending(multipleSortOrders, isMaximumCategory);
            }
            else
            {
                sortOrders = this.CreateSampleSortOrdersDescending(multipleSortOrders);
            }

            this.sign = this.sign == !newOrder;
            this.latestSortOrder = sortOrders[0].Order == 0x00 ? SortOrderFlag.SortOrderASC : SortOrderFlag.SortOrderDESC;
            sortTableRequest.RopId = 0x13;
            sortTableRequest.LogonId = 0x00;
            sortTableRequest.InputHandleIndex = (byte)0x00; 
            this.areAllSortOrdersUsedAsCategory = allSortOrdersUsedAsCategory;
            this.areAllCategoryExpanded = allCategoryExpanded;
            this.areMultipleSortOrders = multipleSortOrders;
            sortTableRequest.SortOrderCount = (ushort)sortOrders.Length;
            if (allSortOrdersUsedAsCategory)
            {
                sortTableRequest.CategoryCount = (ushort)sortOrders.Length;
                if (allCategoryExpanded)
                {
                    sortTableRequest.ExpandedCount = (ushort)sortOrders.Length; // All rows expanded
                }
                else
                {
                    sortTableRequest.ExpandedCount = (ushort)(sortOrders.Length - 1); // Not all rows expanded
                }
            }
            else
            {
                sortTableRequest.CategoryCount = (ushort)(sortOrders.Length - 1);
                if (allCategoryExpanded)
                {
                    sortTableRequest.ExpandedCount = (ushort)(sortOrders.Length - 1); // All rows expanded
                }
                else
                {
                    sortTableRequest.ExpandedCount = 0;
                }
            }

            sortTableRequest.SortOrders = sortOrders;
            if (isSortTableAsynchronous)
            {
                sortTableRequest.SortTableFlags = 0x01; // Async
            }
            else
            {
                sortTableRequest.SortTableFlags = 0x00; // Sync
            }

            uint inputObjHandle;
            if (validHandle)
            {
                inputObjHandle = this.tableHandle;
            }
            else
            {
                inputObjHandle = 0xFFFFFFFF; // Cause the request failed when set to invalid handle
            }

            this.globalIsSortTableAsynchronous = isSortTableAsynchronous;
            this.DoSingleCallROP(sortTableRequest, inputObjHandle, ref this.response, ref this.rawData);
            sortTableResponse = (RopSortTableResponse)this.response;

            this.ropType = TableRopType.SORTTABLE;

            if ((TableRopReturnValues)sortTableResponse.ReturnValue == TableRopReturnValues.success)
            {
                this.latestSuccessSortOrder = this.latestSortOrder;
                if (sortTableRequest.ExpandedCount != 0)
                {
                    this.isExpanded = true; // The first header row is expanded when the request succeeds.
                }

                this.GetRowsCount(false); // Update the field rowCount
            }

            // If the RopSortTable ROP is not complete (the returned TableStatus is set to 0x09), wait for the RopGetStatus ROP to return TableStatus set 0x00 (which indicates the RopSortTable ROP is complete).
            if ((TableRopReturnValues)sortTableResponse.ReturnValue == TableRopReturnValues.success && isSortTableAsynchronous && (TableStatus)sortTableResponse.TableStatus == TableStatus.TblstatSorting)
            {
                int getStatusRetryCount = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site));
                RopGetStatusResponse getStatusResponse = new RopGetStatusResponse();
                while (getStatusRetryCount >= 0)
                {
                    Thread.Sleep(this.waitTime);
                    TableStatus tableStatus;
                    this.RopGetStatus(out tableStatus);
                    if (tableStatus == TableStatus.TblstatComplete)
                    {
                        break;
                    }

                    getStatusRetryCount--;
                }

                if (getStatusRetryCount < 0)
                {
                    Site.Assert.Fail("The RopSortTable ROP should complete!");
                }

                this.VerifyAsynchronousROPComplete(getStatusResponse);
            }

            return (TableRopReturnValues)sortTableResponse.ReturnValue;
        }
        /// <summary>
        /// Reset the adapter.
        /// </summary>
        public override void Reset()
        {
            if (this.needDoCleanup)
            {
                if (this.tableType == TableType.CONTENT_TABLE || this.tableType == TableType.RULES_TABLE || this.tableType == TableType.HIERARCHY_TABLE || this.tableType == TableType.ATTACHMENTS_TABLE)
                {
                    this.CleanInbox();
                }

                if (this.isConnected)
                {
                    this.Disconnect();
                }
            }

            this.latestSortOrder = SortOrderFlag.NotSort;
            this.latestSuccessSortOrder = SortOrderFlag.NotSort;
            this.latestRestrict = RestrictFlag.NotRestrict;
            this.latestSuccessRestrict = RestrictFlag.NotRestrict;
            this.areMultipleSortOrders = false;
            this.areAllSortOrdersUsedAsCategory = false;
            this.areAllCategoryExpanded = false;
            this.isExpanded = false;
            this.isSetCollapseStateCalled = false;
            this.isCollapseStateGot = false;
            this.globalIsRestrictAsynchronous = false;
            this.globalIsSetColumnsAsynchronous = false;
            this.globalIsSortTableAsynchronous = false;

            this.userDefinedBookmark = new byte[] { 0x00 };
            this.userDefinedBookmarkPosition = 0;
            this.userDefinedBookmarkSize = 1;

            this.propertyValues = new List<PropertyValue>();
            this.collapseState = new byte[] { 0x00 };
            this.collapseStateSize = 1;
            this.needDoCleanup = true;

            base.Reset();
        }