/// <summary> /// Parse the GetProps request type response body. /// </summary> /// <param name="rawData">The raw data of response.</param> /// <returns>The GetProps request type response body.</returns> public static GetPropsResponseBody Parse(byte[] rawData) { GetPropsResponseBody responseBody = new GetPropsResponseBody(); 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.HasPropertyValues = BitConverter.ToBoolean(rawData, index); index += sizeof(bool); if (responseBody.HasPropertyValues) { responseBody.PropertyValues = AddressBookPropertyValueList.Parse(rawData, ref index); } else { responseBody.PropertyValues = 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 GetSpecialTable request type response body. /// </summary> /// <param name="rawData">The raw data of response.</param> /// <returns>The GetSpecialTable request type response body.</returns> public static GetSpecialTableResponseBody Parse(byte[] rawData) { GetSpecialTableResponseBody responseBody = new GetSpecialTableResponseBody(); 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.HasVersion = BitConverter.ToBoolean(rawData, index); index += sizeof(bool); if (responseBody.HasVersion) { responseBody.Version = BitConverter.ToUInt32(rawData, index); index += sizeof(uint); } else { responseBody.Version = null; } responseBody.HasRows = BitConverter.ToBoolean(rawData, index); index += sizeof(bool); if (responseBody.HasRows) { responseBody.RowCount = BitConverter.ToUInt32(rawData, index); index += sizeof(uint); responseBody.Rows = new AddressBookPropertyValueList[(uint)responseBody.RowCount]; for (int i = 0; i < responseBody.RowCount; i++) { responseBody.Rows[i] = AddressBookPropertyValueList.Parse(rawData, ref index); } } else { responseBody.RowCount = null; responseBody.Rows = 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> /// Compare whether two AddressBookPropValueLists are equal. /// </summary> /// <param name="addressBookPropValueList1">The first AddressBookPropertyValueList used to compare.</param> /// <param name="addressBookPropValueList2">The second AddressBookPropertyValueList used to compare.</param> /// <returns>Returns true if they are equal; otherwise false.</returns> public static bool AreTwoAddressBookPropValueListEqual(AddressBookPropertyValueList addressBookPropValueList1, AddressBookPropertyValueList addressBookPropValueList2) { if (addressBookPropValueList1.PropertyValueCount != addressBookPropValueList2.PropertyValueCount) { site.Log.Add( LogEntryKind.Debug, "The length the two AddressBookPropertyValueList are not equal. The length of addressBookPropValueList1 is {0}, the length of addressBookPropValueList2 is {1}.", addressBookPropValueList1.PropertyValueCount, addressBookPropValueList2.PropertyValueCount); return(false); } else { AddressBookTaggedPropertyValue[] propertyValues1 = addressBookPropValueList1.PropertyValues; AddressBookTaggedPropertyValue[] propertyValues2 = addressBookPropValueList2.PropertyValues; for (int i = 0; i < propertyValues1.Length; i++) { if (propertyValues1[i].PropertyId != propertyValues2[i].PropertyId) { site.Log.Add( LogEntryKind.Debug, "The property ID of property {0} in the two property tag array are not equal. The property ID of propertyTag1 is {1}, the property ID of propertyTag2 is {2}", i, propertyValues1[i].PropertyId, propertyValues2[i].PropertyId); return(false); } else if (propertyValues1[i].PropertyType != propertyValues2[i].PropertyType) { site.Log.Add( LogEntryKind.Debug, "The property type of property {0} in the two property tag array are not equal. The property type of propertyTag1 is {1}, the property type of propertyTag2 is {2}", i, propertyValues1[i].PropertyType, propertyValues2[i].PropertyType); return(false); } } } return(true); }
/// <summary> /// Parse the AddressBookPropertyValueList structure. /// </summary> /// <param name="rawData">The raw data of response buffer.</param> /// <param name="index">The start index.</param> /// <returns>Instance of the AddressBookPropertyValueList.</returns> public static AddressBookPropertyValueList Parse(byte[] rawData, ref int index) { AddressBookPropertyValueList addressBookPropValueList = new AddressBookPropertyValueList(); addressBookPropValueList.PropertyValueCount = BitConverter.ToUInt32(rawData, index); index += sizeof(uint); Context.Instance.PropertyBytes = rawData; Context.Instance.CurIndex = index; Context.Instance.CurProperty = new Property(PropertyType.PtypUnspecified); addressBookPropValueList.PropertyValues = new AddressBookTaggedPropertyValue[addressBookPropValueList.PropertyValueCount]; for (int i = 0; i < addressBookPropValueList.PropertyValueCount; i++) { // Parse the AddressBookTaggedPropertyValue from the response buffer. AddressBookTaggedPropertyValue taggedPropertyValue = new AddressBookTaggedPropertyValue(); taggedPropertyValue.Parse(Context.Instance); addressBookPropValueList.PropertyValues[i] = taggedPropertyValue; } index = Context.Instance.CurIndex; return addressBookPropValueList; }
/// <summary> /// Parse the AddressBookPropertyValueList structure. /// </summary> /// <param name="rawData">The raw data of response buffer.</param> /// <param name="index">The start index.</param> /// <returns>Instance of the AddressBookPropertyValueList.</returns> public static AddressBookPropertyValueList Parse(byte[] rawData, ref int index) { AddressBookPropertyValueList addressBookPropValueList = new AddressBookPropertyValueList(); addressBookPropValueList.PropertyValueCount = BitConverter.ToUInt32(rawData, index); index += sizeof(uint); Context.Instance.PropertyBytes = rawData; Context.Instance.CurIndex = index; Context.Instance.CurProperty = new Property(PropertyType.PtypUnspecified); addressBookPropValueList.PropertyValues = new AddressBookTaggedPropertyValue[addressBookPropValueList.PropertyValueCount]; for (int i = 0; i < addressBookPropValueList.PropertyValueCount; i++) { // Parse the AddressBookTaggedPropertyValue from the response buffer. AddressBookTaggedPropertyValue taggedPropertyValue = new AddressBookTaggedPropertyValue(); taggedPropertyValue.Parse(Context.Instance); addressBookPropValueList.PropertyValues[i] = taggedPropertyValue; } index = Context.Instance.CurIndex; return(addressBookPropValueList); }
/// <summary> /// Compare whether two AddressBookPropValueLists are equal. /// </summary> /// <param name="addressBookPropValueList1">The first AddressBookPropertyValueList used to compare.</param> /// <param name="addressBookPropValueList2">The second AddressBookPropertyValueList used to compare.</param> /// <returns>Returns true if they are equal; otherwise false.</returns> public static bool AreTwoAddressBookPropValueListEqual(AddressBookPropertyValueList addressBookPropValueList1, AddressBookPropertyValueList addressBookPropValueList2) { if (addressBookPropValueList1.PropertyValueCount != addressBookPropValueList2.PropertyValueCount) { site.Log.Add( LogEntryKind.Debug, "The length the two AddressBookPropertyValueList are not equal. The length of addressBookPropValueList1 is {0}, the length of addressBookPropValueList2 is {1}.", addressBookPropValueList1.PropertyValueCount, addressBookPropValueList2.PropertyValueCount); return false; } else { AddressBookTaggedPropertyValue[] propertyValues1 = addressBookPropValueList1.PropertyValues; AddressBookTaggedPropertyValue[] propertyValues2 = addressBookPropValueList2.PropertyValues; for (int i = 0; i < propertyValues1.Length; i++) { if (propertyValues1[i].PropertyId != propertyValues2[i].PropertyId) { site.Log.Add( LogEntryKind.Debug, "The property ID of property {0} in the two property tag array are not equal. The property ID of propertyTag1 is {1}, the property ID of propertyTag2 is {2}", i, propertyValues1[i].PropertyId, propertyValues2[i].PropertyId); return false; } else if (propertyValues1[i].PropertyType != propertyValues2[i].PropertyType) { site.Log.Add( LogEntryKind.Debug, "The property type of property {0} in the two property tag array are not equal. The property type of propertyTag1 is {1}, the property type of propertyTag2 is {2}", i, propertyValues1[i].PropertyType, propertyValues2[i].PropertyType); return false; } } } return true; }
/// <summary> /// Initialize ModProps request body. /// </summary> /// <param name="hasState">A Boolean value that specifies whether the State field is present.</param> /// <param name="stat">A STAT structure that specifies the state of a specific address book container.</param> /// <param name="hasPropertyValues">A Boolean value that specifies whether the PropertyValues field is present.</param> /// <param name="propertyTag">A property tag both identifies a property and gives the data type its value.</param> /// <param name="hasPropertyTagsToRemove">A Boolean value that specifies whether the PropertyTagsToRemove field is present.</param> /// <param name="propertyTagsToRemove">A LargePropTagArray structure that specifies the properties that the client is requesting to be removed. </param> /// <returns>Returns the ModProps request body.</returns> private ModPropsRequestBody BuildModPropsRequestBody(bool hasState, STAT stat, bool hasPropertyValues, PropertyTag propertyTag, bool hasPropertyTagsToRemove, LargePropertyTagArray propertyTagsToRemove) { ModPropsRequestBody modPropsRequestBody = new ModPropsRequestBody(); modPropsRequestBody.Reserved = 0x0; byte[] auxIn = new byte[] { }; modPropsRequestBody.AuxiliaryBuffer = auxIn; modPropsRequestBody.AuxiliaryBufferSize = (uint)auxIn.Length; modPropsRequestBody.HasState = hasState; if (hasState) { modPropsRequestBody.State = stat; } modPropsRequestBody.HasPropertyValues = hasPropertyValues; if (hasPropertyValues) { AddressBookPropertyValueList addressBookProperties = new AddressBookPropertyValueList(); addressBookProperties.PropertyValueCount = 1; AddressBookTaggedPropertyValue[] taggedPropertyValues = new AddressBookTaggedPropertyValue[1]; AddressBookTaggedPropertyValue taggedPropertyValue = new AddressBookTaggedPropertyValue(); taggedPropertyValue.PropertyType = propertyTag.PropertyType; taggedPropertyValue.PropertyId = propertyTag.PropertyId; taggedPropertyValue.Value = new byte[] { 0x00, 0x00 }; taggedPropertyValues[0] = taggedPropertyValue; addressBookProperties.PropertyValues = taggedPropertyValues; modPropsRequestBody.PropertyVaules = addressBookProperties; } modPropsRequestBody.HasPropertyTagsToRemove = hasPropertyTagsToRemove; if (hasPropertyTagsToRemove) { modPropsRequestBody.PropertyTagsToRemove = propertyTagsToRemove; } return modPropsRequestBody; }