Exemplo n.º 1
0
        public void Set(CommandContext commandContext, IEventSourceBase eventSource)
        {
            var id           = eventSource.StringId;
            var bucketId     = eventSource.BucketId;
            var type         = eventSource.GetType();
            var oldVersion   = eventSource.Version;
            var events       = eventSource.Flush();
            var newVersion   = eventSource.Version;
            var commitId     = commandContext.Id;
            var headers      = commandContext.Headers;
            var eventHeaders = new Dictionary <object, Dictionary <string, object> >();

            if (!events.Any())
            {
                return;
            }

            Logger.Debug("Set event source Id '{0}', Version '{1}', Type '{2}', CommitId '{3}'", id, newVersion, eventSource.GetType().Name, commitId);

            headers["AggregateId"]       = id;
            headers["AggregateBucketId"] = bucketId;
            headers["AggregateVersion"]  = newVersion;
            headers["AggregateType"]     = type.FullName;

            for (int i = 0; i < events.Count(); i++)
            {
                eventHeaders[events.ElementAt(i)] = new Dictionary <string, object> {
                    { "EventVersion", oldVersion + i + 1 }
                };
            }

            try
            {
                _eventStore.Write(bucketId, id, oldVersion, events, commitId, headers, eventHeaders);
            }
            catch (ConflictingCommandException)
            {
                // TODO: Check if the events actually conflict
                throw;
            }
        }
Exemplo n.º 2
0
 protected override void Event()
 {
     _flushedEvents = _eventSource.Flush().Cast <IEvent>();
 }