コード例 #1
0
        /// <summary>
        /// Renames the entry within the same container. The <paramref name="newName"/> can be in the format
        /// XX=New Name or just New Name.
        /// </summary>
        /// <param name="connection">The connection to the directory.</param>
        /// <param name="log">The log for query information. Defaults to null.</param>
        /// <param name="currentDistinguishedName">The entry's current distinguished name</param>
        /// <param name="newName">The new name of the entry</param>
        /// <param name="deleteOldRDN">Maps to <see cref="P:System.DirectoryServices.Protocols.ModifyDNRequest.DeleteOldRdn"/>. Defaults to null to use default behavior</param>
        /// <param name="controls">Any <see cref="DirectoryControl"/>s to be sent with the request</param>
        /// <param name="resultProcessing">How the async results are processed</param>
        /// <exception cref="ArgumentException">
        /// Thrown if <paramref name="currentDistinguishedName"/> has an invalid format.
        /// </exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="currentDistinguishedName"/>
        /// or <paramref name="newName"/> are null, empty or white space.
        /// </exception>
        /// <exception cref="DirectoryOperationException">Thrown if the operation fails.</exception>
        /// <exception cref="LdapConnection">Thrown if the operation fails.</exception>
        public static async Task <string> RenameEntryAsync(this LdapConnection connection, string currentDistinguishedName, string newName, ILinqToLdapLogger log = null,
                                                           bool?deleteOldRDN = null, DirectoryControl[] controls = null, PartialResultProcessing resultProcessing = LdapConfiguration.DefaultAsyncResultProcessing)
        {
            try
            {
                if (connection == null)
                {
                    throw new ArgumentNullException("connection");
                }

                if (currentDistinguishedName.IsNullOrEmpty())
                {
                    throw new ArgumentNullException("currentDistinguishedName");
                }

                if (newName.IsNullOrEmpty())
                {
                    throw new ArgumentNullException("newName");
                }

                newName = DnParser.FormatName(newName, currentDistinguishedName);
                var container = DnParser.GetEntryContainer(currentDistinguishedName);

                var response = await SendModifyDnRequestAsync(connection, currentDistinguishedName, container, newName, deleteOldRDN, controls, log, resultProcessing).ConfigureAwait(false);

                response.AssertSuccess();

                return(string.Format("{0},{1}", newName, container));
            }
            catch (Exception ex)
            {
                if (log != null)
                {
                    log.Error(ex, string.Format("An error occurred while trying to rename entry '{0}' to '{1}'.", currentDistinguishedName, newName));
                }

                throw;
            }
        }
コード例 #2
0
        /// <summary>
        /// Renames the entry within the same container. The <paramref name="newName"/> can be in the format
        /// XX=New Name or just New Name.
        /// </summary>
        /// <param name="connection">The connection to the directory.</param>
        /// <param name="log">The log for query information. Defaults to null.</param>
        /// <param name="currentDistinguishedName">The entry's current distinguished name</param>
        /// <param name="newName">The new name of the entry</param>
        /// <param name="deleteOldRDN">Maps to <see cref="P:System.DirectoryServices.Protocols.ModifyDNRequest.DeleteOldRdn"/>. Defaults to null to use default behavior</param>
        /// <param name="controls">Any <see cref="DirectoryControl"/>s to be sent with the request</param>
        /// <exception cref="ArgumentException">
        /// Thrown if <paramref name="currentDistinguishedName"/> has an invalid format.
        /// </exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="currentDistinguishedName"/>
        /// or <paramref name="newName"/> are null, empty or white space.
        /// </exception>
        /// <exception cref="DirectoryOperationException">Thrown if the operation fails.</exception>
        /// <exception cref="LdapConnection">Thrown if the operation fails.</exception>
        public static string RenameEntry(this LdapConnection connection, string currentDistinguishedName, string newName, ILinqToLdapLogger log = null, bool?deleteOldRDN = null, params DirectoryControl[] controls)
        {
            try
            {
                if (connection == null)
                {
                    throw new ArgumentNullException("connection");
                }

                if (currentDistinguishedName.IsNullOrEmpty())
                {
                    throw new ArgumentNullException("currentDistinguishedName");
                }

                if (newName.IsNullOrEmpty())
                {
                    throw new ArgumentNullException("newName");
                }

                newName = DnParser.FormatName(newName, currentDistinguishedName);
                var container = DnParser.GetEntryContainer(currentDistinguishedName);

                var response = SendModifyDnRequest(connection, currentDistinguishedName, container, newName, deleteOldRDN, controls, log);
                response.AssertSuccess();

                return(string.Format("{0},{1}", newName, container));
            }
            catch (Exception ex)
            {
                if (log != null)
                {
                    log.Error(ex, string.Format("An error occurred while trying to rename entry '{0}' to '{1}'.", currentDistinguishedName, newName));
                }

                throw;
            }
        }
コード例 #3
0
ファイル: DnParserTest.cs プロジェクト: zeWizard/LinqToLdap
 public void GetEntryContainer_OU_ReturnsContainer()
 {
     DnParser.GetEntryContainer("OU=test,Cn=test2,Dc=domain,Dc=com").Should().Be.EqualTo("Cn=test2,Dc=domain,Dc=com");
 }
コード例 #4
0
ファイル: DnParserTest.cs プロジェクト: zeWizard/LinqToLdap
 public void GetEntryContainer_OneRDN_ReturnsOU()
 {
     DnParser.GetEntryContainer("OU=DoeJohn").Should().Be.EqualTo("OU=DoeJohn");
 }
コード例 #5
0
ファイル: DnParserTest.cs プロジェクト: zeWizard/LinqToLdap
 public void GetEntryContainer_RDNWithComma_ReturnsOU()
 {
     DnParser.GetEntryContainer("OU=Doe, John,Cn=test2,Dc=domain,Dc=com").Should().Be.EqualTo("Cn=test2,Dc=domain,Dc=com");
 }