public async Task AppendToStream(
            string streamId,
            int expectedVersion,
            NewStreamEvent[] events,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            CheckIfDisposed();

            var connection = _getConnection();

            var eventDatas = events.Select(e =>
            {
                var data = Encoding.UTF8.GetBytes(e.JsonData);
                var metadata = Encoding.UTF8.GetBytes(e.JsonMetadata);

                return new EventData(e.EventId, e.Type, true, data, metadata);
            });

            try
            {
                await connection
                    .AppendToStreamAsync(streamId, expectedVersion, eventDatas)
                    .NotOnCapturedContext();
            }
            catch(global::EventStore.ClientAPI.Exceptions.StreamDeletedException ex)
            {
                throw new StreamDeletedException(ex.Message, ex);
            }
            catch(global::EventStore.ClientAPI.Exceptions.WrongExpectedVersionException ex)
            {
                throw new WrongExpectedVersionException(ex.Message, ex);
            }
        }
 public static Task AppendToStream(
     this IEventStore eventStore,
     string streamId,
     int expectedVersion,
     NewStreamEvent newStreamEvent)
 {
     return eventStore.AppendToStream(streamId, expectedVersion, new[] { newStreamEvent });
 }
        public Task AppendToStream(string streamId, int expectedVersion, NewStreamEvent[] events, CancellationToken cancellationToken = default(CancellationToken))
        {
            var connection = _getConnection();
            connection.BeginTransaction();

            //TODO Idempotency check
            /*var sequence = connection.Table<Event>()
                .Where(e => e.BucketId == "default" && e.StreamId == streamId)
                .OrderByDescending(e => e.StreamVersion)
                .Select(e => e.StreamVersion)
                .Take(1)
                .ToList()
                .FirstOrDefault();

            if(sequence != expectedVersion)
            {
                throw new Exception();
            }*/

            var sequence = 0;
            var eventsToInsert = events.Select(e => new SqliteEvent
            {
                JsonData = e.JsonData,
                EventId = e.EventId,
                JsonMetadata = e.JsonMetadata,
                IsDeleted = false,
                OriginalStreamId = streamId,
                SequenceNumber = sequence++,
                Created = _getUtcNow().UtcDateTime,
                StreamId = streamId
            });

            foreach(var eventToInsert in eventsToInsert)
            {
                connection.Insert(eventToInsert);
            }
            connection.Commit();

            return Task.FromResult(0);
        }
 public Task AppendToStream(string streamId, int expectedVersion, NewStreamEvent[] events, CancellationToken cancellationToken = default(CancellationToken))
 {
     return _inner.AppendToStream(streamId, expectedVersion, events, cancellationToken);
 }