Beispiel #1
0
        internal StreamAction Append(DocumentSessionBase session, string stream, params object[] events)
        {
            EnsureAsStringStorage(session);

            if (session.UnitOfWork.TryFindStream(stream, out var eventStream))
            {
                eventStream.AddEvents(events);
            }
            else
            {
                eventStream = StreamAction.Append(stream, events);
                session.UnitOfWork.Streams.Add(eventStream);
            }

            return(eventStream);
        }
Beispiel #2
0
        internal StreamAction StartStream(DocumentSessionBase session, Guid id, params object[] events)
        {
            EnsureAsGuidStorage(session);

            if (id == Guid.Empty)
            {
                throw new ArgumentOutOfRangeException(nameof(id), "Cannot use an empty Guid as the stream id");
            }


            var stream = StreamAction.Start(this, id, events);

            session.WorkTracker.Streams.Add(stream);

            return(stream);
        }
Beispiel #3
0
        internal StreamAction StartStream(DocumentSessionBase session, string streamKey, params object[] events)
        {
            EnsureAsStringStorage(session);

            if (streamKey.IsEmpty())
            {
                throw new ArgumentOutOfRangeException(nameof(streamKey), "The stream key cannot be null or empty");
            }


            var stream = StreamAction.Start(this, streamKey, events);

            session.WorkTracker.Streams.Add(stream);

            return(stream);
        }
        internal StreamAction StartEmptyStream(DocumentSessionBase session, string key, params object[] events)
        {
            EnsureAsStringStorage(session);

            if (key.IsEmpty())
            {
                throw new ArgumentOutOfRangeException(nameof(key), "Cannot use an empty or null string as the stream key");
            }


            var stream = new StreamAction(key, StreamActionType.Start);

            session.WorkTracker.Streams.Add(stream);

            return(stream);
        }
Beispiel #5
0
        internal StreamAction Append(DocumentSessionBase session, string stream, params object[] events)
        {
            EnsureAsStringStorage(session);

            var wrapped = events.Select(BuildEvent).ToArray();

            if (session.WorkTracker.TryFindStream(stream, out var eventStream))
            {
                eventStream.AddEvents(wrapped);
            }
            else
            {
                eventStream = StreamAction.Append(stream, wrapped);
                session.WorkTracker.Streams.Add(eventStream);
            }

            return(eventStream);
        }
Beispiel #6
0
        internal bool TryCreateTombstoneBatch(DocumentSessionBase session, out UpdateBatch batch)
        {
            if (session.UnitOfWork.Streams.Any())
            {
                var stream = StreamAction.ForTombstone();

                var tombstone = new Tombstone();
                var mapping   = EventMappingFor <Tombstone>();

                var operations = new List <IStorageOperation>();
                var storage    = session.EventStorage();

                var dotNetTypeName = DotnetTypeNameFor(typeof(Tombstone));

                operations.Add(_establishTombstone.Value);
                var tombstones = session.UnitOfWork.Streams
                                 .SelectMany(x => x.Events)
                                 .Select(x => new Event <Tombstone>(tombstone)
                {
                    Sequence       = x.Sequence,
                    Version        = x.Version,
                    TenantId       = x.TenantId,
                    StreamId       = EstablishTombstoneStream.StreamId,
                    StreamKey      = EstablishTombstoneStream.StreamKey,
                    Id             = CombGuidIdGeneration.NewGuid(),
                    EventTypeName  = mapping.EventTypeName,
                    DotNetTypeName = dotNetTypeName
                })
                                 .Select(e => storage.AppendEvent(this, session, stream, e));

                operations.AddRange(tombstones);

                batch = new UpdateBatch(operations);

                return(true);
            }

            batch = null;
            return(false);
        }
Beispiel #7
0
        internal StreamAction Append(DocumentSessionBase session, Guid stream, params object[] events)
        {
            EnsureAsGuidStorage(session);

            if (stream == Guid.Empty)
            {
                throw new ArgumentOutOfRangeException(nameof(stream), "Cannot use an empty Guid as the stream id");
            }

            var wrapped = events.Select(BuildEvent).ToArray();

            if (session.WorkTracker.TryFindStream(stream, out var eventStream))
            {
                eventStream.AddEvents(wrapped);
            }
            else
            {
                eventStream = StreamAction.Append(stream, wrapped);
                session.WorkTracker.Streams.Add(eventStream);
            }

            return(eventStream);
        }
