Exemple #1
0
        /// <summary>
        /// AppendStream appends the provides messages to the specified stream.
        /// </summary>
        /// <param name="streamId">The stream to append to. If the stream does not exists, it will be created.</param>
        /// <param name="concurrencyCheck">The optimistic concurrency check. See <see cref="ConcurrencyCheck"/> for different options.</param>
        /// <param name="messages">The messages to append.</param>
        /// <returns>The position in the stream of the first message that has been written.</returns>
        public async Task <long> AppendStream(string streamId, ConcurrencyCheck concurrencyCheck, IEnumerable <MessageInput> messages)
        {
            var request = new AppendStreamRequest
            {
                Database        = _db,
                Stream          = streamId,
                ExpectedVersion = -2,
            };

            concurrencyCheck.InterceptRequest(request);

            foreach (var m in messages)
            {
                if (string.IsNullOrEmpty(m.Type))
                {
                    throw new ArgumentNullException(nameof(m.Type), "missing type name");
                }

                request.Messages.Add(new Wire.MessageInput
                {
                    Type   = m.Type,
                    Header = ByteString.CopyFrom(m.Header ?? new byte[0]),
                    Value  = ByteString.CopyFrom(m.Value ?? new byte[0]),
                });
            }

            var reply = await _client.AppendStreamAsync(request, _metadata);

            return(reply.From);
        }
Exemple #2
0
 /// <summary>
 /// AppendStream appends the provides messages to the specified stream.
 /// </summary>
 /// <param name="streamId">The stream to append to. If the stream does not exists, it will be created.</param>
 /// <param name="concurrencyCheck">The optimistic concurrency check. See <see cref="ConcurrencyCheck"/> for different options.</param>
 /// <param name="messages">The messages to append.</param>
 /// <returns>The position in the stream of the first message that has been written.</returns>
 public async Task <long> AppendStream(string streamId, ConcurrencyCheck concurrencyCheck, params MessageInput[] messages) => await AppendStream(streamId, concurrencyCheck, (IEnumerable <MessageInput>) messages);
Exemple #3
0
 /// <summary>
 /// AppendStream appends the provides messages to the specified stream.
 /// </summary>
 /// <param name="streamId">The stream to append to. If the stream does not exists, it will be created.</param>
 /// <param name="messages">The messages to append.</param>
 /// <returns>The position in the stream of the first message that has been written.</returns>
 public async Task <long> AppendStream(string streamId, params MessageInput[] messages) => await AppendStream(streamId, ConcurrencyCheck.Skip(), messages);
Exemple #4
0
 /// <summary>
 /// AppendStream appends the provides messages to the specified stream.
 /// </summary>
 /// <param name="streamId">The stream to append to. If the stream does not exists, it will be created.</param>
 /// <param name="messages">The messages to append.</param>
 /// <returns>The position in the stream of the first message that has been written.</returns>
 public async Task <long> AppendStream(string streamId, IEnumerable <MessageInput> messages) => await AppendStream(streamId, ConcurrencyCheck.Skip(), messages);
Exemple #5
0
 public StreamInput(string stream, ConcurrencyCheck concurrencyCheck, IEnumerable <MessageInput> messages)
 {
     Stream           = stream;
     ConcurrencyCheck = concurrencyCheck;
     Messages         = messages;
 }
Exemple #6
0
 public StreamInput(string stream, IEnumerable <MessageInput> messages) : this(stream, ConcurrencyCheck.Skip(), messages)
 {
 }