public async Task WriteAsync(LDAPAttribute attr) { var attWriter = new LDAPWriter(); await attWriter.WriteAsync(attr.Description); var valuesWriter = new LDAPWriter(); foreach (var value in attr.Values) { await valuesWriter.WriteAsync(value); } await attWriter.WriteAsync(valuesWriter, (int)EncodingType.SET); await WriteAsync(attWriter); }
/// <summary> /// Copies the writer to this as a complex object /// </summary> /// <param name="writer">The writer to copy</param> /// <param name="tag">The tag to use for the object</param> /// <param name="scope">The scope to use for the object</param> public async Task WriteAsync(LDAPWriter writer, int tag, EncodingScope scope) { await EncodeHeaderAsync(tag, scope, false); // Get the underlying stream var s = writer._target; // Reset the stream if possible for copying if (s.Position != 0 && s.CanSeek) { s.Seek(0, SeekOrigin.Begin); } else if (s.Length - s.Position <= 0) { throw new LDAPProtocolException("Stream has data that cannot be recovered"); } // Write the number of bytes available in the stream await EncodeLengthAsync((int)(s.Length - s.Position)); // Copy the streams await s.CopyToAsync(_target); }
public async Task WriteAsync(LDAPFilter filter) { switch (filter.FilterType) { case LDAPFilterType.Add: case LDAPFilterType.Or: case LDAPFilterType.Not: var bWriter = new LDAPWriter(); foreach (var f in filter.Children) { await bWriter.WriteAsync(f); } await WriteAsync(bWriter, (int)filter.FilterType, EncodingScope.CONTEXT_SPECIFIC); break; case LDAPFilterType.Substring: var subWriter = new LDAPWriter(); await subWriter.WriteAsync(filter.Description); var subSequenceWriter = new LDAPWriter(); foreach (var sub in filter.Substrings) { await subSequenceWriter.WriteAsync(sub.Value, (int)sub.SubstringType, EncodingScope.CONTEXT_SPECIFIC); } await subWriter.WriteAsync(subSequenceWriter); await WriteAsync(subWriter, (int)filter.FilterType, EncodingScope.CONTEXT_SPECIFIC); break; case LDAPFilterType.EqualityMatch: case LDAPFilterType.GreaterOrEqual: case LDAPFilterType.LessOrEqual: case LDAPFilterType.ApproximateMatch: var valWriter = new LDAPWriter(); await valWriter.WriteAsync(filter.Description); await valWriter.WriteAsync(filter.Value); await WriteAsync(valWriter, (int)filter.FilterType, EncodingScope.CONTEXT_SPECIFIC); break; case LDAPFilterType.Present: var desc = string.IsNullOrEmpty(filter.Value) ? filter.Description : "{0}={1}".ToFormat(filter.Description, filter.Value); await WriteAsync(desc, (int)filter.FilterType, EncodingScope.CONTEXT_SPECIFIC); break; case LDAPFilterType.ExtensibleMatch: var eWriter = new LDAPWriter(); if (!string.IsNullOrEmpty(filter.MatchingRule)) { await eWriter.WriteAsync(filter.MatchingRule, 1, EncodingScope.CONTEXT_SPECIFIC); } if (!string.IsNullOrEmpty(filter.Description)) { await eWriter.WriteAsync(filter.Description, 2, EncodingScope.CONTEXT_SPECIFIC); } await eWriter.WriteAsync(filter.Value, 3, EncodingScope.CONTEXT_SPECIFIC); await eWriter.WriteAsync(filter.AllAttributes, 4, EncodingScope.CONTEXT_SPECIFIC); await WriteAsync(eWriter, (int)filter.FilterType, EncodingScope.CONTEXT_SPECIFIC); break; default: throw new LDAPProtocolException("Unsupported filter type: {0}".ToFormat(filter.FilterType)); } }
/// <summary> /// Copies the writer to this as a complex object /// </summary> /// <param name="writer">The writer to copy</param> /// <param name="tag">The tag to use for the object</param> public async Task WriteAsync(LDAPWriter writer, int tag) => await WriteAsync(writer, tag, EncodingScope.UNIVERSAL);
/// <summary> /// Copies the writer to this as a complex object /// </summary> /// <param name="writer">The writer to copy</param> public async Task WriteAsync(LDAPWriter writer) => await WriteAsync(writer, (int)EncodingType.SEQUENCE);