internal async Task RequestLdapMessage(LdapMessage msg, CancellationToken ct = default) { using (var stream = new MemoryStream()) { LberEncoder.Encode(msg.Asn1Object, stream); await _conn.WriteDataAsync(stream.ToArray(), true, ct); try { while (new List <RfcLdapMessage>(Messages).Any(x => x.MessageId == msg.MessageId) == false) { await Task.Delay(100, ct); } } catch (ArgumentException) { // expected } var first = new List <RfcLdapMessage>(Messages).FirstOrDefault(x => x.MessageId == msg.MessageId); if (first != null) { var response = new LdapResponse(first); response.ChkResultCode(); } } }
/// <summary> /// Requests the LDAP message. /// </summary> /// <param name="msg">The MSG.</param> /// <param name="ct">The ct.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> internal async Task RequestLdapMessage(LdapMessage msg, CancellationToken ct = default(CancellationToken)) { var encoder = new LBEREncoder(); var ber = msg.Asn1Object.GetEncoding(encoder); await _conn.WriteDataAsync(ber.ToByteArray(), true, ct); while (new List <RfcLdapMessage>(Messages).Any(x => x.MessageId == msg.MessageId) == false) { await Task.Delay(100, ct); } var first = new List <RfcLdapMessage>(Messages).FirstOrDefault(x => x.MessageId == msg.MessageId); if (first != null) { var response = new LdapResponse(first); response.ChkResultCode(); } }