示例#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;
        }
示例#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;
        }
示例#3
0
        public BatchCommand(DocumentConventions conventions, JsonOperationContext context, List <ICommandData> commands, BatchOptions options = null)
        {
            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];
                _commands[i] = context.ReadObject(command.ToJson(conventions, context), "command");

                if (command is PutAttachmentCommandData putAttachmentCommandData)
                {
                    if (_attachmentStreams == null)
                    {
                        _attachmentStreams = new HashSet <Stream>();
                    }

                    var stream = putAttachmentCommandData.Stream;
                    PutAttachmentCommandHelper.ValidateStream(stream);
                    if (_attachmentStreams.Add(stream) == false)
                    {
                        PutAttachmentCommandHelper.ThrowStreamAlready();
                    }
                }
            }

            _options = options;

            Timeout = options?.RequestTimeout;
        }
示例#4
0
 public ClusterWideBatchCommand(DocumentConventions conventions, JsonOperationContext context, IList <ICommandData> commands, BatchOptions options = null) : base(conventions, context, commands, options, TransactionMode.ClusterWide)
 {
 }
示例#5
0
 public BatchCommand(DocumentConventions conventions, JsonOperationContext context, IList <ICommandData> commands, BatchOptions options = null, TransactionMode mode = TransactionMode.SingleNode) : base(conventions, context, commands, options, mode)
 {
 }
示例#6
0
 public ClusterWideBatchCommand(DocumentConventions conventions, IList <ICommandData> commands, BatchOptions options = null, bool?disableAtomicDocumentsWrites = null) :
     base(conventions, context: null, commands, options, TransactionMode.ClusterWide)
 {
     DisableAtomicDocumentWrites = disableAtomicDocumentsWrites;
 }