This define the base class for a property value node
상속: Node
예제 #1
0
        /// <summary>
        /// Parse bytes in context into a PropertyRowNode
        /// </summary>
        /// <param name="context">The value of Context</param>
        public override void Parse(Context context)
        {
            // Clear PropertyValues to store parsing result
            this.propertyValues.Clear();

            // Flag indicates the Type of PropertyRow
            this.flag = context.PropertyBytes[context.CurIndex++];

            foreach (Property prop in context.Properties)
            {
                if (context.IsEnd())
                {
                    throw new ParseException("End prematurely");
                }
                
                PropertyValue valueNode = null;

                if (this.flag == 0)
                {
                    // StandardPropertyRow
                    if (prop.Type == PropertyType.PtypUnspecified)
                    {
                        valueNode = new TypedPropertyValue();
                    }
                    else
                    {
                        valueNode = new PropertyValue();
                    }
                }
                else
                {
                    // FlaggedPropertyRow
                    if (prop.Type == PropertyType.PtypUnspecified)
                    {
                        valueNode = new FlaggedPropertyValueWithType();
                    }
                    else
                    {
                        valueNode = new FlaggedPropertyValue();
                    }
                }

                context.CurProperty = new Property((PropertyType)prop.Type);
                valueNode.Parse(context);
                this.propertyValues.Add(valueNode);
            }
        }