Beispiel #8
0
        internal StreamAction Append(DocumentSessionBase session, string stream, params object[] events)
        {
            EnsureAsStringStorage(session);

            if (stream.IsEmpty())
            {
                throw new ArgumentOutOfRangeException(nameof(stream), "The stream key cannot be null or empty");
            }

            var wrapped = events.Select(BuildEvent).ToArray();

            if (session.WorkTracker.TryFindStream(stream, out var eventStream))
            {
                eventStream.AddEvents(wrapped);
            }
            else
            {
                eventStream = StreamAction.Append(stream, wrapped);
                session.WorkTracker.Streams.Add(eventStream);
            }

            return(eventStream);
        }
Beispiel #9
0
 public abstract IStorageOperation UpdateStreamVersion(StreamAction stream);
Beispiel #10
0
 public abstract IQueryHandler <StreamState> QueryForStream(StreamAction stream);
Beispiel #11
0
 public abstract IStorageOperation InsertStream(StreamAction stream);
Beispiel #12
0
 public abstract IStorageOperation AppendEvent(EventGraph events, IMartenSession session, StreamAction stream, IEvent e);
Beispiel #13
0
        public Task <StreamState> FetchStreamStateAsync(Guid streamId, CancellationToken token = default)
        {
            var handler = eventStorage().QueryForStream(StreamAction.ForReference(streamId, _tenant.TenantId));

            return(_session.ExecuteHandlerAsync(handler, token));
        }
Beispiel #14
0
        public StreamState FetchStreamState(Guid streamId)
        {
            var handler = eventStorage().QueryForStream(StreamAction.ForReference(streamId, _tenant.TenantId));

            return(_session.ExecuteHandler(handler));
        }
Beispiel #15
0
 public override Marten.Internal.Operations.IStorageOperation AppendEvent(Marten.Events.EventGraph events, Marten.Internal.IMartenSession session, Marten.Events.StreamAction stream, Marten.Events.IEvent e)
 {
     return(new Marten.Generated.EventStore.AppendEventOperation(stream, e));
 }
Beispiel #16
0
 public override Marten.Internal.Operations.IStorageOperation InsertStream(Marten.Events.StreamAction stream)
 {
     return(new Marten.Generated.EventStore.GeneratedInsertStream(stream));
 }
Beispiel #17
0
 public GeneratedInsertStream(Marten.Events.StreamAction stream) : base(stream)
 {
     _stream = stream;
 }
Beispiel #18
0
        public StreamState FetchStreamState(string streamKey)
        {
            var handler = _tenant.EventStorage().QueryForStream(StreamAction.ForReference(streamKey, _tenant));

            return(_session.ExecuteHandler(handler));
        }
Beispiel #19
0
 public GeneratedStreamVersionOperation(Marten.Events.StreamAction stream) : base(stream)
 {
     _stream = stream;
 }
Beispiel #20
0
 public override Marten.Linq.QueryHandlers.IQueryHandler <Marten.Events.StreamState> QueryForStream(Marten.Events.StreamAction stream)
 {
     return(new Marten.Generated.EventStore.GeneratedStreamStateQueryHandler(stream.Id));
 }
Beispiel #21
0
 public override Marten.Internal.Operations.IStorageOperation UpdateStreamVersion(Marten.Events.StreamAction stream)
 {
     return(new Marten.Generated.EventStore.GeneratedStreamVersionOperation(stream));
 }
Beispiel #22
0
        public Task <StreamState> FetchStreamStateAsync(string streamKey, CancellationToken token = new CancellationToken())
        {
            var handler = _tenant.EventStorage().QueryForStream(StreamAction.ForReference(streamKey, _tenant));

            return(_session.ExecuteHandlerAsync(handler, token));
        }
Beispiel #23
0
 public AppendEventOperation(Marten.Events.StreamAction stream, Marten.Events.IEvent e) : base(stream, e)
 {
     _stream = stream;
     _e      = e;
 }