A transaction performed by a user.
Example #1
0
        internal ConceptualRevision(
            int conceptualEntityId, IEnumerable <Tuple <IEnumerable <RevisionId>, IEnumerable <Revision> > > entityTypeAndRevisionSetPairs,
            Func <Func <IEnumerable <RevisionId>, IEnumerable <int> >, ConceptualEntityStateType> conceptualEntityStateSelector,
            Func <Func <IEnumerable <RevisionId>, IEnumerable <RevisionIdDelta <UserType> > >, ConceptualEntityDeltaType> conceptualEntityDeltaSelector,
            UserTransaction transaction, UserType user, ConceptualRevision <ConceptualEntityStateType, ConceptualEntityDeltaType, UserType> previous)
        {
            this.conceptualEntityId = conceptualEntityId;

            var cachedEntityTypeAndRevisionSetPairs =
                new Lazy <IReadOnlyCollection <Tuple <IEnumerable <RevisionId>, IEnumerable <Revision> > > >(() => entityTypeAndRevisionSetPairs.ToImmutableArray());

            revisionDictionariesByEntityType =
                new Lazy <ImmutableDictionary <IEnumerable <RevisionId>, ImmutableDictionary <int, Tuple <Revision, UserTransaction, UserType> > > >(
                    () => {
                if (previous == null)
                {
                    return(cachedEntityTypeAndRevisionSetPairs.Value.ToImmutableDictionary(
                               entityTypeAndRevisions => entityTypeAndRevisions.Item1,
                               entityTypeAndRevisions => entityTypeAndRevisions.Item2.ToImmutableDictionary(i => i.LatestRevisionId, i => Tuple.Create(i, transaction, user))));
                }

                var newEntityTypeAndRevisionDictionaryPairs =
                    new List <KeyValuePair <IEnumerable <RevisionId>, ImmutableDictionary <int, Tuple <Revision, UserTransaction, UserType> > > >(
                        cachedEntityTypeAndRevisionSetPairs.Value.Count);
                foreach (var entityTypeAndRevisions in cachedEntityTypeAndRevisionSetPairs.Value)
                {
                    var revisionsByLatestRevisionId = previous.revisionDictionariesByEntityType.Value.GetValueOrDefault(
                        entityTypeAndRevisions.Item1,
                        ImmutableDictionary <int, Tuple <Revision, UserTransaction, UserType> > .Empty);
                    newEntityTypeAndRevisionDictionaryPairs.Add(
                        new KeyValuePair <IEnumerable <RevisionId>, ImmutableDictionary <int, Tuple <Revision, UserTransaction, UserType> > >(
                            entityTypeAndRevisions.Item1,
                            revisionsByLatestRevisionId.SetItems(
                                entityTypeAndRevisions.Item2.Select(
                                    i => new KeyValuePair <int, Tuple <Revision, UserTransaction, UserType> >(i.LatestRevisionId, Tuple.Create(i, transaction, user))))));
                }
                return(previous.revisionDictionariesByEntityType.Value.SetItems(newEntityTypeAndRevisionDictionaryPairs));
            });

            conceptualEntityState =
                new Lazy <ConceptualEntityStateType>(
                    () =>
                    conceptualEntityStateSelector(
                        entityType =>
                        revisionDictionariesByEntityType.Value.GetValueOrDefault(entityType, ImmutableDictionary <int, Tuple <Revision, UserTransaction, UserType> > .Empty)
                        .Values.Select(i => i.Item1.RevisionId)));

            conceptualEntityDelta = new Lazy <ConceptualEntityDeltaType>(
                () => {
                var revisionSetsByEntityType = cachedEntityTypeAndRevisionSetPairs.Value.ToImmutableDictionary(i => i.Item1, i => i.Item2);
                return(conceptualEntityDeltaSelector(
                           entityType => revisionSetsByEntityType.GetValueOrDefault(entityType, new Revision[0]).Select(
                               revision => {
                    Tuple <Revision, UserTransaction, UserType> previousRevisionAndTransactionAndUser = null;
                    if (previous != null)
                    {
                        var previousRevisionsByLatestRevisionId = previous.revisionDictionariesByEntityType.Value.GetValueOrDefault(entityType);
                        if (previousRevisionsByLatestRevisionId != null)
                        {
                            previousRevisionAndTransactionAndUser = previousRevisionsByLatestRevisionId.GetValueOrDefault(revision.LatestRevisionId);
                        }
                    }
                    return previousRevisionAndTransactionAndUser == null
                                                                               ? new RevisionIdDelta <UserType>(revision.RevisionId, null, null, default(UserType))
                                                                               : new RevisionIdDelta <UserType>(
                        revision.RevisionId,
                        previousRevisionAndTransactionAndUser.Item1.RevisionId,
                        previousRevisionAndTransactionAndUser.Item2,
                        previousRevisionAndTransactionAndUser.Item3);
                })));
            });

            this.transaction = transaction;
            this.user        = user;
            this.previous    = previous;
        }
Example #2
0
 internal RevisionIdDelta(int newRevisionId, int?oldRevisionId, UserTransaction oldTransaction, UserType oldUser)
 {
     revisionDelta = new RevisionDelta <int?, UserType>(newRevisionId, oldRevisionId, oldTransaction, oldUser);
 }