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

            responseBody.StatusCode = BitConverter.ToUInt32(rawData, index);
            index += sizeof(uint);
            responseBody.ErrorCode = BitConverter.ToUInt32(rawData, index);
            index += sizeof(uint);
            responseBody.CodePage = BitConverter.ToUInt32(rawData, index);
            index += sizeof(uint);

            responseBody.HasMinimalIds = BitConverter.ToBoolean(rawData, index);
            index += sizeof(bool);
            if (responseBody.HasMinimalIds)
            {
                responseBody.MinimalIdCount = BitConverter.ToUInt32(rawData, index);
                index += sizeof(uint);
                responseBody.MinimalIds = new uint[(uint)responseBody.MinimalIdCount];
                for (int i = 0; i < responseBody.MinimalIdCount; i++)
                {
                    responseBody.MinimalIds[i] = BitConverter.ToUInt32(rawData, index);
                    index += sizeof(uint);
                }
            }
            else
            {
                responseBody.MinimalIdCount = null;
                responseBody.MinimalIds     = null;
            }

            responseBody.HasRowsAndPropertyTags = BitConverter.ToBoolean(rawData, index);
            index += sizeof(bool);
            if (responseBody.HasRowsAndPropertyTags)
            {
                responseBody.PropertyTags = 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.PropertyTags, 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);
        }
Esempio n. 2
0
        /// <summary>
        /// Parse the SeekEntries request type response body.
        /// </summary>
        /// <param name="rawData">The raw data of response.</param>
        /// <returns>The SeekEntries request type response body.</returns>
        public static SeekEntriesResponseBody Parse(byte[] rawData)
        {
            SeekEntriesResponseBody responseBody = new SeekEntriesResponseBody();
            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);
            }
            else
            {
                responseBody.State = null;
            }

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

            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>
        /// 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, LargePropertyTagArray propTagArray, ref int index)
        {
            AddressBookPropertyRow addressBookPropertyRow = new AddressBookPropertyRow();

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

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

            // If the value of the Flags field is set to 0x00: The array contains either a AddressBookPropertyValue structure, or a AddressBookTypedPropertyValue structure.
            // If the value of the Flags field is set to 0x01: The array contains either a AddressBookFlaggedPropertyValue structure, or a AddressBookFlaggedPropertyValueWithType 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 AddressBookTypedPropertyValue structure, if the type of property is PtyUnspecified.
                        AddressBookTypedPropertyValue typedPropertyValue = new AddressBookTypedPropertyValue();

                        // Parse the AddressBookTypedPropertyValue with the instance of the context which contains the datas and start index.
                        typedPropertyValue.Parse(Context.Instance);
                        valueArray.Add(typedPropertyValue);
                        index = Context.Instance.CurIndex;
                    }
                    else
                    {
                        // If the value of the Flags field is set to 0x00: The array contains a AddressBookPropertyValue structure, if the type of property is specified.
                        Context.Instance.CurProperty.Type = (PropertyType)propertyTag.PropertyType;
                        AddressBookPropertyValue propertyValue = new AddressBookPropertyValue();

                        // Parse the AddressBookTypedPropertyValue with the instance of the context which contains the datas and start index.
                        propertyValue.Parse(Context.Instance);
                        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 AddressBookFlaggedPropertyValueWithType structure, if the type of property is PtyUnspecified.
                        AddressBookFlaggedPropertyValueWithType flaggedPropertyValue = new AddressBookFlaggedPropertyValueWithType();

                        // Parse the AddressBookTypedPropertyValue with the instance of the context which contains the datas and start index.
                        flaggedPropertyValue.Parse(Context.Instance);
                        valueArray.Add(flaggedPropertyValue);
                        index = Context.Instance.CurIndex;
                    }
                    else
                    {
                        // If the value of the Flags field is set to 0x01: The array contains a AddressBookFlaggedPropertyValue structure, if the type of property is specified.
                        Context.Instance.CurProperty.Type = (PropertyType)propertyTag.PropertyType;
                        AddressBookFlaggedPropertyValue propertyValue = new AddressBookFlaggedPropertyValue();

                        // Parse the AddressBookTypedPropertyValue with the instance of the context which contains the datas and start index.
                        propertyValue.Parse(Context.Instance);
                        valueArray.Add(propertyValue);
                        index = Context.Instance.CurIndex;
                    }
                }
            }

            addressBookPropertyRow.ValueArray = valueArray.ToArray();

            return(addressBookPropertyRow);
        }
Esempio n. 4
0
        /// <summary>
        /// Compare whether two AddressBookPropertyRow arrays are equal.
        /// </summary>
        /// <param name="propertyRows1">The first AddressBookPropertyRow array used to compare.</param>
        /// <param name="propertyRows2">The second AddressBookPropertyRow array used to compare.</param>
        /// <returns>Returns true if they are equal; otherwise false.</returns>
        public static bool AreTwoAddressBookPropertyRowEqual(AddressBookPropertyRow[] propertyRows1, AddressBookPropertyRow[] propertyRows2)
        {
            if (propertyRows1.Length != propertyRows2.Length)
            {
                site.Log.Add(
                    LogEntryKind.Debug,
                    "The length of propertyRows1 is {0}, the length of propertyRows2 is {1}.",
                    propertyRows1.Length,
                    propertyRows2.Length);

                return(false);
            }
            else
            {
                for (int i = 0; i < propertyRows1.Length; i++)
                {
                    AddressBookPropertyRow propertyRow1 = propertyRows1[i];
                    AddressBookPropertyRow propertyRow2 = propertyRows2[i];

                    if (propertyRow1.Flag != propertyRow2.Flag)
                    {
                        site.Log.Add(
                            LogEntryKind.Debug,
                            "The value of Flag field of propertyRow1 is {0}, the value of Flag field of propertyRow2 is {1}.",
                            propertyRow1.Flag,
                            propertyRow2.Flag);

                        return(false);
                    }
                    else
                    {
                        List <AddressBookPropertyValue> valueArray1 = new List <AddressBookPropertyValue>();
                        valueArray1.AddRange(propertyRow1.ValueArray);
                        List <AddressBookPropertyValue> valueArray2 = new List <AddressBookPropertyValue>();
                        valueArray2.AddRange(propertyRow2.ValueArray);

                        if (valueArray1.Count != valueArray2.Count)
                        {
                            site.Log.Add(
                                LogEntryKind.Debug,
                                "The length of valueArray1 is {0}, the length of valueArray2 is {1}.",
                                valueArray1.Count,
                                valueArray2.Count);

                            return(false);
                        }
                        else
                        {
                            for (int j = 0; j < valueArray1.Count; j++)
                            {
                                if (valueArray1[j].Value.Length != valueArray2[j].Value.Length)
                                {
                                    site.Log.Add(
                                        LogEntryKind.Debug,
                                        "The length of the first property value is {0}, the length of the second property value is {1}.",
                                        valueArray1[j].Value.Length,
                                        valueArray2[j].Value.Length);

                                    return(false);
                                }
                                else
                                {
                                    byte[] valueOfProperty1 = valueArray1[j].Value;
                                    byte[] valueOfProperty2 = valueArray2[j].Value;

                                    for (int k = 0; k < valueOfProperty1.Length; k++)
                                    {
                                        if (valueOfProperty1[k] != valueOfProperty2[k])
                                        {
                                            site.Log.Add(
                                                LogEntryKind.Debug,
                                                "The {0} bit of the first property value is {1}, The {0} bit of the second property value is {2}.",
                                                valueOfProperty1[k],
                                                valueOfProperty2[k]);

                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }