コード例 #1
0
ファイル: BatchCommand.cs プロジェクト: ikvm/ravendb
        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
ファイル: BatchCommand.cs プロジェクト: syrjgc11006/ravendb
        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;
        }