Ejemplo n.º 1
0
        private static void EventAppeared(EventStoreCatchUpSubscription s, ResolvedEvent e)
        {
            if (e.Event.EventType != "withdrew")
            {
                return;
            }

            var o           = e.Deserialze();
            var withdrew    = o as V1.Withdrew;
            var withdrewFix = new V1.WithdrewFix
            {
                Id          = withdrew.Id,
                Amount      = new Account().CalculateFee(withdrew.Amount),
                Description = "my fix",
                ChangedAt   = DateTime.Now,
                WithdrewId  = e.Event.EventId
            };
            var data = new EventData(
                Guid.NewGuid(),
                EventTypeMapper.GetTypeName(withdrewFix.GetType()),
                true,
                Encoding.Default.GetBytes(JsonConvert.SerializeObject(withdrewFix)), null);

            eventStoreConnection.AppendToStreamAsync(e.OriginalStreamId, ExpectedVersion.Any, data);

            Console.WriteLine($"Last position of fix=> {e.OriginalPosition.Value.CommitPosition}");
        }
        public async Task <long> SaveSnapshotAsync <T>(Snapshot snapshot) where T : Aggregate
        {
            var stream = GetStreamName <T>(snapshot.AggregateId);

            var snapshotEvent = new EventData(
                snapshot.Id,
                EventTypeMapper.GetTypeName(snapshot.GetType()),
                EventSerializer.IsJsonSerializer,
                EventSerializer.Serialize(snapshot),
                null);

            var result = await eventStoreConnection.AppendToStreamAsync(stream, ExpectedVersion.Any, snapshotEvent);

            return(result.LogPosition.CommitPosition);
        }