Example #1
0
        public void SaveEvents(Guid id, IEnumerable<Event> events, int expectedVersion)
        {
            EventDescriptionCollection collection = GetEventDescriptionCollection(id);

            // PERHAPS: If it's an entirely new event stream, no use in querying the database
            //if (events.First().Version != -1)
            //{
            //    collection = GetEventDescriptionCollection(id);
            //}

            if (collection == null)
            {
                collection = new EventDescriptionCollection(id);
            }
            else if (collection.Items.Any() && collection.LatestVersion != expectedVersion)
            {
                throw new ConcurrencyException();
            }

            foreach (var @event in events)
            {
                expectedVersion++;
                @event.Version = expectedVersion;
                collection.Add(id, @event);
            }

            PersistEventDescriptionCollection(collection);

            foreach (var @event in events)
            {
                _serviceBus.Publish(@event);
            }
        }
Example #2
0
 protected override void PersistEventDescriptionCollection(EventDescriptionCollection collection)
 {
     lock (_syncLock)
     {
         if (!_eventStore.ContainsKey(collection.Id))
         {
             _eventStore.Add(collection.Id, collection);
         }
     }
 }
Example #3
0
 protected abstract void PersistEventDescriptionCollection(EventDescriptionCollection collection);
Example #4
0
 protected override void PersistEventDescriptionCollection(EventDescriptionCollection collection)
 {
     _repository.Put(collection);
 }