Пример #1
0
        public void Save(Guid batchId, IEnumerable <EventData> events)
        {
            lock (_lock)
            {
                var batch = events.ToList();

                bool isCorrupted;
                var  globalSequenceNumber = CommitLog.Read(out isCorrupted);
                if (isCorrupted)
                {
                    CommitLog.Recover();
                }

                GlobalSequenceIndex.DetectCorruptionAndRecover(DataStore, globalSequenceNumber);

                foreach (var domainEvent in batch)
                {
                    domainEvent.Meta[DomainEvent.MetadataKeys.GlobalSequenceNumber] = (++globalSequenceNumber).ToString(Metadata.NumberCulture);
                    domainEvent.Meta[DomainEvent.MetadataKeys.BatchId] = batchId.ToString();
                }

                EventValidation.ValidateBatchIntegrity(batchId, batch);

                GlobalSequenceIndex.Write(batch);
                DataStore.Write(batchId, batch);
                CommitLog.Write(globalSequenceNumber);
            }
        }
Пример #2
0
        public IEnumerable <EventData> Stream(long globalSequenceNumber = 0)
        {
            var lastCommittedGlobalSequenceNumber = CommitLog.Read();

            return(from record in GlobalSequenceIndex.Read(lastCommittedGlobalSequenceNumber, offset: globalSequenceNumber)
                   select DataStore.Read(record.AggregateRootId, record.LocalSequenceNumber));
        }
Пример #3
0
        internal NtfsEventStore(string basePath, bool dropEvents)
        {
            Directory.CreateDirectory(basePath);

            GlobalSequenceIndex = new GlobalSequenceIndex(basePath, dropEvents);
            DataStore = new DataStore(basePath, dropEvents);
            CommitLog = new CommitLog(basePath, dropEvents);
        }
Пример #4
0
        public NtfsEventStore(string basePath, bool dropEvents)
        {
            Directory.CreateDirectory(basePath);

            GlobalSequenceIndex = new GlobalSequenceIndex(basePath, dropEvents);
            DataStore           = new DataStore(basePath, dropEvents);
            CommitLog           = new CommitLog(basePath, dropEvents);
        }
Пример #5
0
 public void Dispose()
 {
     GlobalSequenceIndex.Dispose();
     CommitLog.Dispose();
 }