Exemple #1
0
        public SingleNodeBatchCommand(DocumentConventions conventions, JsonOperationContext context, IList <ICommandData> commands, BatchOptions options = null, TransactionMode mode = TransactionMode.SingleNode)
        {
            _conventions = conventions ?? throw new ArgumentNullException(nameof(conventions));
            _commands    = commands ?? throw new ArgumentNullException(nameof(commands));
            _options     = options;
            _mode        = mode;

            _commandsAsJson = new BlittableJsonReaderObject[_commands.Count];
            foreach (var command in commands)
            {
                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.ThrowStreamWasAlreadyUsed();
                    }
                    _attachmentStreams.Add(stream);
                }
            }

            Timeout = options?.RequestTimeout;
        }
Exemple #2
0
        public SingleNodeBatchCommand(DocumentConventions conventions, JsonOperationContext context, IList <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.ThrowStreamWasAlreadyUsed();
                    }
                    _attachmentStreams.Add(stream);
                }
            }

            _options = options;
            _mode    = mode;

            Timeout = options?.RequestTimeout;
        }