Esempio n. 1
0
        public T Get <T, TId>(string bucketId, string id, int version)
            where T : class, IEventSource <TId>
        {
            Logger.Debug("Get event source Id '{0}', Type '{1}'", id, typeof(T).Name);

            if (string.IsNullOrEmpty(id) || string.IsNullOrWhiteSpace(id))
            {
                Logger.Warn("Try to read event store with Guid.Empty");
                return(null);
            }

            var eventSource = _eventSourceFactory.Create <T>();

            bool hasSnaphot = this.RestoreSnapshot <T, TId>(bucketId, id, eventSource, version);
            bool hasEvents  = this.Hydrate(bucketId, id, eventSource, version);

            if (!(hasSnaphot || hasEvents))
            {
                Logger.Debug("No event source found using the id {0}", id);
                return(null);
            }

            if (string.IsNullOrEmpty(eventSource.StringId))
            {
                Logger.Warn(string.Format("Source with id {0} found in eventstore, but after hydration the id was not set properly {1}", id, eventSource.StringId));
                return(null);
            }

            return(eventSource);
        }
Esempio n. 2
0
        public T Get <T>(Guid id) where T : class, IEventSource
        {
            var eventSource = _eventSourceFactory.Create <T>();

            RestoreSnapshot(id, eventSource);
            Hydrate(id, eventSource);

            return(eventSource.Id != Guid.Empty ? eventSource : null);
        }
Esempio n. 3
0
        public T Build()
        {
            _source = _aggregate = _eventSourceFactory.Create <T>();

            _source.Hydrate(_events);
            _source.Flush();

            return(_aggregate);
        }
Esempio n. 4
0
        public T Get <T>(Guid id) where T : class, IEventSource
        {
            Logger.Debug("Get event source Id '{0}', Type '{1}'", id, typeof(T).Name);

            var eventSource = _eventSourceFactory.Create <T>();

            RestoreSnapshot(id, eventSource);
            Hydrate(id, eventSource);

            return(eventSource.Id != Guid.Empty ? eventSource : null);
        }