The PropertyRowSet_r structure is an encoding of the PropertyRowSet data structure.
示例#1
0
        /// <summary>
        /// Parse PropertyRowSet_r structure.
        /// </summary>
        /// <param name="ptr">A pointer points to memory allocated.</param>
        /// <returns>Instance of PropertyRowSet_r structure.</returns>
        public static PropertyRowSet_r ParsePropertyRowSet_r(IntPtr ptr)
        {
            PropertyRowSet_r prs_r = new PropertyRowSet_r
            {
                Rows = (uint)Marshal.ReadInt32(ptr)
            };

            const int PropertyRowLengthInBytes = 12;

            if (prs_r.Rows == 0)
            {
                prs_r.PropertyRowSet = null;
            }
            else
            {
                ptr = new IntPtr(ptr.ToInt32() + sizeof(uint));
                prs_r.PropertyRowSet = new PropertyRow_r[prs_r.Rows];
                for (uint i = 0; i < prs_r.Rows; i++)
                {
                    prs_r.PropertyRowSet[i] = ParsePropertyRow_r(ptr);
                    ptr = new IntPtr(ptr.ToInt32() + PropertyRowLengthInBytes);
                }
            }

            return(prs_r);
        }
示例#2
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>
        /// 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 PropertyRowSet_r structure.
        /// </summary>
        /// <param name="ptr">A pointer points to the allocated memory.</param>
        /// <returns>Instance of PropertyRowSet_r structure.</returns>
        public static PropertyRowSet_r ParsePropertyRowSet_r(IntPtr ptr)
        {
            PropertyRowSet_r prs_r = new PropertyRowSet_r();
            int offset = 0;

            prs_r.Rows = (uint)Marshal.ReadInt32(ptr);
            offset += sizeof(uint);

            const int PropertyRowLengthInBytes = 12;

            if (prs_r.Rows == 0)
            {
                prs_r.PropertyRowSet = null;
            }
            else
            {
                ptr = new IntPtr(ptr.ToInt32() + offset);
                prs_r.PropertyRowSet = new PropertyRow_r[prs_r.Rows];

                for (uint i = 0; i < prs_r.Rows; i++)
                {
                    prs_r.PropertyRowSet[i] = ParsePropertyRow_r(ptr);
                    ptr = new IntPtr(ptr.ToInt32() + PropertyRowLengthInBytes);
                }
            }

            return prs_r;
        }
        /// <summary>
        /// Parse PropertyRowSet_r structure.
        /// </summary>
        /// <param name="rowsCount">The row count of the PropertyRowSet_r.</param>
        /// <param name="rows">The rows which contains property tags and property values.</param>
        /// <returns>Instance of PropertyRowSet_r structure.</returns>
        public static PropertyRowSet_r ParsePropertyRowSet_r(uint rowsCount, AddressBookPropValueList[] rows)
        {
            PropertyRowSet_r propertyRowSet_r = new PropertyRowSet_r();

            propertyRowSet_r.Rows = rowsCount;
            if (rowsCount == 0)
            {
                propertyRowSet_r.PropertyRowSet = null;
            }
            else
            {
                propertyRowSet_r.PropertyRowSet = new PropertyRow_r[rowsCount];

                for (int i = 0; i < rowsCount; i++)
                {
                    propertyRowSet_r.PropertyRowSet[i].Reserved = 0;
                    propertyRowSet_r.PropertyRowSet[i].Values = rows[i].PropertyValueCount;
                    propertyRowSet_r.PropertyRowSet[i].Props = new PropertyValue_r[rows[i].PropertyValueCount];
                    for (int j = 0; j < rows[i].PropertyValueCount; j++)
                    {
                        propertyRowSet_r.PropertyRowSet[i].Props[j].PropTag = BitConverter.ToUInt32(rows[i].PropertyValues[j].PropertyTag.Serialize(), 0);
                        propertyRowSet_r.PropertyRowSet[i].Props[j].Reserved = 0;
                        propertyRowSet_r.PropertyRowSet[i].Props[j].Value = AdapterHelper.ParsePROP_VAL_UNION((AddressBookPropertyValue)rows[i].PropertyValues[j], (PropertyTypeValue)rows[i].PropertyValues[j].PropertyTag.PropertyType);
                    }
                }
            }

            return propertyRowSet_r;
        }
        /// <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>
        /// 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>
        /// <param name="needRetry">A bool value indicates if need to retry to get an expected result. This parameter is designed to avoid meaningless retry when an error response is expected.</param>
        /// <returns>Status of NSPI method.</returns>
        public ErrorCodeValue NspiQueryRows(uint flags, ref STAT stat, uint tableCount, uint[] table, uint count, PropertyTagArray_r? propTags, out PropertyRowSet_r? rows, bool needRetry = true)
        {
            int result;
            IntPtr ptrRows = IntPtr.Zero;
            IntPtr ptrPropTags = IntPtr.Zero;
            IntPtr ptrStat = AdapterHelper.AllocStat(stat);
            if (propTags != null)
            {
                ptrPropTags = AdapterHelper.AllocPropertyTagArray_r(propTags.Value);
            }

            int retryCount = 0;
            do
            {
                try
                {
                    result = OxnspiInterop.NspiQueryRows(this.contextHandle, flags, ref stat, tableCount, table, count, ptrPropTags, out ptrRows);
                }
                catch (SEHException e)
                {
                    result = (int)NativeMethods.RpcExceptionCode(e);
                    this.site.Log.Add(LogEntryKind.Comment, "RPC component throws exception, the error code is {0}, the error message is: {1}", result, new Win32Exception(result).ToString());
                }

                if ((ErrorCodeValue)result == ErrorCodeValue.GeneralFailure && needRetry)
                {
                    Thread.Sleep(this.waitTime);
                }
                else
                {
                    break;
                }

                retryCount++;
            }
            while ((ErrorCodeValue)result == ErrorCodeValue.GeneralFailure && retryCount < this.maxRetryCount);

            if (!Enum.IsDefined(typeof(ErrorCodeValue), (uint)result))
            {
                throw new ArgumentException(string.Format("An unknown error is returned, the error code is: {0} and the error message is: {1}", result, new Win32Exception(result).ToString()));
            }

            if (propTags != null)
            {
                Marshal.FreeHGlobal(ptrPropTags);
            }

            // Parse rows according to ptrRows.
            if (ptrRows == IntPtr.Zero)
            {
                rows = null;
            }
            else
            {
                rows = AdapterHelper.ParsePropertyRowSet_r(ptrRows);
            }

            // Free stat.
            Marshal.FreeHGlobal(ptrStat);
            return (ErrorCodeValue)result;
        }