Example #1
0
        void IEventStore.SaveEvents(ItemIdentity aggregateId, IEnumerable <Event> events, int expectedVersion)
        {
            List <EventDescriptor> eventDescriptors;

            // try to get event descriptors list for given aggregate id
            // otherwise -> create empty dictionary
            if (!_current.TryGetValue(aggregateId, out eventDescriptors))
            {
                eventDescriptors = new List <EventDescriptor>();
                _current.Add(aggregateId, eventDescriptors);
            }
            // check whether latest event version matches current aggregate version
            // otherwise -> throw exception
            else if (eventDescriptors[eventDescriptors.Count - 1].Version != expectedVersion && expectedVersion != -1)
            {
                throw new ConcurrencyException();
            }
            var i = expectedVersion;

            // iterate through current aggregate events increasing version with each processed event
            foreach (var @event in events)
            {
                i++;
                @event.Version = i;

                // push event to the event descriptors list for current aggregate
                eventDescriptors.Add(new EventDescriptor(aggregateId, @event, i));

                // publish current event to the bus for further processing by subscribers
                _publisher.Publish(@event);
            }
        }
Example #2
0
        void IEventStore.SaveEvents(ItemIdentity aggregateId, IEnumerable<Event> events, int expectedVersion)
        {
            List<EventDescriptor> eventDescriptors;

            // try to get event descriptors list for given aggregate id
            // otherwise -> create empty dictionary
            if (!_current.TryGetValue(aggregateId, out eventDescriptors))
            {
                eventDescriptors = new List<EventDescriptor>();
                _current.Add(aggregateId, eventDescriptors);
            }
            // check whether latest event version matches current aggregate version
            // otherwise -> throw exception
            else if (eventDescriptors[eventDescriptors.Count - 1].Version != expectedVersion && expectedVersion != -1)
            {
                throw new ConcurrencyException();
            }
            var i = expectedVersion;

            // iterate through current aggregate events increasing version with each processed event
            foreach (var @event in events)
            {
                i++;
                @event.Version = i;

                // push event to the event descriptors list for current aggregate
                eventDescriptors.Add(new EventDescriptor(aggregateId, @event, i));

                // publish current event to the bus for further processing by subscribers
                _publisher.Publish(@event);
            }
        }
Example #3
0
        public T GetId(ItemIdentity identity)
        {
            var obj = new T();//lots of ways to do this
            var e   = _storage.GetEventsForAggregate(identity);

            obj.LoadsFromHistory(e);
            return(obj);
        }
Example #4
0
        List <Event> IEventStore.GetEventsForAggregate(ItemIdentity aggregateId)
        {
            List <EventDescriptor> eventDescriptors;

            if (!_current.TryGetValue(aggregateId, out eventDescriptors))
            {
                throw new AggregateNotFoundException();
            }

            return(eventDescriptors.Select(desc => desc.EventData).ToList());
        }
Example #5
0
        List<Event> IEventStore.GetEventsForAggregate(ItemIdentity aggregateId)
        {
            List<EventDescriptor> eventDescriptors;

            if (!_current.TryGetValue(aggregateId, out eventDescriptors))
            {
                throw new AggregateNotFoundException();
            }

            return eventDescriptors.Select(desc => desc.EventData).ToList();

        }
Example #6
0
 public EventDescriptor(ItemIdentity id, Event eventData, int version)
 {
     Id        = id;
     EventData = eventData;
     Version   = version;
 }
 public InventoryItemDeactivated(ItemIdentity id) : base(id)
 {
 }
 public ItemCreatedEvent(ItemIdentity id)
 {
     Id = id;
 }
 public InventoryItemRenamed(ItemIdentity id,string name)
 {
     Name = name;
 }
Example #10
0
 public EventDescriptor(ItemIdentity id, Event eventData, int version)
 {
     Id = id;
     EventData = eventData;  
     Version = version;
 }
 public ItemsCheckedInToInventory(ItemIdentity id, int count)
 {
     Count = count;
 }
 public ItemCreatedEvent(ItemIdentity id)
 {
     Id = id;
 }
Example #13
0
 public AggregateRoot(ItemIdentity id)
 {
     Id = id;
 }
        public InventoryItemCreated(ItemIdentity id,string name) :base(id)
        {

        }