예제 #1
0
 public void Write(string streamName, int streamVersion, EntryBatch batch)
 {
     lock (store)
     {
         foreach (EntryBatch.Entry entry in batch.Entries)
         {
             store.Add(new EntryValue(streamName, streamVersion, entry.Type, entry.Body, entry.Snapshot));
         }
     }
 }
예제 #2
0
 public void Write(EntryBatch batch)
 {
     lock (store)
     {
         foreach (EntryBatch.Entry entry in batch.Entries)
         {
             store.Add(new EntryValue("", 0, entry.Type, entry.Body, ""));
         }
     }
 }
        protected EntryBatch ToBatch <T>(IEnumerable <T> sources) where T : DomainEvent
        {
            var localSources = sources.ToList();
            var batch        = new EntryBatch(localSources.Count);

            foreach (var source in localSources)
            {
                var eventBody             = Serialization.Serialize(source);
                var assemblyQualifiedName = source?.GetType().AssemblyQualifiedName;
                if (!string.IsNullOrEmpty(assemblyQualifiedName))
                {
                    batch.AddEntry(assemblyQualifiedName !, eventBody);
                }
            }
            return(batch);
        }
예제 #4
0
        public void Write <T>(string streamName, int streamVersion, EntryBatch batch)
        {
            lock (((ICollection)store).SyncRoot)
            {
                if (!TryCanWrite(streamName, streamVersion, out var currentVersion))
                {
                    throw new IndexOutOfRangeException($"Cannot write to stream '{streamName}' with expected version {streamVersion} because the current version is {currentVersion}");
                }

                var offset = 1;
                foreach (var entry in batch.Entries)
                {
                    store.Add(new EntryValue(StreamNameBuilder.BuildStreamNameFor <T>(streamName), streamVersion + offset, entry.Type, entry.Body, entry.Snapshot));
                    offset++;
                }
            }
        }
예제 #5
0
        public void Write(EntryBatch batch)
        {
            lock (((ICollection)store).SyncRoot)
            {
                if (!TryCanWrite(string.Empty, EntryValue.NoStreamVersion, out var currentVersion))
                {
                    throw new IndexOutOfRangeException($"Cannot write to stream '{string.Empty}' with expected version {EntryValue.NoStreamVersion} because the current version is {currentVersion}");
                }

                var offset = 1;
                foreach (var entry in batch.Entries)
                {
                    store.Add(new EntryValue(string.Empty, 0 + offset, entry.Type, entry.Body, string.Empty));
                    offset++;
                }
            }
        }