public SnapshotChangeset ExtractSnapshotChanges(IEnumerable <HistoricalEvent> events, T2 actual)
        {
            var sourceEvent = events.FirstOrDefault();

            var sourceObject = sourceEvent.Changeset == null?
                               JsonConvert.DeserializeObject <T2>(sourceEvent.Changeset.ObjectData) :
                                   JsonConvert.DeserializeObject <T2>(sourceEvent.Changeset.ObjectDelta);

            var snapshotChangeset = new SnapshotChangeset();

            snapshotChangeset.EntityTypeName    = sourceEvent.EntityName;
            snapshotChangeset.EntityId          = sourceEvent.EntityId;
            snapshotChangeset.LastViewed        = GetLastTimeViewed <T2>(actual.Id).Value;
            snapshotChangeset.LastModifiedBy    = events.Last().CreatedBy;
            snapshotChangeset.LastModifiedEvent = events.Last().Action;
            snapshotChangeset.LastModifiedDate  = events.Last().CreatedDate.Value;
            // TODO: Bug here if entity is deleted or not found
            snapshotChangeset.Changes = ExtractChanges(sourceObject, actual);
            return(snapshotChangeset);
        }
Ejemplo n.º 2
0
        private SnapshotChangeset ExtractSnapshotChanges(IEnumerable <HistoricalEvent> events, TEntity actual)
        {
            var actualDto   = _mapper.Map <TDto>(actual);
            var sourceEvent = events.FirstOrDefault();

            var sourceObject = sourceEvent.Changeset == null?
                               JsonConvert.DeserializeObject <TEntity>(sourceEvent.Changeset.ObjectData) :
                                   JsonConvert.DeserializeObject <TEntity>(sourceEvent.Changeset.ObjectDelta);

            var sourceDto = _mapper.Map <TDto>(sourceObject);

            var snapshotChangeset = new SnapshotChangeset();

            snapshotChangeset.EntityTypeName    = sourceEvent.EntityName;
            snapshotChangeset.EntityId          = sourceEvent.EntityId;
            snapshotChangeset.LastViewed        = DateTime.MinValue; // TODO: Get Last Viewed Info from read status (if available)
            snapshotChangeset.LastModifiedBy    = events.Last().CreatedBy;
            snapshotChangeset.LastModifiedEvent = events.Last().Action;
            snapshotChangeset.LastModifiedDate  = events.Last().CreatedDate.Value;
            // TODO: Bug here if entity is deleted or not found
            snapshotChangeset.Changes = _historicalCrudReadService.ExtractChanges(sourceDto, actualDto);
            return(snapshotChangeset);
        }