コード例 #1
0
        /// <inheritdoc />
        public async Task <T> Find <T>(string id, bool computeHash = false)
            where T : class, TEventSourced, new()
        {
            var stream = await _streams.Find <T>(id, _timeline.Id);

            if (stream == null)
            {
                return(null);
            }
            TEventSourced es;

#if USE_ES_CACHE
            if (_cache.TryGetValue(stream.Key, out es) && es.Version == stream.Version)
            {
                es.Clear();
                return(es as T);
            }
#endif

            var start  = stream.SnapshotVersion;
            var events = await _eventStore.ReadStream <IEvent>(stream, start).ToList();

            if (events.Count == 0)
            {
                return(null);
            }
            es = EventSourced.Create <T>(id, start - 1, _log);
            es.LoadFrom <T>(events, computeHash);

            return(es as T);
        }
コード例 #2
0
        /// <inheritdoc />
        public async Task <T> GetOrAdd <T>(string id)
            where T : class, TEventSourced, new()
        {
            var instance = await Find <T>(id);

            return(instance ?? EventSourced.Create <T>(id, 0, _log));
        }
コード例 #3
0
        /// <inheritdoc />
        public async Task <int> LastValidVersion <T>(string id)
            where T : class, TEventSourced, new()
        {
            var stream = await _streams.Find <T>(id, _timeline.Id);

            if (stream == null)
            {
                return(ExpectedVersion.NoStream);
            }

            var start  = stream.SnapshotVersion;
            var events = await _eventStore.ReadStream <IEvent>(stream, start).ToList();

            var es = EventSourced.Create <T>(id, start - 1, _log);

            es.LoadFrom <T>(events, true);

            return(es.LastValidVersion);
        }
コード例 #4
0
        /// <inheritdoc />
        public async Task <IEnumerable <IEvent> > FindInvalidEvents <T>(string id)
            where T : class, TEventSourced, new()
        {
            _log.StopWatch.Start(nameof(FindInvalidEvents));
            var stream = await _streams.Find <T>(id, _timeline.Id);

            if (stream == null)
            {
                return(null);
            }

            // return new List<IEvent>();
            var start  = stream.SnapshotVersion;
            var events = await _eventStore.ReadStream <IEvent>(stream, start).ToList();

            var es = EventSourced.Create <T>(id, start - 1, _log);

            es.LoadFrom <T>(events, true);

            _log.StopWatch.Stop(nameof(FindInvalidEvents));
            return(es.GetInvalidEvents());
        }