Example #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="target"></param>
        /// <param name="args"></param>
        /// <param name="instanceRestrict"></param>
        /// <returns></returns>
        internal static Restrict2 BuildCallRestrictions(Meta2 target, Meta2[] args, RestrictFlag flag)
        {
            var restrictions =
                target.Restrictions.Merge(
                    Restrict2.Combine(args)
                );

            if (flag == RestrictFlag.Instance)
            {
                restrictions =
                    restrictions.Merge(
                        Restrict2.GetInstanceRestriction(
                            target.Expression,
                            target.Value
                        )
                    );
            }
            else
            {
                restrictions =
                    restrictions.Merge(
                        Restrict2.GetTypeRestriction(
                            target.Expression,
                            target.LimitType
                        )
                    );
            }

            for (var i = 0; i < args.Length; ++i)
            {
                Restrict2 restr;

                // HasValue and Value == null, means we have a null value
                if (args[i].HasValue && args[i].Value == null)
                {
                    restr =
                        Restrict2.GetInstanceRestriction(
                            args[i].Expression,
                            null
                        );
                }
                else
                {
                    restr =
                        Restrict2.GetTypeRestriction(
                            args[i].Expression,
                            args[i].LimitType
                        );
                }

                restrictions = restrictions.Merge(restr);
            }

            return restrictions;
        }
        /// <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 restrict for a 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 Restrict</param>
        /// <param name="newRestrict">A identify whether new restriction is required</param>
        /// <param name="isRestrictAsynchronous">Indicate whether RopRestrict Rop is to be performed asynchronously</param>
        /// <returns>Table ROP return value</returns>
        public TableRopReturnValues RopRestrict(uint reqId, bool validHandle, bool newRestrict, bool isRestrictAsynchronous)
        {
            RopRestrictRequest restrictRequest;
            RopRestrictResponse restrictResponse;

            restrictRequest.RopId = 0x14;
            restrictRequest.LogonId = 0x00;
            restrictRequest.InputHandleIndex = (byte)0x00; 
            if (isRestrictAsynchronous)
            {
                restrictRequest.RestrictFlags = 0x01; // Async
            }
            else
            {
                restrictRequest.RestrictFlags = 0x00; // Sync
            }

            this.globalIsRestrictAsynchronous = isRestrictAsynchronous;
            byte[] data;
            if (this.tableType == TableType.CONTENT_TABLE)
            {
                if (!newRestrict && this.sign)
                {
                    byte[] tempData = Encoding.Unicode.GetBytes(Common.GetConfigurationPropertyValue("Sender1Name", this.Site) + "\0");
                    data = new byte[tempData.Length + 13];
                    int index = 0;
                    data[index++] = 0x03;
                    data[index++] = 0x02;
                    data[index++] = 0x00;
                    data[index++] = 0x04;
                    data[index++] = 0x00;
                    data[index++] = 0x1f;
                    data[index++] = 0x00;
                    data[index++] = 0x1a;
                    data[index++] = 0x0c;
                    data[index++] = 0x1f;
                    data[index++] = 0x00;
                    data[index++] = 0x1a;
                    data[index++] = 0x0c;
                    Array.Copy(tempData, 0, data, index, tempData.Length);

                    this.latestRestrict = RestrictFlag.SenderIsTest1Restrict;
                }
                else
                {
                    byte[] tempData = Encoding.Unicode.GetBytes(Common.GetConfigurationPropertyValue("Sender2Name", this.Site) + "\0");
                    data = new byte[tempData.Length + 13];
                    int index = 0;
                    data[index++] = 0x03;
                    data[index++] = 0x02;
                    data[index++] = 0x00;
                    data[index++] = 0x04;
                    data[index++] = 0x00;
                    data[index++] = 0x1f;
                    data[index++] = 0x00;
                    data[index++] = 0x1a;
                    data[index++] = 0x0c;
                    data[index++] = 0x1f;
                    data[index++] = 0x00;
                    data[index++] = 0x1a;
                    data[index++] = 0x0c;
                    Array.Copy(tempData, 0, data, index, tempData.Length);

                    this.latestRestrict = RestrictFlag.SenderIsTest2Restriction;
                }

                this.sign = this.sign == !newRestrict;
            }
            else if (this.tableType == TableType.HIERARCHY_TABLE || this.tableType == TableType.RULES_TABLE)
            {
                data = AdapterHelper.GenerateValidRestrictData(this.Site, this.tableType);
            }
            else
            {
                data = null;
            }

            restrictRequest.RestrictionDataSize = data == null ? (ushort)0 : (ushort)data.Length;
            restrictRequest.RestrictionData = data;

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

            this.DoSingleCallROP(restrictRequest, inputObjHandle, ref this.response, ref this.rawData);
            restrictResponse = (RopRestrictResponse)this.response;

            this.ropType = TableRopType.RESTRICT;

            if ((TableRopReturnValues)restrictResponse.ReturnValue == TableRopReturnValues.success)
            {
                this.latestSuccessRestrict = this.latestRestrict;

                this.GetRowsCount(false);
            }

            // If the RopRestrict ROP is not complete (the returned TableStatus is set to 0x0E), wait for the RopGetStatus ROP to return TableStatus set 0x00 (which indicates the RopRestrict ROP is complete).
            if ((TableRopReturnValues)restrictResponse.ReturnValue == TableRopReturnValues.success && isRestrictAsynchronous && (TableStatus)restrictResponse.TableStatus == TableStatus.TblstatRestricting)
            {
                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 RopRestrict ROP should complete!");
                }

                this.VerifyAsynchronousROPComplete(getStatusResponse);
            }

            return (TableRopReturnValues)restrictResponse.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();
        }