public void Notify(ListenerPostArgs <object, ModifyRequest, ModifyResponse> postArgs) { postArgs.Entry.Should().Not.Be.Null(); postArgs.Request.Should().Not.Be.Null(); postArgs.Response.Should().Not.Be.Null(); postArgs.Response.ResultCode.Should().Be.EqualTo(ResultCode.Success); postArgs.Connection.Should().Not.Be.Null(); _postUpdateNotified = true; }
public void Notify(ListenerPostArgs <string, DeleteRequest, DeleteResponse> postArgs) { postArgs.Entry.Should().Not.Be.Null(); postArgs.Request.Should().Not.Be.Null(); postArgs.Response.Should().Not.Be.Null(); postArgs.Response.ResultCode.Should().Be.EqualTo(ResultCode.Success); postArgs.Connection.Should().Not.Be.Null(); _postDeleteNotified = true; }
/// <summary> /// Deletes an entry from the directory. /// </summary> /// <param name="connection">The connection to the directory.</param> /// <param name="distinguishedName">The distinguished name of the entry /// </param><param name="controls">Any <see cref="DirectoryControl"/>s to be sent with the request</param> /// <param name="log">The log for query information. Defaults to null.</param> /// <param name="listeners">The event listeners to be notified.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="distinguishedName"/> is null, empty or white space.</exception> /// <exception cref="DirectoryOperationException">Thrown if the operation fails.</exception> /// <exception cref="LdapException">Thrown if the operation fails.</exception> public static void Delete(this LdapConnection connection, string distinguishedName, ILinqToLdapLogger log = null, DirectoryControl[] controls = null, IEnumerable <IDeleteEventListener> listeners = null) { try { if (connection == null) { throw new ArgumentNullException("connection"); } if (distinguishedName.IsNullOrEmpty()) { throw new ArgumentNullException("distinguishedName"); } var request = new DeleteRequest(distinguishedName); if (controls != null) { request.Controls.AddRange(controls); } if (listeners != null) { var args = new ListenerPreArgs <string, DeleteRequest>(distinguishedName, request, connection); foreach (var eventListener in listeners.OfType <IPreDeleteEventListener>()) { eventListener.Notify(args); } } if (log != null && log.TraceEnabled) { log.Trace(request.ToLogString()); } var response = connection.SendRequest(request) as DeleteResponse; response.AssertSuccess(); if (listeners != null) { var args = new ListenerPostArgs <string, DeleteRequest, DeleteResponse>(distinguishedName, request, response, connection); foreach (var eventListener in listeners.OfType <IPostDeleteEventListener>()) { eventListener.Notify(args); } } } catch (Exception ex) { string message = string.Format("An error occurred while trying to delete '{0}'.", distinguishedName); if (log != null) { log.Error(ex, message); } throw; } }
/// <summary> /// Adds the entry to the directory. /// </summary> /// <param name="connection">The connection to the directory.</param> /// <param name="entry">The entry to add.</param> /// <param name="log">The log for query information. Defaults to null.</param> /// <param name="controls">Any <see cref="DirectoryControl"/>s to be sent with the request</param> /// <param name="listeners">The event listeners to be notified.</param> /// <param name="resultProcessing">How the async results are processed</param> /// <returns></returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="connection"/> or <paramref name="entry"/>> is null. /// </exception> /// <exception cref="DirectoryOperationException">Thrown if the add was not successful.</exception> /// <exception cref="LdapException">Thrown if the operation fails.</exception> public static async Task AddAsync(this LdapConnection connection, IDirectoryAttributes entry, ILinqToLdapLogger log = null, DirectoryControl[] controls = null, IEnumerable <IAddEventListener> listeners = null, PartialResultProcessing resultProcessing = LdapConfiguration.DefaultAsyncResultProcessing) { string distinguishedName = null; try { if (connection == null) { throw new ArgumentNullException("connection"); } if (entry == null) { throw new ArgumentNullException("entry"); } distinguishedName = entry.DistinguishedName; if (distinguishedName.IsNullOrEmpty()) { throw new ArgumentException("entry.DistinguishedName is invalid."); } var request = new AddRequest(distinguishedName, entry.GetChangedAttributes().Where(da => da.Count > 0).ToArray()); if (controls != null) { request.Controls.AddRange(controls); } if (listeners != null) { var args = new ListenerPreArgs <object, AddRequest>(entry, request, connection); foreach (var eventListener in listeners.OfType <IPreAddEventListener>()) { eventListener.Notify(args); } } if (log != null && log.TraceEnabled) { log.Trace(request.ToLogString()); } AddResponse response = null; #if NET45 await Task.Factory.FromAsync( (callback, state) => { return(connection.BeginSendRequest(request, resultProcessing, callback, state)); }, (asyncresult) => { response = (AddResponse)connection.EndSendRequest(asyncresult); response.AssertSuccess(); }, null ).ConfigureAwait(false); #else response = await Task.Run(() => connection.SendRequest(request) as AddResponse).ConfigureAwait(false); response.AssertSuccess(); #endif if (listeners != null) { var args = new ListenerPostArgs <object, AddRequest, AddResponse>(entry, request, response, connection); foreach (var eventListener in listeners.OfType <IPostAddEventListener>()) { eventListener.Notify(args); } } } catch (Exception ex) { if (log != null) { log.Error(ex, string.Format("An error occurred while trying to add '{0}'.", distinguishedName)); } throw; } }
/// <summary> /// Deletes an entry from the directory. /// </summary> /// <param name="connection">The connection to the directory.</param> /// <param name="distinguishedName">The distinguished name of the entry /// </param><param name="controls">Any <see cref="DirectoryControl"/>s to be sent with the request</param> /// <param name="log">The log for query information. Defaults to null.</param> /// <param name="listeners">The event listeners to be notified.</param> /// <param name="resultProcessing">How the async results are processed</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="distinguishedName"/> is null, empty or white space.</exception> /// <exception cref="DirectoryOperationException">Thrown if the operation fails.</exception> /// <exception cref="LdapException">Thrown if the operation fails.</exception> public static async Task DeleteAsync(this LdapConnection connection, string distinguishedName, ILinqToLdapLogger log = null, DirectoryControl[] controls = null, IEnumerable <IDeleteEventListener> listeners = null, PartialResultProcessing resultProcessing = LdapConfiguration.DefaultAsyncResultProcessing) { try { if (connection == null) { throw new ArgumentNullException("connection"); } if (distinguishedName.IsNullOrEmpty()) { throw new ArgumentNullException("distinguishedName"); } var request = new DeleteRequest(distinguishedName); if (controls != null) { request.Controls.AddRange(controls); } if (listeners != null) { var args = new ListenerPreArgs <string, DeleteRequest>(distinguishedName, request, connection); foreach (var eventListener in listeners.OfType <IPreDeleteEventListener>()) { eventListener.Notify(args); } } if (log != null && log.TraceEnabled) { log.Trace(request.ToLogString()); } DeleteResponse response = null; #if NET45 await Task.Factory.FromAsync( (callback, state) => { return(connection.BeginSendRequest(request, resultProcessing, callback, state)); }, (asyncresult) => { response = (DeleteResponse)connection.EndSendRequest(asyncresult); response.AssertSuccess(); }, null ).ConfigureAwait(false); #else response = await Task.Run(() => connection.SendRequest(request) as DeleteResponse).ConfigureAwait(false); response.AssertSuccess(); #endif if (listeners != null) { var args = new ListenerPostArgs <string, DeleteRequest, DeleteResponse>(distinguishedName, request, response, connection); foreach (var eventListener in listeners.OfType <IPostDeleteEventListener>()) { eventListener.Notify(args); } } } catch (Exception ex) { string message = string.Format("An error occurred while trying to delete '{0}'.", distinguishedName); if (log != null) { log.Error(ex, message); } throw; } }
/// <summary> /// Adds the entry to the directory. /// </summary> /// <param name="connection">The connection to the directory.</param> /// <param name="entry">The entry to add.</param> /// <param name="log">The log for query information. Defaults to null.</param> /// <param name="controls">Any <see cref="DirectoryControl"/>s to be sent with the request</param> /// <param name="listeners">The event listeners to be notified.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="connection"/> or <paramref name="entry"/>> is null. /// </exception> /// <exception cref="DirectoryOperationException">Thrown if the add was not successful.</exception> /// <exception cref="LdapException">Thrown if the operation fails.</exception> public static void Add(this LdapConnection connection, IDirectoryAttributes entry, ILinqToLdapLogger log = null, DirectoryControl[] controls = null, IEnumerable <IAddEventListener> listeners = null) { string distinguishedName = null; try { if (connection == null) { throw new ArgumentNullException("connection"); } if (entry == null) { throw new ArgumentNullException("entry"); } distinguishedName = entry.DistinguishedName; if (distinguishedName.IsNullOrEmpty()) { throw new ArgumentException("entry.DistinguishedName is invalid."); } var request = new AddRequest(distinguishedName, entry.GetChangedAttributes().Where(da => da.Count > 0).ToArray()); if (controls != null) { request.Controls.AddRange(controls); } if (listeners != null) { var args = new ListenerPreArgs <object, AddRequest>(entry, request, connection); foreach (var eventListener in listeners.OfType <IPreAddEventListener>()) { eventListener.Notify(args); } } if (log != null && log.TraceEnabled) { log.Trace(request.ToLogString()); } var response = connection.SendRequest(request) as AddResponse; response.AssertSuccess(); if (listeners != null) { var args = new ListenerPostArgs <object, AddRequest, AddResponse>(entry, request, response, connection); foreach (var eventListener in listeners.OfType <IPostAddEventListener>()) { eventListener.Notify(args); } } } catch (Exception ex) { if (log != null) { log.Error(ex, string.Format("An error occurred while trying to add '{0}'.", distinguishedName)); } throw; } }