public BatchCommand(DocumentConventions conventions, JsonOperationContext context, List <ICommandData> commands, BatchOptions options = null, TransactionMode mode = TransactionMode.SingleNode) { if (conventions == null) { throw new ArgumentNullException(nameof(conventions)); } if (commands == null) { throw new ArgumentNullException(nameof(commands)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } _commands = new BlittableJsonReaderObject[commands.Count]; for (var i = 0; i < commands.Count; i++) { var command = commands[i]; var json = command.ToJson(conventions, context); _commands[i] = context.ReadObject(json, "command"); if (command is PutAttachmentCommandData putAttachmentCommandData) { if (_attachmentStreams == null) { _attachmentStreams = new List <Stream>(); _uniqueAttachmentStreams = new HashSet <Stream>(); } var stream = putAttachmentCommandData.Stream; PutAttachmentCommandHelper.ValidateStream(stream); if (_uniqueAttachmentStreams.Add(stream) == false) { PutAttachmentCommandHelper.ThrowStreamAlready(); } _attachmentStreams.Add(stream); } } _options = options; _mode = mode; Timeout = options?.RequestTimeout; }