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

            Timeout = options?.RequestTimeout;
        }
コード例 #2
0
        public PutAttachmentCommandData(string documentId, string name, Stream stream, string contentType, string changeVector)
        {
            if (string.IsNullOrWhiteSpace(documentId))
            {
                throw new ArgumentNullException(nameof(documentId));
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            Id           = documentId;
            Name         = name;
            Stream       = stream;
            ContentType  = contentType;
            ChangeVector = changeVector;

            PutAttachmentCommandHelper.ValidateStream(stream);
        }