Exemplo n.º 1
0
        private IPersistThroughEvents GetParentOrThrow <TChildId, TParentId>(IParcelVisionEventEnvelope <TChildId, TParentId> eventEnvelope)
            where TParentId : IId
            where TChildId : IId
        {
            IPersistThroughEvents parent;
            var parentContainer = GetOrCreateContainer <TParentId>();

            //TODO (Savvas) replace with propper exception
            if (!parentContainer.TryGetValue(eventEnvelope.ParentId, out parent))
            {
                throw new Exception("Parent should exist already");
            }
            return(parent);
        }
Exemplo n.º 2
0
        private void GetOrCreateAndReconstituteEntity <TChildId, TParentId>(IParcelVisionEventEnvelope <TChildId, TParentId> eventEnvelope)
            where TParentId : IId, IEquatable <TParentId>
            where TChildId : IId, IEquatable <TChildId>
        {
            IPersistThroughEvents entity;

            var childContainer = GetOrCreateContainer <TChildId>();

            if (!childContainer.TryGetValue(eventEnvelope.SourceId, out entity))
            {
                entity = CreateAndSetupRelationships(eventEnvelope, entity);
                childContainer[eventEnvelope.SourceId] = entity;
            }

            entity.ReconstituteFrom(eventEnvelope.Event);
        }
Exemplo n.º 3
0
        private IPersistThroughEvents CreateAndSetupRelationships <TChildId, TParentId>(IParcelVisionEventEnvelope <TChildId, TParentId> eventEnvelope,
                                                                                        IPersistThroughEvents entity)
            where TParentId : IId, IEquatable <TParentId>
            where TChildId : IId, IEquatable <TChildId>
        {
            var parent = GetParentOrThrow(eventEnvelope);

            var newChildEntity = (IPersistThroughEvents)Activator.CreateInstance(eventEnvelope.SourceEntityType);
            var parentAsEntity = parent as Entity <TParentId>;

            var childAsHasParent = newChildEntity as IHaveAParent;

            if (childAsHasParent != null)
            {
                SetParentInChild(parentAsEntity, childAsHasParent);
            }

            entity = newChildEntity;
            return(entity);
        }
Exemplo n.º 4
0
 private void ReconstituteFrom(IParcelVisionEventEnvelope eventEnvelope)
 {
     ((IPersistThroughEvents)this).ReconstituteFrom(eventEnvelope.Event);
 }