public virtual async Task Save <T>(T aggregate, CancellationToken token = default)
            where T : class, IEventSourcingAggregateRoot <TId>, new()
        {
            _eventStore.AppendEvents(aggregate.Id, aggregate.GetUncommittedEvents());
            await _eventStore.CommitEvents(token);

            await PublishEvents(aggregate, token);
        }
    public async Task <IActionResult> CalendarDayStarted(string date)
    {
        var commandMetadata = GetCommandMetadata();

        await _eventStore.AppendEvents("doctorday-time-events", commandMetadata, new CalendarDayStarted(DateTime.Parse(date)));

        return(Ok());
    }
    public async Task Save <T>(T aggregate) where T : AggregateRoot
    {
        if (aggregate == null)
        {
            throw new ArgumentNullException(nameof(aggregate));
        }

        var streamName = GetStreamName(aggregate);
        var changes    = aggregate.GetChanges().ToArray();

        await _store.AppendEvents(streamName, aggregate.Version, changes);

        aggregate.ClearChanges();
    }
Beispiel #4
0
        public async Task Store <T>(T aggregate)
            where T : Aggregate
        {
            Ensure.NotNull(aggregate, nameof(aggregate));

            if (aggregate.Changes.Count == 0)
            {
                return;
            }

            var stream          = StreamName.For <T>(aggregate.GetId());
            var expectedVersion = new ExpectedStreamVersion(aggregate.OriginalVersion);

            await _eventStore.AppendEvents(stream, expectedVersion, aggregate.Changes.Select(ToStreamEvent).ToArray());

            StreamEvent ToStreamEvent(object evt)
            => new(TypeMap.GetTypeName(evt), _serializer.Serialize(evt), null, _serializer.ContentType);
        }
Beispiel #5
0
        public async Task Store <T>(T aggregate)
            where T : Aggregate
        {
            if (aggregate == null)
            {
                throw new ArgumentNullException(nameof(aggregate));
            }

            if (aggregate.Changes.Count == 0)
            {
                return;
            }

            var stream          = StreamName.For <T>(aggregate.GetId());
            var expectedVersion = new ExpectedStreamVersion(aggregate.Version);

            await _eventStore.AppendEvents(stream, expectedVersion, aggregate.Changes.Select(ToStreamEvent).ToArray());

            StreamEvent ToStreamEvent(object evt)
            => new(TypeMap.GetTypeName(evt), _serializer.Serialize(evt));
        }
    public async Task should_archive_all_events_and_truncate_all_except_last_one()
    {
        var dayId       = Guid.NewGuid().ToString();
        var scheduled   = new SlotScheduled(Guid.NewGuid(), dayId, _now, _tenMinutes);
        var slotBooked  = new SlotBooked(dayId, scheduled.SlotId, "PatientId");
        var dayArchived = new DayScheduleArchived(dayId);

        var metadata = new CommandMetadata(new CorrelationId(Guid.NewGuid()), new CausationId(Guid.NewGuid()));

        var events = new List <object> {
            scheduled, slotBooked, dayArchived
        };

        await _esStore.AppendEvents("Day-" + dayId, metadata, events.ToArray());

        await Given(dayArchived);

        Then(events, _inMemoryColdStorage.Events);
        Then(new List <object> {
            dayArchived
        }, await _esStore.LoadEvents("Day-" + dayId));
    }
Beispiel #7
0
    public async Task Save <T>(T aggregate, CommandMetadata metadata) where T : AggregateRoot
    {
        if (aggregate == null)
        {
            throw new ArgumentNullException(nameof(aggregate));
        }

        var streamName = GetStreamName(aggregate);

        var changes = aggregate.GetChanges().ToArray();

        await _store.AppendEvents(streamName, aggregate.Version, metadata, changes);

        // Append snapshot
        if (aggregate is AggregateRootSnapshot snapshotAggregate)
        {
            if ((snapshotAggregate.Version + changes.Length + 1) - snapshotAggregate.SnapshotVersion >= _snapshotThreshold)
            {
                await _store.AppendSnapshot(streamName, aggregate.Version + changes.Length, snapshotAggregate.GetSnapshot());
            }
        }

        aggregate.ClearChanges();
    }
Beispiel #8
0
        public void AppendEvents(T aggregate)
        {
            var events = aggregate.GetUncommittedEvents();

            eventStore.AppendEvents(GetStreamName(aggregate.Id), events);
        }
Beispiel #9
0
        public async Task Save(TAgg aggregate)
        {
            await _eventStore.AppendEvents(aggregate.AggregateRootId, aggregate.DomainEvents, aggregate.Version);

            await _dispatcher.Dispatch(aggregate.DomainEvents);
        }
        public async Task Save <T, TId>(T aggregate) where T : AggregateRoot <TId>
        {
            await _eventStore.StoreStreamMetadata(aggregate.Id.ToString(), AggregateRootTypeKey, aggregate.GetType().AssemblyQualifiedName);

            await _eventStore.AppendEvents(aggregate.Id.ToString(), aggregate.GetEvents(), aggregate.Version);
        }