The LargePropTagArray structure contains a list of property tags.
예제 #1
0
        /// <summary>
        /// The NspiQueryRows method returns a number of rows from a specified table to the client.
        /// </summary>
        /// <param name="flags">A DWORD value that contains a set of bit flags.</param>
        /// <param name="stat">A STAT block that describes a logical position in a specific address book container.</param>
        /// <param name="tableCount">A DWORD value that contains the number values in the input parameter table.
        /// This value is limited to 100,000.</param>
        /// <param name="table">An array of DWORD values, representing an Explicit Table.</param>
        /// <param name="count">A DWORD value that contains the number of rows the client is requesting.</param>
        /// <param name="propTags">The value NULL or a reference to a PropertyTagArray_r value,
        /// containing a list of the proptags of the properties that the client requires to be returned for each row returned.</param>
        /// <param name="rows">A nullable PropertyRowSet_r value, it contains the address book container rows that the server returns in response to the request.</param>
        /// <returns>Status of NSPI method.</returns>
        public ErrorCodeValue QueryRows(uint flags, ref STAT stat, uint tableCount, uint[] table, uint count, PropertyTagArray_r?propTags, out PropertyRowSet_r?rows)
        {
            ErrorCodeValue       result;
            QueryRowsRequestBody queryRowsRequestBody = new QueryRowsRequestBody();
            LargePropTagArray    propetyTags          = new LargePropTagArray();

            if (propTags != null)
            {
                propetyTags.PropertyTagCount = propTags.Value.Values;
                propetyTags.PropertyTags     = new PropertyTag[propetyTags.PropertyTagCount];
                for (int i = 0; i < propTags.Value.Values; i++)
                {
                    propetyTags.PropertyTags[i].PropertyId   = (ushort)((propTags.Value.AulPropTag[i] & 0xFFFF0000) >> 16);
                    propetyTags.PropertyTags[i].PropertyType = (ushort)(propTags.Value.AulPropTag[i] & 0x0000FFFF);
                }

                queryRowsRequestBody.HasColumns = true;
                queryRowsRequestBody.Columns    = propetyTags;
            }

            queryRowsRequestBody.Flags              = flags;
            queryRowsRequestBody.HasState           = true;
            queryRowsRequestBody.State              = stat;
            queryRowsRequestBody.ExplicitTableCount = tableCount;
            queryRowsRequestBody.ExplicitTable      = table;
            queryRowsRequestBody.RowCount           = count;
            byte[] auxIn = new byte[] { };
            queryRowsRequestBody.AuxiliaryBuffer     = auxIn;
            queryRowsRequestBody.AuxiliaryBufferSize = (uint)auxIn.Length;

            ChunkedResponse       chunkedResponse       = this.SendAddressBookRequest(queryRowsRequestBody, RequestType.QueryRows);
            QueryRowsResponseBody queryRowsResponseBody = QueryRowsResponseBody.Parse(chunkedResponse.ResponseBodyRawData);

            result = (ErrorCodeValue)queryRowsResponseBody.ErrorCode;
            if (queryRowsResponseBody.RowCount != null)
            {
                PropertyRowSet_r newRows = AdapterHelper.ParsePropertyRowSet_r(queryRowsResponseBody.Columns.Value, queryRowsResponseBody.RowCount.Value, queryRowsResponseBody.RowData);
                rows = newRows;
            }
            else
            {
                rows = null;
            }

            if (queryRowsResponseBody.HasState)
            {
                stat = queryRowsResponseBody.State.Value;
            }

            return(result);
        }
        /// <summary>
        /// Parse the Large property tag array from the response data.
        /// </summary>
        /// <param name="rawData">The response data.</param>
        /// <param name="index">The start index of response data.</param>
        /// <returns>The result of parse the response data</returns>
        public static LargePropTagArray Parse(byte[] rawData, ref int index)
        {
            LargePropTagArray largePropTagArray = new LargePropTagArray();

            largePropTagArray.PropertyTagCount = BitConverter.ToUInt32(rawData, index);
            index += sizeof(uint);
            largePropTagArray.PropertyTags = new PropertyTag[largePropTagArray.PropertyTagCount];

            int count = 0;
            while (largePropTagArray.PropertyTagCount > count)
            {
                largePropTagArray.PropertyTags[count].PropertyType = BitConverter.ToUInt16(rawData, index);
                index += 2;
                largePropTagArray.PropertyTags[count].PropertyId = BitConverter.ToUInt16(rawData, index);
                index += 2;
                count++;
            }

            return largePropTagArray;
        }
        /// <summary>
        /// Parse the Large property tag array from the response data.
        /// </summary>
        /// <param name="rawData">The response data.</param>
        /// <param name="index">The start index of response data.</param>
        /// <returns>The result of parse the response data</returns>
        public static LargePropTagArray Parse(byte[] rawData, ref int index)
        {
            LargePropTagArray largePropTagArray = new LargePropTagArray();

            largePropTagArray.PropertyTagCount = BitConverter.ToUInt32(rawData, index);
            index += sizeof(uint);
            largePropTagArray.PropertyTags = new PropertyTag[largePropTagArray.PropertyTagCount];

            int count = 0;

            while (largePropTagArray.PropertyTagCount > count)
            {
                largePropTagArray.PropertyTags[count].PropertyType = BitConverter.ToUInt16(rawData, index);
                index += 2;
                largePropTagArray.PropertyTags[count].PropertyId = BitConverter.ToUInt16(rawData, index);
                index += 2;
                count++;
            }

            return(largePropTagArray);
        }
        /// <summary>
        /// Parse the response data into response body.
        /// </summary>
        /// <param name="rawData">The raw data of response</param>
        /// <returns>The response body of the request</returns>
        public static QueryRowsResponseBody Parse(byte[] rawData)
        {
            QueryRowsResponseBody responseBody = new QueryRowsResponseBody();
            int index = 0;

            responseBody.StatusCode = BitConverter.ToUInt32(rawData, index);
            index += sizeof(uint);
            responseBody.ErrorCode = BitConverter.ToUInt32(rawData, index);
            index += sizeof(uint);
            responseBody.HasState = BitConverter.ToBoolean(rawData, index);
            index += sizeof(bool);
            if (responseBody.HasState)
            {
                responseBody.State = STAT.Parse(rawData, ref index);
            }

            responseBody.HasColumnsAndRows = BitConverter.ToBoolean(rawData, index);
            index += sizeof(bool);
            if (responseBody.HasColumnsAndRows)
            {
                responseBody.Columns  = LargePropTagArray.Parse(rawData, ref index);
                responseBody.RowCount = BitConverter.ToUInt32(rawData, index);
                index += sizeof(uint);
                responseBody.RowData = new AddressBookPropertyRow[(uint)responseBody.RowCount];
                for (int i = 0; i < responseBody.RowCount; i++)
                {
                    responseBody.RowData[i] = AddressBookPropertyRow.Parse(rawData, (LargePropTagArray)responseBody.Columns, ref index);
                }
            }

            responseBody.AuxiliaryBufferSize = BitConverter.ToUInt32(rawData, index);
            index += 4;
            responseBody.AuxiliaryBuffer = new byte[responseBody.AuxiliaryBufferSize];
            Array.Copy(rawData, index, responseBody.AuxiliaryBuffer, 0, responseBody.AuxiliaryBufferSize);
            return(responseBody);
        }
        /// <summary>
        /// The NspiQueryRows method returns a number of rows from a specified table to the client.
        /// </summary>
        /// <param name="flags">A DWORD value that contains a set of bit flags.</param>
        /// <param name="stat">A STAT block that describes a logical position in a specific address book container.</param>
        /// <param name="tableCount">A DWORD value that contains the number values in the input parameter table. 
        /// This value is limited to 100,000.</param>
        /// <param name="table">An array of DWORD values, representing an Explicit Table.</param>
        /// <param name="count">A DWORD value that contains the number of rows the client is requesting.</param>
        /// <param name="propTags">The value NULL or a reference to a PropertyTagArray_r value, 
        /// containing a list of the proptags of the properties that the client requires to be returned for each row returned.</param>
        /// <param name="rows">A nullable PropertyRowSet_r value, it contains the address book container rows that the server returns in response to the request.</param>
        /// <returns>Status of NSPI method.</returns>
        public ErrorCodeValue QueryRows(uint flags, ref STAT stat, uint tableCount, uint[] table, uint count, PropertyTagArray_r? propTags, out PropertyRowSet_r? rows)
        {
            ErrorCodeValue result;
            QueryRowsRequestBody queryRowsRequestBody = new QueryRowsRequestBody();
            LargePropTagArray propetyTags = new LargePropTagArray();
            if (propTags != null)
            {
                propetyTags.PropertyTagCount = propTags.Value.Values;
                propetyTags.PropertyTags = new PropertyTag[propetyTags.PropertyTagCount];
                for (int i = 0; i < propTags.Value.Values; i++)
                {
                    propetyTags.PropertyTags[i].PropertyId = (ushort)((propTags.Value.AulPropTag[i] & 0xFFFF0000) >> 16);
                    propetyTags.PropertyTags[i].PropertyType = (ushort)(propTags.Value.AulPropTag[i] & 0x0000FFFF);
                }

                queryRowsRequestBody.HasColumns = true;
                queryRowsRequestBody.Columns = propetyTags;
            }

            queryRowsRequestBody.Flags = flags;
            queryRowsRequestBody.HasState = true;
            queryRowsRequestBody.State = stat;
            queryRowsRequestBody.ExplicitTableCount = tableCount;
            queryRowsRequestBody.ExplicitTable = table;
            queryRowsRequestBody.RowCount = count;
            byte[] auxIn = new byte[] { };
            queryRowsRequestBody.AuxiliaryBuffer = auxIn;
            queryRowsRequestBody.AuxiliaryBufferSize = (uint)auxIn.Length;

            ChunkedResponse chunkedResponse = this.SendAddressBookRequest(queryRowsRequestBody, RequestType.QueryRows);
            QueryRowsResponseBody queryRowsResponseBody = QueryRowsResponseBody.Parse(chunkedResponse.ResponseBodyRawData);
            result = (ErrorCodeValue)queryRowsResponseBody.ErrorCode;
            if (queryRowsResponseBody.RowCount != null)
            {
                PropertyRowSet_r newRows = AdapterHelper.ParsePropertyRowSet_r(queryRowsResponseBody.Columns.Value, queryRowsResponseBody.RowCount.Value, queryRowsResponseBody.RowData);
                rows = newRows;
            }
            else
            {
                rows = null;
            }

            if (queryRowsResponseBody.HasState)
            {
                stat = queryRowsResponseBody.State.Value;
            }

            return result;
        }
        /// <summary>
        /// Parse the AddressBookPropertyRow structure.
        /// </summary>
        /// <param name="rawBuffer">The raw data returned from server.</param>
        /// <param name="propTagArray">The list of property tags.</param>
        ///  <param name="index">The start index.</param>
        /// <returns>Return an instance of AddressBookPropertyRow.</returns>
        public static AddressBookPropertyRow Parse(byte[] rawBuffer, LargePropTagArray propTagArray, ref int index)
        {
            AddressBookPropertyRow addressBookPropertyRow = new AddressBookPropertyRow();

            addressBookPropertyRow.Flag = rawBuffer[index];
            index++;
            addressBookPropertyRow.ValueArray = new List <AddressBookPropertyValue>();

            Context.Instance.PropertyBytes = rawBuffer;
            Context.Instance.CurIndex      = index;
            Context.Instance.CurProperty   = new Property(Microsoft.Protocols.TestSuites.Common.PropertyType.PtypUnspecified);

            // If the value of the Flags field is set to 0x00: The array contains either a PropertyValue structure, or a TypedPropertyValue structure.
            // If the value of the Flags field is set to 0x01: The array contains either a FlaggedPropertyValue structure, or a FlaggedPropertyValueWithType structure.
            if (addressBookPropertyRow.Flag == 0x00)
            {
                foreach (PropertyTag propertyTag in propTagArray.PropertyTags)
                {
                    if (propertyTag.PropertyType == 0x0000)
                    {
                        // If the value of the Flags field is set to 0x00: The array contains a TypedPropertyValue structure, if the type of property is PtyUnspecified.
                        AddressBookTypedPropertyValue typedPropertyValue = new AddressBookTypedPropertyValue();
                        typedPropertyValue.Parse(Context.Instance);
                        addressBookPropertyRow.ValueArray.Add(typedPropertyValue);
                        index = Context.Instance.CurIndex;
                    }
                    else
                    {
                        // If the value of the Flags field is set to 0x00: The array contains a PropertyValue structure, if the type of property is specified.
                        Context.Instance.CurProperty.Type = (Microsoft.Protocols.TestSuites.Common.PropertyType)propertyTag.PropertyType;
                        AddressBookPropertyValue propertyValue = new AddressBookPropertyValue();
                        propertyValue.Parse(Context.Instance);
                        addressBookPropertyRow.ValueArray.Add(propertyValue);
                        index = Context.Instance.CurIndex;
                    }
                }
            }
            else if (addressBookPropertyRow.Flag == 0x01)
            {
                foreach (PropertyTag propertyTag in propTagArray.PropertyTags)
                {
                    if (propertyTag.PropertyType == 0x0000)
                    {
                        // If the value of the Flags field is set to 0x01: The array contains a FlaggedPropertyValueWithType structure, if the type of property is PtyUnspecified.
                        AddressBookFlaggedPropertyValueWithType flaggedPropertyValue = new AddressBookFlaggedPropertyValueWithType();
                        flaggedPropertyValue.Parse(Context.Instance);
                        addressBookPropertyRow.ValueArray.Add(flaggedPropertyValue);
                        index = Context.Instance.CurIndex;
                    }
                    else
                    {
                        // If the value of the Flags field is set to 0x01: The array contains a FlaggedPropertyValue structure, if the type of property is specified.
                        Context.Instance.CurProperty.Type = (Microsoft.Protocols.TestSuites.Common.PropertyType)propertyTag.PropertyType;
                        AddressBookFlaggedPropertyValue propertyValue = new AddressBookFlaggedPropertyValue();
                        propertyValue.Parse(Context.Instance);
                        addressBookPropertyRow.ValueArray.Add(propertyValue);
                        index = Context.Instance.CurIndex;
                    }
                }
            }

            return(addressBookPropertyRow);
        }
        /// <summary>
        /// Parse PropertyRowSet_r structure.
        /// </summary>
        /// <param name="columns">The columns which contain property tags.</param>
        /// <param name="rowCount">The row count of the PropertyRowSet_r.</param>
        /// <param name="rowData">The row data which contain the property values.</param>
        /// <returns>Instance of PropertyRowSet_r structure.</returns>
        public static PropertyRowSet_r ParsePropertyRowSet_r(LargePropTagArray columns, uint rowCount, AddressBookPropertyRow[] rowData)
        {
            PropertyRowSet_r propertyRowSet_r = new PropertyRowSet_r();

            propertyRowSet_r.Rows = rowCount;
            propertyRowSet_r.PropertyRowSet = new PropertyRow_r[rowCount];

            for (int i = 0; i < rowCount; i++)
            {
                propertyRowSet_r.PropertyRowSet[i].Reserved = 0;
                propertyRowSet_r.PropertyRowSet[i].Values = columns.PropertyTagCount;
                propertyRowSet_r.PropertyRowSet[i].Props = new PropertyValue_r[columns.PropertyTagCount];
                for (int j = 0; j < columns.PropertyTagCount; j++)
                {
                    propertyRowSet_r.PropertyRowSet[i].Props[j].PropTag = BitConverter.ToUInt32(columns.PropertyTags[j].Serialize(), 0);
                    propertyRowSet_r.PropertyRowSet[i].Props[j].Reserved = 0;
                    propertyRowSet_r.PropertyRowSet[i].Props[j].Value = AdapterHelper.ParsePROP_VAL_UNION(rowData[i].ValueArray.ToArray()[j], (PropertyTypeValue)columns.PropertyTags[j].PropertyType);
                }
            }

            return propertyRowSet_r;
        }
        /// <summary>
        /// Parse the AddressBookPropertyRow structure.
        /// </summary>
        /// <param name="rawBuffer">The raw data returned from server.</param>
        /// <param name="propTagArray">The list of property tags.</param>
        ///  <param name="index">The start index.</param>
        /// <returns>Return an instance of AddressBookPropertyRow.</returns>
        public static AddressBookPropertyRow Parse(byte[] rawBuffer, LargePropTagArray propTagArray, ref int index)
        {
            AddressBookPropertyRow addressBookPropertyRow = new AddressBookPropertyRow();
            addressBookPropertyRow.Flag = rawBuffer[index];
            index++;
            addressBookPropertyRow.ValueArray = new List<AddressBookPropertyValue>();

            Context.Instance.PropertyBytes = rawBuffer;
            Context.Instance.CurIndex = index;
            Context.Instance.CurProperty = new Property(Microsoft.Protocols.TestSuites.Common.PropertyType.PtypUnspecified);

            // If the value of the Flags field is set to 0x00: The array contains either a PropertyValue structure, or a TypedPropertyValue structure.
            // If the value of the Flags field is set to 0x01: The array contains either a FlaggedPropertyValue structure, or a FlaggedPropertyValueWithType structure. 
            if (addressBookPropertyRow.Flag == 0x00)
            {
               foreach (PropertyTag propertyTag in propTagArray.PropertyTags)
               {
                   if (propertyTag.PropertyType == 0x0000)
                   {
                        // If the value of the Flags field is set to 0x00: The array contains a TypedPropertyValue structure, if the type of property is PtyUnspecified.
                       AddressBookTypedPropertyValue typedPropertyValue = new AddressBookTypedPropertyValue();
                       typedPropertyValue.Parse(Context.Instance);
                       addressBookPropertyRow.ValueArray.Add(typedPropertyValue);
                       index = Context.Instance.CurIndex;
                   }
                   else
                   {
                       // If the value of the Flags field is set to 0x00: The array contains a PropertyValue structure, if the type of property is specified.
                       Context.Instance.CurProperty.Type = (Microsoft.Protocols.TestSuites.Common.PropertyType)propertyTag.PropertyType;
                        AddressBookPropertyValue propertyValue = new AddressBookPropertyValue();
                       propertyValue.Parse(Context.Instance);
                       addressBookPropertyRow.ValueArray.Add(propertyValue);
                       index = Context.Instance.CurIndex;
                   }
               }
            }
            else if (addressBookPropertyRow.Flag == 0x01)
            {
                foreach (PropertyTag propertyTag in propTagArray.PropertyTags)
                {
                    if (propertyTag.PropertyType == 0x0000)
                    {
                        // If the value of the Flags field is set to 0x01: The array contains a FlaggedPropertyValueWithType structure, if the type of property is PtyUnspecified.
                        AddressBookFlaggedPropertyValueWithType flaggedPropertyValue = new AddressBookFlaggedPropertyValueWithType();
                        flaggedPropertyValue.Parse(Context.Instance);
                        addressBookPropertyRow.ValueArray.Add(flaggedPropertyValue);
                        index = Context.Instance.CurIndex;
                    }
                    else
                    {
                        // If the value of the Flags field is set to 0x01: The array contains a FlaggedPropertyValue structure, if the type of property is specified.
                        Context.Instance.CurProperty.Type = (Microsoft.Protocols.TestSuites.Common.PropertyType)propertyTag.PropertyType;
                        AddressBookFlaggedPropertyValue propertyValue = new AddressBookFlaggedPropertyValue();
                        propertyValue.Parse(Context.Instance);
                        addressBookPropertyRow.ValueArray.Add(propertyValue);
                        index = Context.Instance.CurIndex;
                    }
                }
            }

            return addressBookPropertyRow;
        }