Beispiel #1
0
        /// <summary>
        /// Saves the snap shot.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="snapShotType">Type of the snap shot.</param>
        /// <param name="events">The events.</param>
        /// <param name="state">The state.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        public void SaveSnapShot(TEntity entity, SnapShotType snapShotType, IEnumerable <IDomainEvent <TEntity> > events, string state)
        {
            var query = _querySnapshotBuilder.GetQuery(snapShotType, entity);

            var entitySourceWrapper = (EntityEventSourceWrapper)NHibernateHelper.CurrentSession
                                      .CreateCriteria <EntityEventSourceWrapper>()
                                      .Add(query).UniqueResult();

            entitySourceWrapper.SnapShot = entity.ToBson();
            entitySourceWrapper.Version  = entity.Version;
            entitySourceWrapper.State    = state;

            entitySourceWrapper.ClearEvents();

            foreach (var domainEvent in events)
            {
                var eventWrapper = new EventWrapper
                {
                    Type = domainEvent.GetType().Name,
                    Data = domainEvent.ToBson()
                };
                entitySourceWrapper.AddEvent(eventWrapper);
            }
            NHibernateHelper.CurrentSession.Update(entitySourceWrapper);
            NHibernateHelper.CurrentSession.Flush();
        }
Beispiel #2
0
 /// <summary>
 /// Saves the snap shot.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <param name="snapShotType">Type of the snap shot.</param>
 /// <param name="events">The events.</param>
 /// <param name="state">The state.</param>
 public void SaveSnapShot(TEntity entity, SnapShotType snapShotType, IEnumerable <IDomainEvent <TEntity> > events, string state)
 {
     _repository.Update
     (
         _mongoBuilder.GetQuery(snapShotType, entity),
         x => ((UpdateBuilder)x.GetUpdateBuilder())
         .Set("SnapShot", BsonDocumentWrapper.Create(entity))
         .Set("Version", BsonDocumentWrapper.Create(entity.Version))
         .Set("State", BsonDocumentWrapper.Create(state))
         .PullAll("Events", events.Select(BsonDocumentWrapper.Create))
         .Set("AppliedEvents", BsonDocumentWrapper.Create(events))
     );
 }