Esempio n. 1
0
        public async Task <T> GetById(int id)
        {
            IEnumerable <Event> events;
            var memento = await _storage.GetMemento <BaseMemento>(id).ConfigureAwait(false);

            if (memento != null)
            {
                var list = await _storage.GetEvents(id).ConfigureAwait(false);

                events = list.Where(e => e.Version >= memento.Version);
            }
            else
            {
                events = await _storage.GetEvents(id).ConfigureAwait(false);
            }

            var obj = new T();

            if (memento != null)
            {
                ((IOriginator)obj).SetMemento(memento);
            }

            await Task.Run(() => obj.LoadsFromHistory(events)).ConfigureAwait(false);

            return(obj);
        }
Esempio n. 2
0
        public T GetById(Guid id)
        {
            IEnumerable <Event> events;
            var memento = _eventStorage.GetMemento <BaseMemento>(id);

            if (memento != null)
            {
                events = _eventStorage.GetEvents(id).Where(e => e.Version >= memento.Version);
            }
            else
            {
                events = _eventStorage.GetEvents(id);
            }
            var obj = new T();

            if (memento != null)
            {
                ((IOriginator)obj).SetMemento(memento);
            }
            obj.LoadsFromHistory(events);
            return(obj);
        }
Esempio n. 3
0
        public T GetById(Guid id)
        {
            //获取该记录的所有缓存事件
            IEnumerable <Event> events;
            var obj = new T();
            //获取该记录的更改快照
            var memento = _eventStorage.GetMemento <BaseMemento>(id);

            if (memento != null)
            {
                //获取该记录最后一次快照之后的更改,避免加载过多历史更改
                events = _eventStorage.GetEvents(id).Where(x => x.Version >= memento.Version);
                //从快照恢复
                ((IOriginator)obj).SetMemento(memento);
            }
            else
            {
                //获取所有历史更改记录
                events = _eventStorage.GetEvents(id);
            }
            //重现历史更改
            obj.LoadsFromHistory(events);
            return(obj);
        }
Esempio n. 4
0
        public TAggregateRoot GetById(Guid id)
        {
            IEnumerable <IEvent> events;
            var memento = _eventStorage.GetMemento <Memento>(id);

            if (memento != null)
            {
                events = _eventStorage.GetEvents(id).Where(e => e.Version >= memento.Version);
            }
            else
            {
                events = _eventStorage.GetEvents(id);
            }

            var instance = new TAggregateRoot();

            if (memento != null)
            {
                ((IOriginator)instance).SetMemento(memento);
            }

            instance.LoadDataFromHistories(events);
            return(instance);
        }
Esempio n. 5
0
        public T GetById(Guid id)
        {
            IEnumerable <Event> events;

            if (_storage == null)
            {
                return(new T());
            }
            var memento = _storage.GetMemento <BaseMemento>(id);

            events = memento != null
                ? _storage.GetEvents(id).Where(p => p.Version >= memento.Version)
                : _storage.GetEvents(id);

            var obj = new T();

            if (memento != null)
            {
                ((IOriginator)obj).SetMemento(memento);
            }

            obj.LoadsFromHistory(events);
            return(obj);
        }