コード例 #1
0
        /// <summary>
        /// Moves the entry from one container to another without modifying the entry's 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="newNamingContext">The new container for 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="newNamingContext"/> 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 System.Threading.Tasks.Task <string> MoveEntryAsync(this LdapConnection connection, string currentDistinguishedName, string newNamingContext, 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 (newNamingContext.IsNullOrEmpty())
                {
                    throw new ArgumentNullException("newNamingContext");
                }

                var name = DnParser.GetEntryName(currentDistinguishedName);

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

                response.AssertSuccess();

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

                throw;
            }
        }
コード例 #2
0
        /// <summary>
        /// Moves the entry from one container to another without modifying the entry's 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="newNamingContext">The new container for 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="newNamingContext"/> 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 MoveEntry(this LdapConnection connection, string currentDistinguishedName, string newNamingContext, 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 (newNamingContext.IsNullOrEmpty())
                {
                    throw new ArgumentNullException("newNamingContext");
                }

                var name = DnParser.GetEntryName(currentDistinguishedName);

                var response = SendModifyDnRequest(connection, currentDistinguishedName, newNamingContext, name, deleteOldRDN, controls, log);
                response.AssertSuccess();

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

                throw;
            }
        }
コード例 #3
0
ファイル: DnParserTest.cs プロジェクト: zeWizard/LinqToLdap
 public void GetEntryName_OneRDN_ReturnsOU()
 {
     DnParser.GetEntryName("OU=DoeJohn").Should().Be.EqualTo("OU=DoeJohn");
 }
コード例 #4
0
ファイル: DnParserTest.cs プロジェクト: zeWizard/LinqToLdap
 public void GetEntryName_RDNWithComma_ReturnsOU()
 {
     DnParser.GetEntryName("OU=Doe, John,Cn=test2,Dc=domain,Dc=com").Should().Be.EqualTo("OU=Doe, John");
 }
コード例 #5
0
ファイル: DnParserTest.cs プロジェクト: zeWizard/LinqToLdap
 public void GetEntryName_OU_ReturnsOU()
 {
     DnParser.GetEntryName("OU=test,Cn=test2,Dc=domain,Dc=com").Should().Be.EqualTo("OU=test");
 }
コード例 #6
0
ファイル: DnParserTest.cs プロジェクト: zeWizard/LinqToLdap
 public void GetEntryName_CN_ReturnsCN()
 {
     DnParser.GetEntryName("Cn=test,Dd=domain,Dd=com").Should().Be.EqualTo("Cn=test");
 }
コード例 #7
0
ファイル: DnParserTest.cs プロジェクト: zeWizard/LinqToLdap
 public void GetEntryName_SingleCharacter_ReturnsCN()
 {
     DnParser.GetEntryName("n=test,Dd=domain,Dd=com").Should().Be.EqualTo("n=test");
 }