Exemplo n.º 1
0
        public IEnumerable <TSnapshot> GetSnapshotsByParent(string parentType, string parentId)
        {
            ParentKey parentKey = new ParentKey(parentType, parentId);

            List <TSnapshot> childSnapshot = null;

            if (_parentMap.TryGetValue(parentKey, out childSnapshot))
            {
                foreach (var snapshot in childSnapshot)
                {
                    yield return(SerializeRoundTripSnapshot(snapshot));
                }
            }
        }
Exemplo n.º 2
0
        public IEnumerable <EntityReference> GetSnapshotReferencesByParent(string parentType, string parentId)
        {
            ParentKey parentKey = new ParentKey(parentType, parentId);

            List <TSnapshot> childSnapshot = null;

            if (_parentMap.TryGetValue(parentKey, out childSnapshot))
            {
                foreach (var snapshot in childSnapshot)
                {
                    yield return(new EntityReference(EntityTypeLookups.GetEntityType(typeof(TSnapshot)).Name, snapshot.EntityID));
                }
            }
        }
Exemplo n.º 3
0
        private void RemoveCurrentSnapshot(TSnapshot snapshot)
        {
            var currentSnapshot = FindCurrentSnapshot(snapshot);

            if (currentSnapshot == null)
            {
                return;
            }

            if (currentSnapshot.Parent?.EntityID != null)
            {
                ParentKey        parentKey = new ParentKey(currentSnapshot.Parent.EntityType, currentSnapshot.Parent.EntityID);
                List <TSnapshot> childList = null;
                if (_parentMap.TryGetValue(parentKey, out childList))
                {
                    childList.Remove(currentSnapshot);
                }
            }

            _identityMap.Remove(snapshot.EntityID);
        }
Exemplo n.º 4
0
        public void StoreSnapshot(TSnapshot snapshot)
        {
            snapshot = SerializeRoundTripSnapshot(snapshot);
            RemoveCurrentSnapshot(snapshot);

            _identityMap.Add(snapshot.EntityID, snapshot);

            if (snapshot.Parent?.EntityID != null)
            {
                ParentKey        parentKey = new ParentKey(snapshot.Parent.EntityType, snapshot.Parent.EntityID);
                List <TSnapshot> childList = null;
                if (_parentMap.TryGetValue(parentKey, out childList))
                {
                    childList.Add(snapshot);
                }
                else
                {
                    childList = new List <TSnapshot>();
                    childList.Add(snapshot);
                    _parentMap.Add(parentKey, childList);
                }
            }
        }