/// <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); }
internal override void InterceptRequest(AppendStreamRequest request) { request.ExpectedVersion = _version; }