private static ByteArrayContent CreateWriteBody(IEnumerable <CounterWriteOperation> operations) { var writeBody = new CounterWriteRequest { Writes = operations.ToList() }; using (var ms = new MemoryStream()) { var writer = new SimpleJsonWriter(ms); writer.Write(writeBody); var bytes = new byte[ms.Length]; Buffer.BlockCopy(ms.GetBuffer(), 0, bytes, 0, bytes.Length); var content = new ByteArrayContent(bytes); content.Headers.ContentType = new MediaTypeHeaderValue(Protocol.ApplicationJsonMimeType); return(content); } }
private void Write <TData>(TData data) { var acceptTypes = this.HttpRequest.AcceptTypes; if (acceptTypes != null && acceptTypes.Contains(Protocol.BondCompactBinaryMimeType, StringComparer.Ordinal)) { this.ContentType = Protocol.BondCompactBinaryMimeType; using (var writerStream = new WriterStream(this.responseBody)) { var writer = writerStream.CreateCompactBinaryWriter(); writer.Write(data); } } else { this.ContentType = Protocol.ApplicationJsonMimeType; var writer = new SimpleJsonWriter(this.responseBody); writer.Write(data); } }