예제 #2
0
        /// <summary>
        /// Create sample RuleData array to modify the rules associated with a folder.
        /// </summary>
        /// <returns>Return RuleData array to be used in RopModifyRules request.</returns>
        protected RuleData[] CreateSampleRuleDataArrayForAdd()
        {
            int propertyValuesCount = 4;
            PropertyValue[] propertyValues = new PropertyValue[propertyValuesCount];

            for (int i = 0; i < propertyValuesCount; i++)
            {
                propertyValues[i] = new PropertyValue();
            }

            // As specified in section 2.2.1.3.2 in [MS-OXORULE],
            // when adding a PRULE, the client MUST NOT
            // pass in PidTagRuleId, it MUST pass in PidTagRuleCondition,
            // PidTagRuleActions and PidTagRuleProvider.
            TaggedPropertyValue taggedPropertyValue = new TaggedPropertyValue();
            PropertyTag tempPropertyTag = new PropertyTag
            {
                PropertyId = 0x6676, PropertyType = 0003
            };
            taggedPropertyValue.PropertyTag = tempPropertyTag;
            byte[] value3 = { 0x00, 0x00, 0x00, 0x0a };
            taggedPropertyValue.Value = value3;
            propertyValues[3].Value = taggedPropertyValue.Serialize();

            // PidTagRuleCondition
            taggedPropertyValue = new TaggedPropertyValue();
            tempPropertyTag.PropertyId = 0x6679;
            tempPropertyTag.PropertyType = 0x00fd;
            taggedPropertyValue.PropertyTag = tempPropertyTag;
            byte[] value =
            {
                0x03, 0x01, 0x00, 0x01, 0x00, 0x1f, 0x00, 0x37, 0x00, 0x1f, 0x00,
                0x37, 0x00, 0x50, 0x00, 0x72, 0x00, 0x6f, 0x00, 0x6a, 0x00, 0x65,
                0x00, 0x63, 0x00, 0x74, 0x00, 0x20, 0x00, 0x58, 0x00, 0x00, 0x00
            };
            taggedPropertyValue.Value = value;
            propertyValues[1].Value = taggedPropertyValue.Serialize();

            // PidTagRuleAction
            taggedPropertyValue = new TaggedPropertyValue();
            tempPropertyTag.PropertyId = 0x6680;
            tempPropertyTag.PropertyType = 0x00fe;
            taggedPropertyValue.PropertyTag = tempPropertyTag;
            byte[] value1 = { 0x01, 0x00, 0x09, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            taggedPropertyValue.Value = value1;
            propertyValues[2].Value = taggedPropertyValue.Serialize();

            // PidTagRuleProvider
            taggedPropertyValue = new TaggedPropertyValue();
            tempPropertyTag.PropertyId = 0x6681;
            tempPropertyTag.PropertyType = 0x001f;
            taggedPropertyValue.PropertyTag = tempPropertyTag;
            byte[] value2 = Encoding.Unicode.GetBytes("RuleOrganizer\0");
            taggedPropertyValue.Value = value2;
            propertyValues[0].Value = taggedPropertyValue.Serialize();

            RuleData sampleRuleData = new RuleData
            {
                RuleDataFlags = 0x01,
                PropertyValueCount = (ushort)propertyValues.Length,
                PropertyValues = propertyValues
            };

            RuleData[] sampleRuleDataArray = new RuleData[1];
            sampleRuleDataArray[0] = sampleRuleData;

            return sampleRuleDataArray;
        }
예제 #3
0
        /// <summary>
        /// This method creates Sample RecipientColumns and Sample RecipientRows.
        /// </summary>
        /// <param name="recipientColumns">Sample RecipientColumns</param>
        /// <param name="recipientRows">Sample RecipientRows</param>
        protected void CreateSampleRecipientColumnsAndRecipientRows(out PropertyTag[] recipientColumns, out ModifyRecipientRow[] recipientRows)
        {
            // Step 1: Create Sample RecipientColumns.
            #region recipientColumns

            // The following sample data is from MS-OXCMSG 4.7.1.
            PropertyTag[] sampleRecipientColumns = new PropertyTag[12];
            sampleRecipientColumns[0] = this.propertyDictionary[PropertyNames.PidTagObjectType];
            sampleRecipientColumns[1] = this.propertyDictionary[PropertyNames.PidTagDisplayType];
            sampleRecipientColumns[2] = this.propertyDictionary[PropertyNames.PidTagAddressBookDisplayNamePrintable];
            sampleRecipientColumns[3] = this.propertyDictionary[PropertyNames.PidTagSmtpAddress];
            sampleRecipientColumns[4] = this.propertyDictionary[PropertyNames.PidTagSendInternetEncoding];
            sampleRecipientColumns[5] = this.propertyDictionary[PropertyNames.PidTagDisplayTypeEx];
            sampleRecipientColumns[6] = this.propertyDictionary[PropertyNames.PidTagRecipientDisplayName];
            sampleRecipientColumns[7] = this.propertyDictionary[PropertyNames.PidTagRecipientFlags];
            sampleRecipientColumns[8] = this.propertyDictionary[PropertyNames.PidTagRecipientTrackStatus];
            sampleRecipientColumns[9] = this.propertyDictionary[PropertyNames.PidTagRecipientResourceState];
            sampleRecipientColumns[10] = this.propertyDictionary[PropertyNames.PidTagRecipientOrder];
            sampleRecipientColumns[11] = this.propertyDictionary[PropertyNames.PidTagRecipientEntryId];
            recipientColumns = sampleRecipientColumns;

            #endregion

            // Step 2: Configure a StandardPropertyRow: propertyRow.
            #region Configure a StandardPropertyRow: propertyRow, data is from Page 62 of MS-OXCMSG

            PropertyValue[] propertyValueArray = new PropertyValue[12];
            for (int i = 0; i < propertyValueArray.Length; i++)
            {
                propertyValueArray[i] = new PropertyValue();
            }

            // PidTagObjectType
            propertyValueArray[0].Value = BitConverter.GetBytes(0x00000006);

            // PidTagDisplayType
            propertyValueArray[1].Value = BitConverter.GetBytes(0x00000000);

            // PidTa7BitDisplayName
            propertyValueArray[2].Value = Encoding.Unicode.GetBytes(Common.GetConfigurationPropertyValue("EmailAlias", this.Site) + "\0");

            // PidTagSmtpAddress
            propertyValueArray[3].Value = Encoding.Unicode.GetBytes(Common.GetConfigurationPropertyValue("EmailAlias", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site) + "\0");

            // PidTagSendInternetEncoding
            propertyValueArray[4].Value = BitConverter.GetBytes(0x00000000);

            // PidTagDisplayTypeEx
            propertyValueArray[5].Value = BitConverter.GetBytes(0x40000000);

            // PidTagRecipientDisplayName
            propertyValueArray[6].Value = Encoding.Unicode.GetBytes(Common.GetConfigurationPropertyValue("EmailAlias", this.Site) + "\0");

            // PidTagRecipientFlags
            propertyValueArray[7].Value = BitConverter.GetBytes(0x00000001);

            // PidTagRecipientTrackStatus
            propertyValueArray[8].Value = BitConverter.GetBytes(0x00000000);

            // PidTagRecipientResourceState
            propertyValueArray[9].Value = BitConverter.GetBytes(0x00000000);

            // PidTagRecipientOrder
            propertyValueArray[10].Value = BitConverter.GetBytes(0x00000000);

            // The following sample data (0x007c and the subsequent 124(0x7c) binary)
            // is copied from Page 62 of MS-OXCMSG
            byte[] sampleData = 
            { 
                0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0xa7, 0x40, 0xc8,
                0xc0, 0x42, 0x10, 0x1a, 0xb4, 0xb9, 0x08, 0x00, 0x2b, 0x2f,
                0xe1, 0x82, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x2f, 0x6f, 0x3d, 0x46, 0x69, 0x72, 0x73, 0x74, 0x20, 0x4f,
                0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f,
                0x6e, 0x2f, 0x6f, 0x75, 0x3d, 0x45, 0x78, 0x63, 0x68, 0x61,
                0x6e, 0x67, 0x65, 0x20, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x69,
                0x73, 0x74, 0x72, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x47,
                0x72, 0x6f, 0x75, 0x70, 0x20, 0x28, 0x46, 0x59, 0x44, 0x49,
                0x42, 0x4f, 0x48, 0x46, 0x32, 0x33, 0x53, 0x50, 0x44, 0x4c,
                0x54, 0x29, 0x2f, 0x63, 0x6e, 0x3d, 0x52, 0x65, 0x63, 0x69,
                0x70, 0x69, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x63, 0x6e, 0x3d,
                0x75, 0x73, 0x65, 0x72, 0x32, 0x00 
            };

            // PidTagRecipientEntryId
            propertyValueArray[11].Value = sampleData;

            List<PropertyValue> propertyValues = new List<PropertyValue>();
            for (int i = 0; i < propertyValueArray.Length; i++)
            {
                propertyValues.Add(propertyValueArray[i]);
            }

            PropertyRow propertyRow = new PropertyRow
            {
                Flag = (byte)PropertyRowFlag.FlaggedPropertyRow,
                PropertyValues = propertyValues
            };

            // For propertyRow.Flag
            int tempLengthForTest = 1;
            foreach (PropertyValue pv in propertyRow.PropertyValues)
            {
                tempLengthForTest = tempLengthForTest + pv.Value.Length;
            }

            #endregion

            // Step 3: Create Sample RecipientRows.
            #region recipientRows

            RecipientRow recipientRow = new RecipientRow
            {
                // 0101 1001 0000 0110 S,D, Type=SMTP,I,U,E
                RecipientFlags = (ushort)(
                    RecipientFlags.SMTP
                    | RecipientFlags.S
                    | RecipientFlags.D
                    | RecipientFlags.I
                    | RecipientFlags.U
                    | RecipientFlags.E),

                // Set DisplayName, which specifies the Email Address of the recipient, as specified in [MS-OXCDATA].
                // This field is present because D is Set.
                DisplayName = Encoding.Unicode.GetBytes(TestSuiteBase.DisplayNameAndCommentForNonSearchFolder + "\0"),

                // Set EmailAddress, which specifies the Email Address of the recipient,
                // as specified in [MS-OXCDATA].
                EmailAddress =
                    Encoding.Unicode.GetBytes(Common.GetConfigurationPropertyValue("EmailAlias", this.Site) + "@" +
                                              Common.GetConfigurationPropertyValue("Domain", this.Site) + "\0"),

                // Set SimpleDisplayName, which specifies the Email Address of the recipient,
                // as specified in [MS-OXCDATA].
                SimpleDisplayName =
                    Encoding.Unicode.GetBytes(Common.GetConfigurationPropertyValue("EmailAlias", this.Site) + "\0"),

                // Set RecipientColumnCount, which specifies the number of columns from the RecipientColumns field
                // that are included in RecipientProperties, as specified in [MS-OXCDATA].
                RecipientColumnCount = RecipientColumnCount,
                RecipientProperties = propertyRow
            };
            ModifyRecipientRow modifyRecipientRow = new ModifyRecipientRow
            {
                RowId = RowId, // Set RowId, which value specifies the ID of the recipient.
                RecipientType = (byte)RecipientType.PrimaryRecipient,
                RecipientRowSize = (ushort)recipientRow.Size(), // Set RecipientRowSize, which specifies the size of the RecipientRow field.
                RecptRow = recipientRow.Serialize()
            };
            ModifyRecipientRow[] sampleModifyRecipientRows = new ModifyRecipientRow[1];
            sampleModifyRecipientRows[0] = modifyRecipientRow;
            recipientRows = sampleModifyRecipientRows;

            #endregion
        }
        /// <summary>
        /// Generate recipientColumns value and recipientRows value.
        /// </summary>
        /// <param name="recipientColumns">recipientColumns value.</param>
        /// <param name="recipientRows">recipientRows value.</param>
        private void CreateSampleRecipientColumnsAndRecipientRows(out PropertyTag[] recipientColumns, out ModifyRecipientRow[] recipientRows)
        {
            PropertyTag[] sampleRecipientColumns = new PropertyTag[12];
            PropertyTag tag;

            // PidTagObjectType
            tag.PropertyId = 0x0ffe;

            // PtypInteger32
            tag.PropertyType = 0x0003;
            sampleRecipientColumns[0] = tag;

            // PidTagDisplayType
            tag.PropertyId = 0x3900;

            // PtypInteger32
            tag.PropertyType = 0x0003;
            sampleRecipientColumns[1] = tag;

            // PidTagAddressBookDisplayNamePrintable
            tag.PropertyId = 0x39ff;

            // PtypString
            tag.PropertyType = 0x001f;
            sampleRecipientColumns[2] = tag;

            // PidTagSmtpAddress
            tag.PropertyId = 0x39fe;

            // PtypString
            tag.PropertyType = 0x001f;
            sampleRecipientColumns[3] = tag;

            // PidTagSendInternetEncoding
            tag.PropertyId = 0x3a71;

            // PtypInteger32
            tag.PropertyType = 0x0003;
            sampleRecipientColumns[4] = tag;

            // PidTagDisplayTypeEx
            tag.PropertyId = 0x3905;

            // PtypInteger32
            tag.PropertyType = 0x0003;
            sampleRecipientColumns[5] = tag;

            // PidTagRecipientDisplayName
            tag.PropertyId = 0x5ff6;
            tag.PropertyType = 0x001f; // PtypString
            sampleRecipientColumns[6] = tag;

            // PidTagRecipientFlags
            tag.PropertyId = 0x5ffd;

            // PtypInteger32
            tag.PropertyType = 0x0003;
            sampleRecipientColumns[7] = tag;

            // PidTagRecipientTrackStatus
            tag.PropertyId = 0x5fff;

            // PtypInteger32
            tag.PropertyType = 0x0003;
            sampleRecipientColumns[8] = tag;

            // PidTagRecipientResourceState
            tag.PropertyId = 0x5fde;

            // PtypInteger32
            tag.PropertyType = 0x0003;
            sampleRecipientColumns[9] = tag;

            // PidTagRecipientOrder
            tag.PropertyId = 0x5fdf;

            // PtypInteger32
            tag.PropertyType = 0x0003;
            sampleRecipientColumns[10] = tag;

            // PidTagRecipientEntryId
            tag.PropertyId = 0x5ff7;

            // PtypBinary
            tag.PropertyType = 0x0102;
            sampleRecipientColumns[11] = tag;

            recipientColumns = sampleRecipientColumns;

            PropertyValue[] propertyValueArray = new PropertyValue[12];
            for (int i = 0; i < propertyValueArray.Length; i++)
            {
                propertyValueArray[i] = new PropertyValue();
            }

            propertyValueArray[0].Value = BitConverter.GetBytes(0x00000006); // PidTagObjectType
            propertyValueArray[1].Value = BitConverter.GetBytes(0x00000000); // PidTagDisplayType
            propertyValueArray[2].Value = Encoding.Unicode.GetBytes(Common.GetConfigurationPropertyValue("AdminUserName", this.Site) + "\0"); // PidTa7BitDisplayName
            propertyValueArray[3].Value = Encoding.Unicode.GetBytes(Common.GetConfigurationPropertyValue("AdminUserName", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site) + "\0"); // PidTagSmtpAddress
            propertyValueArray[4].Value = BitConverter.GetBytes(0x00000000); // PidTagSendInternetEncoding
            propertyValueArray[5].Value = BitConverter.GetBytes(0x40000000); // PidTagDisplayTypeEx
            propertyValueArray[6].Value = Encoding.Unicode.GetBytes(Common.GetConfigurationPropertyValue("AdminUserName", this.Site) + "\0"); // PidTagRecipientDisplayName
            propertyValueArray[7].Value = BitConverter.GetBytes(0x00000001); // PidTagRecipientFlags
            propertyValueArray[8].Value = BitConverter.GetBytes(0x00000000); // PidTagRecipientTrackStatus
            propertyValueArray[9].Value = BitConverter.GetBytes(0x00000000); // PidTagRecipientResourceState
            propertyValueArray[10].Value = BitConverter.GetBytes(0x00000000); // PidTagRecipientOrder

            // EntryId of administrator 
            byte[] sampleData = ConvertStringToBytes(@"0x79,0x00,0x00,0x00,0x00,0x00,0xDC,0xA7,0x40,0xC8,0xC0,0x42
                                                           ,0x10,0x1A,0xB4,0xB9,0x08,0x00,0x2B,0x2F,0xE1,0x82
                                                           ,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2F,0x6F
                                                           ,0x3D,0x63,0x6F,0x6E,0x74,0x6F,0x73,0x6F,0x2F,0x6F
                                                           ,0x75,0x3D,0x45,0x78,0x63,0x68,0x61,0x6E,0x67,0x65
                                                           ,0x20,0x41,0x64,0x6D,0x69,0x6E,0x69,0x73,0x74,0x72
                                                           ,0x61,0x74,0x69,0x76,0x65,0x20,0x47,0x72,0x6F,0x75
                                                           ,0x70,0x20,0x28,0x46,0x59,0x44,0x49,0x42,0x4F,0x48
                                                           ,0x46,0x32,0x33,0x53,0x50,0x44,0x4C,0x54,0x29,0x2F
                                                           ,0x63,0x6E,0x3D,0x52,0x65,0x63,0x69,0x70,0x69,0x65
                                                           ,0x6E,0x74,0x73,0x2F,0x63,0x6E,0x3D,0x41,0x64,0x6D
                                                           ,0x69,0x6E,0x69,0x73,0x74,0x72,0x61,0x74,0x6F,0x72
                                                           ,0x00");
            propertyValueArray[11].Value = sampleData;

            List<PropertyValue> propertyValues = new List<PropertyValue>();
            for (int i = 0; i < propertyValueArray.Length; i++)
            {
                propertyValues.Add(propertyValueArray[i]);
            }

            PropertyRow propertyRow = new PropertyRow
            {
                Flag = 0x00,
                PropertyValues = propertyValues
            };

            // For propertyRow.Flag.
            int tempLengthForTest = 1;
            foreach (PropertyValue pv in propertyRow.PropertyValues)
            {
                tempLengthForTest = tempLengthForTest + pv.Value.Length;
            }

            RecipientRow recipientRow = new RecipientRow
            {
                RecipientFlags = 0x065B,

                // Present because D is Set.
                DisplayName = Encoding.Unicode.GetBytes(Common.GetConfigurationPropertyValue("AdminUserName", this.Site) + "\0"),
                EmailAddress = Encoding.Unicode.GetBytes(Common.GetConfigurationPropertyValue("AdminUserName", this.Site) + "@" +
                                              Common.GetConfigurationPropertyValue("Domain", this.Site) + "\0"),
                SimpleDisplayName = Encoding.Unicode.GetBytes(Common.GetConfigurationPropertyValue("AdminUserName", this.Site) + "\0"),

                // Matches ColummnCount.
                RecipientColumnCount = 0x000C,
                RecipientProperties = propertyRow
            };

            ModifyRecipientRow modifyRecipientRow = new ModifyRecipientRow
            {
                // Primary Recipient.
                RowId = 0x00000000,
                RecipientType = 0x01,
                RecipientRowSize = (ushort)recipientRow.Size(),

                // Bytes in the following RecipientRow.
                RecptRow = recipientRow.Serialize()
            };

            ModifyRecipientRow[] sampleModifyRecipientRows = new ModifyRecipientRow[1];
            sampleModifyRecipientRows[0] = modifyRecipientRow;
            recipientRows = sampleModifyRecipientRows;
        }
        /// <summary>
        /// Revert the permissions list.
        /// </summary>
        public override void Reset()
        {
            this.Logon(this.User2);

            uint folderHandle = this.GetFolderObjectHandle(FolderTypeEnum.CommonFolderType);
            
            // Clean up the folder
            RopHardDeleteMessagesAndSubfoldersRequest deleteSubfoldersOfInboxRequest = new RopHardDeleteMessagesAndSubfoldersRequest
            {
                RopId = 0x92,
                InputHandleIndex = 0x00,
                WantAsynchronous = 0x00,
                WantDeleteAssociated = 0xff
            };
            this.DoRopCall(deleteSubfoldersOfInboxRequest, folderHandle, ref this.response, ref this.rawData);

            RopHardDeleteMessagesAndSubfoldersResponse deleteSubfoldersOfInboxResponse = (RopHardDeleteMessagesAndSubfoldersResponse)this.response;
            Site.Assert.AreEqual<uint>(0, deleteSubfoldersOfInboxResponse.ReturnValue, "0 indicates the ROP succeeds, other value indicates error occurs.");

            this.messageIdsCreatedByOther.Clear();
            this.ownedMessageIds.Clear();

            // Restore the permissions for the user configured by the "User1Name"
            for (int i = 0; i < this.originalPermissionsList.Count; i++)
            {
                if (this.originalPermissionsList[i].PidTagMemberName == this.User1)
                {
                    PermissionData[] revertPermissionData = new PermissionData[1];
                    PermissionData permission = new PermissionData
                    {
                        PermissionDataFlags = 0x01
                    };

                    PropertyValue[] propertyValues = new PropertyValue[2];
                    propertyValues[0] = this.CreateEntryIdProperty(this.originalPermissionsList[i].PidTagMemberName);
                    propertyValues[1] = this.CreateRightsProperty(this.originalPermissionsList[i].PidTagMemberRights);
                    permission.PropertyValueCount = (ushort)propertyValues.Length;
                    permission.PropertyValues = propertyValues;

                    revertPermissionData[0] = permission;
                    RequestBufferFlags requestBufferFlags = new RequestBufferFlags
                    {
                        IsReplaceRowsFlagSet = false
                    };

                    // Call RopModifyPermissions to revert the permissions list.
                    this.responseSOHs = this.DoRopCall(
                        this.CreateModifyPermissionsRequestBuffer(revertPermissionData, requestBufferFlags),
                        folderHandle,
                        ref this.response,
                        ref this.rawData);

                    RopModifyPermissionsResponse modifyPermissionsResponse = (RopModifyPermissionsResponse)this.response;
                    Site.Log.Add(LogEntryKind.Comment, "The return value for restore the permissions in Reset(): {0:X}", modifyPermissionsResponse.ReturnValue);
                    break;
                }
                else
                {
                    this.RemovePermission(FolderTypeEnum.CommonFolderType, this.User1, new RequestBufferFlags());
                }
            }

            this.ReleaseObject(folderHandle);
            base.Reset();
        }
        /// <summary>
        /// Set the permissionData array for removing by the PidTagMemberId
        /// </summary>
        /// <param name="pidTagMemberId">The PidTagMemberId</param>
        /// <returns>Return the permissionData Array</returns>
        private PermissionData[] SetPermissionDataArrayForRemove(ulong pidTagMemberId)
        {
            PropertyValue[] propertyValues = new PropertyValue[1];

            propertyValues[0] = this.CreateMemberIdProperty(pidTagMemberId);

            PermissionData[] permissionsDataArray = new PermissionData[1];
            permissionsDataArray[0].PermissionDataFlags = 0x04; // RemoveRow flags 
            permissionsDataArray[0].PropertyValueCount = (ushort)propertyValues.Length;
            permissionsDataArray[0].PropertyValues = propertyValues;

            return permissionsDataArray;
        }
        /// <summary>
        /// Set the permissionData array for modifying by the PidTagMemberId and PidTagMemberRights.
        /// </summary>
        /// <param name="pidTagMemberId">The pidTagMemberId that specifies the unique identifier that the server generates for each user. </param>
        /// <param name="memberRights">The permission data</param>
        /// <returns>The permissionData array</returns>
        private PermissionData[] SetPermissionDataArrayForModify(ulong pidTagMemberId, uint memberRights)
        {
            PropertyValue[] propertyValues = new PropertyValue[2];

            propertyValues[0] = this.CreateMemberIdProperty(pidTagMemberId);

            propertyValues[1] = this.CreateRightsProperty(memberRights);

            PermissionData[] permissionsDataArray = new PermissionData[1];
            permissionsDataArray[0].PermissionDataFlags = 0x02; // ModifyRow flags 
            permissionsDataArray[0].PropertyValueCount = (ushort)propertyValues.Length;
            permissionsDataArray[0].PropertyValues = propertyValues;

            return permissionsDataArray;
        }
        /// <summary>
        /// Set the permissionData array for adding by the permissionUserName and permissionRight
        /// </summary>
        /// <param name="permissionUserName">The user whose permission is for adding</param>
        /// <param name="memberRights">The rights will be assigned to user</param>
        /// <returns>Return the permissionData array for adding user</returns>
        private PermissionData[] SetPermissionDataArrayForAdd(string permissionUserName, uint memberRights)
        {
            PropertyValue[] propertyValues = new PropertyValue[2];
            propertyValues[0] = this.CreateRightsProperty(memberRights);
            propertyValues[1] = this.CreateEntryIdProperty(permissionUserName);

            PermissionData[] permissionsDataArray = new PermissionData[1];
            permissionsDataArray[0].PermissionDataFlags = 0x01; // AddRow flags 
            permissionsDataArray[0].PropertyValueCount = (ushort)propertyValues.Length;
            permissionsDataArray[0].PropertyValues = propertyValues;

            return permissionsDataArray;
        }
        /// <summary>
        /// Create Recipient Array 
        /// </summary>
        /// <param name="recipientColumns">Recipient Columns </param>
        /// <param name="recipientRows">Recipient Rows</param>
        private void CreateRecipientColumnsAndRecipientRows(out PropertyTag[] recipientColumns, out ModifyRecipientRow[] recipientRows)
        {
            #region recipientColumns

            // The following sample data is from MS-OXCMSG
            PropertyTag[] sampleRecipientColumns = new PropertyTag[12];
            PropertyTag tag;

            // PidTagObjectType
            tag.PropertyId = 0x0ffe;
            tag.PropertyType = 0x0003; // PtypInteger32
            sampleRecipientColumns[0] = tag;

            // PidTagDisplayType
            tag.PropertyId = 0x3900;
            tag.PropertyType = 0x0003; // PtypInteger32
            sampleRecipientColumns[1] = tag;

            // PidTagAddressBookDisplayNamePrintable
            tag.PropertyId = 0x39ff;
            tag.PropertyType = 0x001f; // PtypString
            sampleRecipientColumns[2] = tag;

            // PidTagSmtpAddress
            tag.PropertyId = 0x39fe;
            tag.PropertyType = 0x001f; // PtypString
            sampleRecipientColumns[3] = tag;

            // PidTagSendInternetEncoding
            tag.PropertyId = 0x3a71;
            tag.PropertyType = 0x0003; // PtypInteger32
            sampleRecipientColumns[4] = tag;

            // PidTagDisplayTypeEx
            tag.PropertyId = 0x3905;
            tag.PropertyType = 0x0003; // PtypInteger32
            sampleRecipientColumns[5] = tag;

            // PidTagRecipientDisplayName
            tag.PropertyId = 0x5ff6;
            tag.PropertyType = 0x001f; // PtypString
            sampleRecipientColumns[6] = tag;

            // PidTagRecipientFlags
            tag.PropertyId = 0x5ffd;
            tag.PropertyType = 0x0003; // PtypInteger32
            sampleRecipientColumns[7] = tag;

            // PidTagRecipientTrackStatus
            tag.PropertyId = 0x5fff;
            tag.PropertyType = 0x0003; // PtypInteger32
            sampleRecipientColumns[8] = tag;

            // PidTagRecipientResourceState
            tag.PropertyId = 0x5fde;
            tag.PropertyType = 0x0003; // PtypInteger32
            sampleRecipientColumns[9] = tag;

            // PidTagRecipientOrder
            tag.PropertyId = 0x5fdf;
            tag.PropertyType = 0x0003; // PtypInteger32
            sampleRecipientColumns[10] = tag;

            // PidTagRecipientEntryId
            tag.PropertyId = 0x5ff7;
            tag.PropertyType = 0x0102; // PtypBinary
            sampleRecipientColumns[11] = tag;

            recipientColumns = sampleRecipientColumns;
            #endregion

            #region Configure a StandardPropertyRow: propertyRow, data is from Page 62 of MS-OXCMSG

            PropertyValue[] propertyValueArray = new PropertyValue[12];
            for (int i = 0; i < propertyValueArray.Length; i++)
            {
                propertyValueArray[i] = new PropertyValue();
            }

            propertyValueArray[0].Value = BitConverter.GetBytes(0x00000006); // PidTagObjectType
            propertyValueArray[1].Value = BitConverter.GetBytes(0x00000000); // PidTagDisplayType
            propertyValueArray[2].Value = Encoding.Unicode.GetBytes(UserName + TestSuiteBase.NullTerminatorString); // PidTa7BitDisplayName
            string domainName = Common.GetConfigurationPropertyValue("Domain", this.Site);
            propertyValueArray[3].Value = Encoding.Unicode.GetBytes(UserName + TestSuiteBase.At + domainName + TestSuiteBase.NullTerminatorString); // PidTagSmtpAddress
            propertyValueArray[4].Value = BitConverter.GetBytes(0x00000000); // PidTagSendInternetEncoding
            propertyValueArray[5].Value = BitConverter.GetBytes(0x40000000); // PidTagDisplayTypeEx
            propertyValueArray[6].Value = Encoding.Unicode.GetBytes(UserName + TestSuiteBase.NullTerminatorString); // PidTagRecipientDisplayName
            propertyValueArray[7].Value = BitConverter.GetBytes(0x00000001); // PidTagRecipientFlags
            propertyValueArray[8].Value = BitConverter.GetBytes(0x00000000); // PidTagRecipientTrackStatus
            propertyValueArray[9].Value = BitConverter.GetBytes(0x00000000); // PidTagRecipientResourceState
            propertyValueArray[10].Value = BitConverter.GetBytes(0x00000000); // PidTagRecipientOrder

            // The following sample data (0x007c and the subsequent 124(0x7c) binary) 
            byte[] sampleData = 
            {
                0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0xa7, 0x40,
                0xc8, 0xc0, 0x42, 0x10, 0x1a, 0xb4, 0xb9, 0x08, 0x00, 0x2b, 0x2f, 0xe1, 0x82, 0x01, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x2f, 0x6f, 0x3d, 0x46, 0x69, 0x72, 0x73, 0x74, 0x20, 0x4f, 0x72,
                0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6f, 0x75, 0x3d, 0x45, 0x78,
                0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x20, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x69, 0x73, 0x74, 0x72,
                0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x28, 0x46, 0x59, 0x44,
                0x49, 0x42, 0x4f, 0x48, 0x46, 0x32, 0x33, 0x53, 0x50, 0x44, 0x4c, 0x54, 0x29, 0x2f, 0x63, 0x6e,
                0x3d, 0x52, 0x65, 0x63, 0x69, 0x70, 0x69, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x63, 0x6e, 0x3d, 0x75,
                0x73, 0x65, 0x72, 0x32, 0x00
            };
            propertyValueArray[11].Value = sampleData; // PidTagRecipientEntryId

            List<PropertyValue> propertyValues = new List<PropertyValue>();
            for (int i = 0; i < propertyValueArray.Length; i++)
            {
                propertyValues.Add(propertyValueArray[i]);
            }

            PropertyRow propertyRow = new PropertyRow
            {
                Flag = 0x01, PropertyValues = propertyValues
            };
            #endregion

            RecipientRow recipientRow = new RecipientRow
            {
                RecipientFlags = 0x065B,
                DisplayName = Encoding.Unicode.GetBytes(UserName + TestSuiteBase.NullTerminatorString),
                EmailAddress = Encoding.Unicode.GetBytes(UserName + TestSuiteBase.At + domainName + TestSuiteBase.NullTerminatorString),
                SimpleDisplayName = Encoding.Unicode.GetBytes(UserName + TestSuiteBase.NullTerminatorString),
                RecipientColumnCount = 0x000C,
                RecipientProperties = propertyRow
            };

            ModifyRecipientRow modifyRecipientRow = new ModifyRecipientRow
            {
                RowId = 0x00000000,
                RecipientType = (byte)RecipientType.PrimaryRecipient,
                RecipientRowSize = (ushort)recipientRow.Size(),
                RecptRow = recipientRow.Serialize()
            };

            ModifyRecipientRow[] sampleModifyRecipientRows = new ModifyRecipientRow[3];
            sampleModifyRecipientRows[0] = modifyRecipientRow;

            // Test add second recipient 
            ModifyRecipientRow testmodifyRecipientRow = new ModifyRecipientRow
            {
                RowId = 0x0000001,
                RecipientType = (byte)RecipientType.PrimaryRecipient,
                RecipientRowSize = (ushort)recipientRow.Size(),
                RecptRow = recipientRow.Serialize()
            };
            sampleModifyRecipientRows[1] = testmodifyRecipientRow;

            ModifyRecipientRow test2modifyRecipientRow = new ModifyRecipientRow
            {
                RowId = 0x0000002,
                RecipientType = (byte)RecipientType.PrimaryRecipient,
                RecipientRowSize = (ushort)recipientRow.Size(),
                RecptRow = recipientRow.Serialize()
            };
            sampleModifyRecipientRows[2] = test2modifyRecipientRow;

            recipientRows = sampleModifyRecipientRows;
        }
        /// <summary>
        /// Set the permission data array for the specified user.
        /// </summary>
        /// <param name="userEssdn">The ESSDN of the specified user.</param>
        /// <param name="rights">The rights which will be assigned to the specified user.</param>
        /// <returns>The permission data array for the specified user.</returns>
        private PermissionData[] GetPermissionDataArrayForAdd(string userEssdn, uint rights)
        {
            PropertyValue[] propertyValues = new PropertyValue[2];
            propertyValues[0] = this.CreateRightsProperty(rights);
            propertyValues[1] = this.CreateEntryIdProperty(userEssdn);

            PermissionData[] permissionsDataArray = new PermissionData[1];
            permissionsDataArray[0].PermissionDataFlags = (byte)PermissionDataFlags.AddRow;
            permissionsDataArray[0].PropertyValueCount = (ushort)propertyValues.Length;
            permissionsDataArray[0].PropertyValues = propertyValues;

            return permissionsDataArray;
        }
        /// <summary>
        /// Submit a message to the server
        /// </summary>
        /// <param name="mailTo">The user name of the recipient</param>
        /// <param name="mailToUserDN">The userDN of the recipient</param>
        /// <param name="subject">The subject of the mail</param>
        /// <param name="addedProperties">The added properties of the mail</param>
        /// <returns>Return code of the message delivering</returns>
        public uint DeliverMessageToTriggerRule(string mailTo, string mailToUserDN, string subject, TaggedPropertyValue[] addedProperties)
        {
            RopCreateMessageResponse createMsgRes;
            uint msgHandle = this.OxoruleAdapter.RopCreateMessage(outBoxFolderHandle, outBoxFolderID, 0, out createMsgRes);
            TaggedPropertyValue[] clientSpecificProperties = new TaggedPropertyValue[1];
            clientSpecificProperties[0] = new TaggedPropertyValue();
            PropertyTag propertyTag = new PropertyTag
            {
                PropertyId = (ushort)PropertyId.PidTagSubject,
                PropertyType = (ushort)PropertyType.PtypString
            };
            clientSpecificProperties[0].PropertyTag = propertyTag;
            clientSpecificProperties[0].Value = Encoding.Unicode.GetBytes(subject + "\0");
            this.OxoruleAdapter.RopSetProperties(msgHandle, clientSpecificProperties);
            if (addedProperties != null && addedProperties.Length > 0)
            {
                this.OxoruleAdapter.RopSetProperties(msgHandle, addedProperties);
            }

            #region recipientColumns,  PropertyTag[] sampleRecipientColumns
            // The following sample data is from MS-OXCMSG 4.7.1
            PropertyTag[] sampleRecipientColumns = new PropertyTag[12];
            PropertyTag tag = new PropertyTag
            {
                PropertyId = (ushort)PropertyId.PidTagObjectType,
                PropertyType = (ushort)PropertyType.PtypInteger32
            };

            // PidTagObjectType
            sampleRecipientColumns[0] = tag;

            // PidTagDisplayType
            tag.PropertyId = (ushort)PropertyId.PidTagDisplayType;
            tag.PropertyType = (ushort)PropertyType.PtypInteger32;
            sampleRecipientColumns[1] = tag;

            // PidTagAddressBookDisplayNamePrintable
            tag.PropertyId = (ushort)PropertyId.PidTagAddressBookDisplayNamePrintable;
            tag.PropertyType = (ushort)PropertyType.PtypString;
            sampleRecipientColumns[2] = tag;

            // PidTagSmtpAddress
            tag.PropertyId = (ushort)PropertyId.PidTagSmtpAddress;
            tag.PropertyType = (ushort)PropertyType.PtypString;
            sampleRecipientColumns[3] = tag;

            // PidTagSendInternetEncoding
            tag.PropertyId = (ushort)PropertyId.PidTagSendInternetEncoding;
            tag.PropertyType = (ushort)PropertyType.PtypInteger32;
            sampleRecipientColumns[4] = tag;

            // PidTagDisplayTypeEx
            tag.PropertyId = (ushort)PropertyId.PidTagDisplayTypeEx;
            tag.PropertyType = (ushort)PropertyType.PtypInteger32;
            sampleRecipientColumns[5] = tag;

            // PidTagRecipientDisplayName
            tag.PropertyId = (ushort)PropertyId.PidTagRecipientDisplayName;
            tag.PropertyType = (ushort)PropertyType.PtypString;
            sampleRecipientColumns[6] = tag;

            // PidTagRecipientFlags
            tag.PropertyId = (ushort)PropertyId.PidTagRecipientFlags;
            tag.PropertyType = (ushort)PropertyType.PtypInteger32;
            sampleRecipientColumns[7] = tag;

            // PidTagRecipientTrackStatus
            tag.PropertyId = (ushort)PropertyId.PidTagRecipientTrackStatus;
            tag.PropertyType = (ushort)PropertyType.PtypInteger32;
            sampleRecipientColumns[8] = tag;

            // PidTagRecipientResourceState
            tag.PropertyId = (ushort)PropertyId.PidTagRecipientResourceState;
            tag.PropertyType = (ushort)PropertyType.PtypInteger32;
            sampleRecipientColumns[9] = tag;

            // PidTagRecipientOrder
            tag.PropertyId = (ushort)PropertyId.PidTagRecipientOrder;
            tag.PropertyType = (ushort)PropertyType.PtypInteger32;
            sampleRecipientColumns[10] = tag;

            // PidTagRecipientEntryId
            tag.PropertyId = (ushort)PropertyId.PidTagRecipientEntryId;
            tag.PropertyType = (ushort)PropertyType.PtypBinary;
            sampleRecipientColumns[11] = tag;
            #endregion

            #region Configure a StandardPropertyRow: propertyRow
            PropertyValue[] propertyValueArray = new PropertyValue[12];
            for (int i = 0; i < propertyValueArray.Length; i++)
            {
                propertyValueArray[i] = new PropertyValue();
            }

            // PidTagObjectType
            propertyValueArray[0].Value = BitConverter.GetBytes(0x00000006);

            // PidTagDisplayType
            propertyValueArray[1].Value = BitConverter.GetBytes(0x00000000);

            // PidTagAddressBookDisplayNamePrintable
            propertyValueArray[2].Value = Encoding.Unicode.GetBytes(mailTo + "\0");

            // PidTagSmtpAddress
            propertyValueArray[3].Value = Encoding.Unicode.GetBytes(mailTo + "@" + this.Domain + "\0");

            // PidTagSendInternetEncoding
            propertyValueArray[4].Value = BitConverter.GetBytes(0x00000000);

            // PidTagDisplayTypeEx
            propertyValueArray[5].Value = BitConverter.GetBytes(0x40000000);

            // PidTagRecipientDisplayName
            propertyValueArray[6].Value = Encoding.Unicode.GetBytes(mailTo + "\0");

            // PidTagRecipientFlags
            propertyValueArray[7].Value = BitConverter.GetBytes(0x00000001);

            // PidTagRecipientTrackStatus
            propertyValueArray[8].Value = BitConverter.GetBytes(0x00000000);

            // PidTagRecipientResourceState
            propertyValueArray[9].Value = BitConverter.GetBytes(0x00000000);

            // PidTagRecipientOrder
            propertyValueArray[10].Value = BitConverter.GetBytes(0x00000000);

            AddressBookEntryID addressBookEntryID = new AddressBookEntryID(mailToUserDN);
            propertyValueArray[11].Value = Common.AddInt16LengthBeforeBinaryArray(addressBookEntryID.Serialize());

            List<PropertyValue> propertyValues = new List<PropertyValue>();
            for (int i = 0; i < propertyValueArray.Length; i++)
            {
                propertyValues.Add(propertyValueArray[i]);
            }

            PropertyRow propertyRow = new PropertyRow
            {
                Flag = 0x01,
                PropertyValues = propertyValues
            };
            #endregion

            RecipientRow recipientRow = new RecipientRow
            {
                RecipientFlags = 0x065B,
                DisplayName = Encoding.Unicode.GetBytes(mailTo + "\0"),
                EmailAddress = Encoding.Unicode.GetBytes(mailTo + "@" + this.Domain + "\0"),
                SimpleDisplayName = Encoding.Unicode.GetBytes(mailTo + "\0"),
                RecipientColumnCount = 0x000C,
                RecipientProperties = propertyRow
            };

            ModifyRecipientRow modifyRecipientRow = new ModifyRecipientRow
            {
                RowId = 0x00000000,
                RecipientType = 0x01,
                RecipientRowSize = (ushort)recipientRow.Size(),
                RecptRow = recipientRow.Serialize()
            };

            ModifyRecipientRow[] sampleModifyRecipientRows = new ModifyRecipientRow[1];
            sampleModifyRecipientRows[0] = modifyRecipientRow;
            this.OxoruleAdapter.RopModifyRecipients(msgHandle, sampleRecipientColumns, sampleModifyRecipientRows);
            this.OxoruleAdapter.RopSaveChangesMessage(msgHandle);
            RopSubmitMessageResponse submitMsgRes = this.OxoruleAdapter.RopSubmitMessage(msgHandle, 0);
            return submitMsgRes.ReturnValue;
        }
        /// <summary>
        /// Create RecipientColumns
        /// </summary>
        /// <param name="name">Recipient name</param>
        /// <returns>Return PropertyRow</returns>
        protected PropertyRow CreateRecipientColumns(string name)
        {
            // Based on above recipient columns, an ARRAY of ModifyRecipientRow is created.
            // The following sample data is from MS-OXCMSG 4.7.1
            #region Configure a StandardPropertyRow: propertyRow, data is from Page 62 of MS-OXCMSG

            PropertyValue[] propertyValueArray = new PropertyValue[12];

            for (int i = 0; i < propertyValueArray.Length; i++)
            {
                propertyValueArray[i] = new PropertyValue();
            }

            propertyValueArray[0].Value = BitConverter.GetBytes(0x00000006); // PidTagObjectType
            propertyValueArray[1].Value = BitConverter.GetBytes(0x00000000); // PidTagDisplayType
            propertyValueArray[2].Value = Common.GetBytesFromUnicodeString(name); // PidTa7BitDisplayName
            string domainName = Common.GetConfigurationPropertyValue("Domain", this.Site);
            propertyValueArray[3].Value = Common.GetBytesFromUnicodeString(string.Format("{0}{1}{2}", name, TestSuiteBase.At, domainName)); // PidTagSmtpAddress
            propertyValueArray[4].Value = BitConverter.GetBytes(0x00000000); // PidTagSendInternetEncoding
            propertyValueArray[5].Value = BitConverter.GetBytes(0x40000000); // PidTagDisplayTypeEx
            propertyValueArray[6].Value = Common.GetBytesFromUnicodeString(PrefixOfDisplayName + name); // PidTagRecipientDisplayName
            propertyValueArray[7].Value = BitConverter.GetBytes(0x00000001); // PidTagRecipientFlags
            propertyValueArray[8].Value = BitConverter.GetBytes(0x00000000); // PidTagRecipientTrackStatus
            propertyValueArray[9].Value = BitConverter.GetBytes(0x00000000); // PidTagRecipientResourceState
            propertyValueArray[10].Value = BitConverter.GetBytes(0x00000000); // PidTagRecipientOrder

            // The following sample data (0x007c and the subsequent 124(0x7c) binary)
            byte[] sampleData = 
            {
                0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0xa7, 0x40,
                0xc8, 0xc0, 0x42, 0x10, 0x1a, 0xb4, 0xb9, 0x08, 0x00, 0x2b, 0x2f, 0xe1, 0x82, 0x01, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x2f, 0x6f, 0x3d, 0x46, 0x69, 0x72, 0x73, 0x74, 0x20, 0x4f, 0x72,
                0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6f, 0x75, 0x3d, 0x45, 0x78,
                0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x20, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x69, 0x73, 0x74, 0x72,
                0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x28, 0x46, 0x59, 0x44,
                0x49, 0x42, 0x4f, 0x48, 0x46, 0x32, 0x33, 0x53, 0x50, 0x44, 0x4c, 0x54, 0x29, 0x2f, 0x63, 0x6e,
                0x3d, 0x52, 0x65, 0x63, 0x69, 0x70, 0x69, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x63, 0x6e, 0x3d, 0x75,
                0x73, 0x65, 0x72, 0x32, 0x00
            };
            propertyValueArray[11].Value = sampleData; // PidTagRecipientEntryId

            List<PropertyValue> propertyValues = new List<PropertyValue>();
            for (int i = 0; i < propertyValueArray.Length; i++)
            {
                propertyValues.Add(propertyValueArray[i]);
            }

            PropertyRow propertyRow = new PropertyRow
            {
                Flag = 0x01, PropertyValues = propertyValues
            };

            #endregion
            return propertyRow;
        }