/// <summary>
        /// Creates a ModifyRequest packet.
        /// </summary>
        /// <param name="context">The user context which contains message ID.</param>
        /// <param name="objectDn">The DN of object to be modified.</param>
        /// <param name="modificationList">Modification list of attributes.</param>
        /// <returns>The packet that contains the request.</returns>
        internal override AdtsModifyRequestPacket CreateModifyRequest(
            AdtsLdapContext context,
            string objectDn,
            params MsLdap.DirectoryAttributeModification[] modificationList)
        {
            int length = (modificationList != null) ? modificationList.Length : 0;

            ModifyRequest_modifications_element[] modifyRequestArray = new ModifyRequest_modifications_element[length];
            for (int i = 0; i < length; i++)
            {
                modifyRequestArray[i] = new ModifyRequest_modifications_element(
                    new ModifyRequest_modifications_element_operation((long)modificationList[i].Operation),
                    new ModifyRequest_modifications_element_modification(
                        new AttributeType(modificationList[i].Name),
                        CreateAttributeValueSet((string[])modificationList[i].GetValues(typeof(string)))));
            }
            Asn1SequenceOf <ModifyRequest_modifications_element> modificationSequence = new Asn1SequenceOf <ModifyRequest_modifications_element>(modifyRequestArray);

            ModifyRequest modifyRequest = new ModifyRequest(
                new LDAPDN(objectDn ?? string.Empty),
                modificationSequence);

            LDAPMessage_protocolOp operation = new LDAPMessage_protocolOp();

            operation.SetData(LDAPMessage_protocolOp.modifyRequest, modifyRequest);

            LDAPMessage             message = new LDAPMessage(new MessageID(context.MessageId), operation);
            AdtsModifyRequestPacket packet  = new AdtsModifyRequestPacket();

            packet.ldapMessagev2 = message;
            packet.messageId     = context.MessageId;

            return(packet);
        }
        /// <summary>
        /// Creates a ModifyRequest packet.
        /// </summary>
        /// <param name="context">The user context which contains message ID.</param>
        /// <param name="objectDn">The DN of object to be modified.</param>
        /// <param name="modificationList">Modification list of attributes.</param>
        /// <returns>The packet that contains the request.</returns>
        internal override AdtsModifyRequestPacket CreateModifyRequest(
            AdtsLdapContext context,
            string objectDn,
            params MsLdap.DirectoryAttributeModification[] modificationList)
        {
            int length = (modificationList != null) ? modificationList.Length : 0;

            ModifyRequest_modification_element[] modificationElements = new ModifyRequest_modification_element[length];
            for (int i = 0; i < length; i++)
            {
                byte[][] values = (byte[][])modificationList[i].GetValues(typeof(byte[]));

                modificationElements[i] = new ModifyRequest_modification_element(
                    new ModifyRequest_modification_element_operation((long)modificationList[i].Operation),
                    new AttributeTypeAndValues(
                        new AttributeDescription(modificationList[i].Name),
                        CreateAttributeValueSet(values)));
            }

            Asn1SequenceOf<ModifyRequest_modification_element> modificationSequence =
                new Asn1SequenceOf<ModifyRequest_modification_element>(modificationElements);

            ModifyRequest modifyRequest = new ModifyRequest(
                new LDAPDN(objectDn ?? string.Empty),
                modificationSequence);

            LDAPMessage_protocolOp operation = new LDAPMessage_protocolOp();
            operation.SetData(LDAPMessage_protocolOp.modifyRequest, modifyRequest);

            LDAPMessage message = new LDAPMessage(new MessageID(context.MessageId), operation, null);
            AdtsModifyRequestPacket packet = new AdtsModifyRequestPacket();
            packet.ldapMessagev3 = message;
            packet.messageId = context.MessageId;

            return packet;
        }
        internal AdtsLdapPacket CreatePacketFromType(Type messageType)
        {
            AdtsLdapPacket packet = null;

            if (messageType == typeof(AbandonRequest))
            {
                packet = new AdtsAbandonRequestPacket();
            }
            else if (messageType == typeof(AddRequest))
            {
                packet = new AdtsAddRequestPacket();
            }
            else if (messageType == typeof(AddResponse))
            {
                packet = new AdtsAddResponsePacket();
            }
            else if (messageType == typeof(BindRequest))
            {
                packet = new AdtsBindRequestPacket();
            }
            else if (messageType == typeof(BindResponse))
            {
                packet = new AdtsBindResponsePacket();
            }
            else if (messageType == typeof(CompareRequest))
            {
                packet = new AdtsCompareRequestPacket();
            }
            else if (messageType == typeof(CompareResponse))
            {
                packet = new AdtsCompareResponsePacket();
            }
            else if (messageType == typeof(DelRequest))
            {
                packet = new AdtsDelRequestPacket();
            }
            else if (messageType == typeof(DelResponse))
            {
                packet = new AdtsDelResponsePacket();
            }
            else if (messageType == typeof(ExtendedRequest))
            {
                packet = new AdtsExtendedRequestPacket();
            }
            else if (messageType == typeof(ExtendedResponse))
            {
                packet = new AdtsExtendedResponsePacket();
            }
            else if (messageType == typeof(ModifyDNRequest))
            {
                packet = new AdtsModifyDnRequestPacket();
            }
            else if (messageType == typeof(ModifyDNResponse))
            {
                packet = new AdtsModifyDnResponsePacket();
            }
            else if (messageType == typeof(ModifyRequest))
            {
                packet = new AdtsModifyRequestPacket();
            }
            else if (messageType == typeof(ModifyResponse))
            {
                packet = new AdtsModifyResponsePacket();
            }
            else if (messageType == typeof(SearchRequest))
            {
                packet = new AdtsSearchRequestPacket();
            }
            else if (messageType == typeof(SearchResultEntry))
            {
                packet = new AdtsSearchResultEntryPacket();
            }
            else if (messageType == typeof(SearchResultReference))
            {
                packet = new AdtsSearchResultReferencePacket();
            }
            else if (messageType == typeof(SearchResultDone))
            {
                packet = new AdtsSearchResultDonePacket();
            }
            else if (messageType == typeof(SicilyBindResponse))
            {
                packet = new AdtsSicilyBindResponsePacket();
            }
            else if (messageType == typeof(UnbindRequest))
            {
                packet = new AdtsUnbindRequestPacket();
            }
            else
            {
                throw new StackException("Unknown message type: " + messageType.ToString());
            }

            return packet;
        }
        internal AdtsLdapPacket CreatePacketFromType(Type messageType)
        {
            AdtsLdapPacket packet = null;

            if (messageType == typeof(AbandonRequest))
            {
                packet = new AdtsAbandonRequestPacket();
            }
            else if (messageType == typeof(AddRequest))
            {
                packet = new AdtsAddRequestPacket();
            }
            else if (messageType == typeof(AddResponse))
            {
                packet = new AdtsAddResponsePacket();
            }
            else if (messageType == typeof(BindRequest))
            {
                packet = new AdtsBindRequestPacket();
            }
            else if (messageType == typeof(BindResponse))
            {
                packet = new AdtsBindResponsePacket();
            }
            else if (messageType == typeof(CompareRequest))
            {
                packet = new AdtsCompareRequestPacket();
            }
            else if (messageType == typeof(CompareResponse))
            {
                packet = new AdtsCompareResponsePacket();
            }
            else if (messageType == typeof(DelRequest))
            {
                packet = new AdtsDelRequestPacket();
            }
            else if (messageType == typeof(DelResponse))
            {
                packet = new AdtsDelResponsePacket();
            }
            else if (messageType == typeof(ExtendedRequest))
            {
                packet = new AdtsExtendedRequestPacket();
            }
            else if (messageType == typeof(ExtendedResponse))
            {
                packet = new AdtsExtendedResponsePacket();
            }
            else if (messageType == typeof(ModifyDNRequest))
            {
                packet = new AdtsModifyDnRequestPacket();
            }
            else if (messageType == typeof(ModifyDNResponse))
            {
                packet = new AdtsModifyDnResponsePacket();
            }
            else if (messageType == typeof(ModifyRequest))
            {
                packet = new AdtsModifyRequestPacket();
            }
            else if (messageType == typeof(ModifyResponse))
            {
                packet = new AdtsModifyResponsePacket();
            }
            else if (messageType == typeof(SearchRequest))
            {
                packet = new AdtsSearchRequestPacket();
            }
            else if (messageType == typeof(SearchResultEntry))
            {
                packet = new AdtsSearchResultEntryPacket();
            }
            else if (messageType == typeof(SearchResultReference))
            {
                packet = new AdtsSearchResultReferencePacket();
            }
            else if (messageType == typeof(SearchResultDone))
            {
                packet = new AdtsSearchResultDonePacket();
            }
            else if (messageType == typeof(SicilyBindResponse))
            {
                packet = new AdtsSicilyBindResponsePacket();
            }
            else if (messageType == typeof(UnbindRequest))
            {
                packet = new AdtsUnbindRequestPacket();
            }
            else
            {
                throw new StackException("Unknown message type: " + messageType.ToString());
            }

            return(packet);
        }