internal void Replay(Core.EntityCollectionBase collection) { foreach (RelationshipAction action in actions) { action.ExecuteInMemory(collection); } }
protected override void InMemoryLogic(EntityCollectionBase target) { bool wasUpdated = false; int[] indexes = target.IndexOf(target.ForeignItem(this) !); foreach (int index in indexes) { CollectionItem?item = target.GetItem(index); if (item is not null) { if (item.IsAfter(Moment)) { target.RemoveAt(index); } else if (item.OverlapsOrIsAttached(Moment)) { target.SetItem(index, target.NewCollectionItem(target.Parent, item.Item, item.StartDate, null)); wasUpdated = true; } } } if (!wasUpdated) { target.Add(target.NewCollectionItem(target.Parent, target.ForeignItem(this) !, Moment, null)); } }
protected override void InMemoryLogic(EntityCollectionBase target) { DateTime minStartDate = Moment; DateTime maxEndDate = EndDate; int[] indexes = target.IndexOf(target.ForeignItem(this) !); foreach (int index in indexes) { CollectionItem?item = target.GetItem(index); if (item is not null) { if (item.Overlaps(Moment)) { if (minStartDate > item.StartDate) { minStartDate = item.StartDate; } if (maxEndDate < item.EndDate) { maxEndDate = item.EndDate; } target.RemoveAt(index); } } } target.Add(target.NewCollectionItem(target.Parent, target.ForeignItem(this) !, minStartDate, maxEndDate)); }
protected override void InMemoryLogic(EntityCollectionBase target) { DateTime minStartDate = Moment; DateTime maxEndDate = EndDate; target.ForEach(delegate(int index, CollectionItem item) { if (item.Item.Equals(target.ForeignItem(this))) { if (item.Overlaps(Moment)) { if (minStartDate > item.StartDate) { minStartDate = item.StartDate ?? DateTime.MinValue; } if (maxEndDate < item.EndDate) { maxEndDate = item.EndDate ?? DateTime.MaxValue; } target.RemoveAt(index); } } }); target.Add(target.NewCollectionItem(target.Parent, target.ForeignItem(this), minStartDate, maxEndDate)); }
protected override void InMemoryLogic(EntityCollectionBase target) { OGM?foreignItem = target.ForeignItem(this); if (foreignItem is null) { target.ForEach((index, item) => { if (item is not null) { target.RemoveAt(index); } }); } else { int[] indexes = target.IndexOf(foreignItem); foreach (int index in indexes) { CollectionItem?item = target.GetItem(index); if (item is not null) { target.RemoveAt(index); } } } }
internal void LoadAll(Core.EntityCollectionBase collection) { if (collection == null) { return; } string relationshipName = collection.Relationship.Name; Dictionary <string, HashSet <Core.EntityCollectionBase> >?properties; if (!registeredCollections.TryGetValue(relationshipName, out properties)) { properties = new Dictionary <string, HashSet <Core.EntityCollectionBase> >(); registeredCollections.Add(relationshipName, properties); } string propertyName = string.Concat(collection.Parent.GetEntity().Name, ".", collection.ParentProperty?.Name ?? "NonExisting"); HashSet <Core.EntityCollectionBase>?values; if (!properties.TryGetValue(propertyName, out values)) { return; } List <Core.EntityCollectionBase> collections = values.Where(item => !item.IsLoaded).ToList(); const int chunkSize = 10000; int initialSize = Math.Min(chunkSize, collections.Count); foreach (var chunk in collections.Chunks(chunkSize)) { List <OGM> parents = new List <OGM>(initialSize); foreach (Core.EntityCollectionBase item in chunk) { if (item.Parent.PersistenceState != PersistenceState.New && item.Parent.PersistenceState != PersistenceState.NewAndChanged) { parents.Add(item.Parent); } } Dictionary <OGM, CollectionItemList> allItems = RelationshipPersistenceProvider.Load(parents, collection); foreach (Core.EntityCollectionBase item in chunk) { CollectionItemList?items = null; if (allItems.TryGetValue(item.Parent, out items)) { item.InitialLoad(items.Items); } else { item.InitialLoad(new List <CollectionItem>()); } } } }
protected override void InMemoryLogic(EntityCollectionBase target) { bool contains = target.IndexOf(target.ForeignItem(this) !).Length != 0; if (!contains) { target.Add(target.NewCollectionItem(target.Parent, target.ForeignItem(this) !, null, null)); } }
protected override void InMemoryLogic(EntityCollectionBase target) { target.ForEach(delegate(int index, CollectionItem item) { if (item.Item.Equals(target.ForeignItem(this))) { target.RemoveAt(index); } }); }
protected override void InMemoryLogic(EntityCollectionBase target) { int[] indexes = target.IndexOf(target.ForeignItem(this) !); foreach (int index in indexes) { CollectionItem?item = target.GetItem(index); if (item is not null) { if (item.StartDate == Moment) { target.RemoveAt(index); } } } }
protected override void InMemoryLogic(EntityCollectionBase target) { bool contains = false; target.ForEach(delegate(int index, CollectionItem item) { if (item.Item.Equals(target.ForeignItem(this))) { contains = true; } }); if (!contains) { target.Add(target.NewCollectionItem(target.Parent, target.ForeignItem(this), null, null)); } }
protected override void InMemoryLogic(EntityCollectionBase target) { target.ForEach(delegate(int index, CollectionItem item) { if (item.Item.Equals(target.ForeignItem(this))) { if (item.IsAfter(Moment)) { target.RemoveAt(index); } else if (item.Overlaps(Moment)) { target.SetItem(index, target.NewCollectionItem(target.Parent, item.Item, item.StartDate, Moment)); } } }); }
private protected void ExecuteAction(ClearRelationshipsAction action) { if (DbTransaction != null) { DbTransaction?.Register(action); } else { foreach (Property property in GetEntity().Properties.Where(item => item.PropertyType != PropertyType.Attribute)) { if (property.ForeignProperty == null) { continue; } IEnumerable <OGM> instances; object value = property.GetValue(this, null); if (property.PropertyType == PropertyType.Lookup) { instances = new OGM[] { (OGM)value } } ; else { instances = (IEnumerable <OGM>)value; } foreach (OGM instance in instances) { if (property.ForeignProperty.PropertyType == PropertyType.Lookup) { property.ForeignProperty.SetValue(instance, null); } else { EntityCollectionBase collection = (EntityCollectionBase)property.ForeignProperty.GetValue(instance, null); action.ExecuteInMemory(collection); } } property.SetValue(this, null); } } }
protected override void InMemoryLogic(EntityCollectionBase target) { OGM?foreignItem = target.ForeignItem(this); if (foreignItem is null) { target.ForEach((index, item) => { if (item is not null) { if (item.IsAfter(Moment)) { target.RemoveAt(index); } else if (item.Overlaps(Moment)) { target.SetItem(index, target.NewCollectionItem(target.Parent, item.Item, item.StartDate, Moment)); } } }); } else { int[] indexes = target.IndexOf(foreignItem); foreach (int index in indexes) { CollectionItem?item = target.GetItem(index); if (item is not null) { if (item.IsAfter(Moment)) { target.RemoveAt(index); } else if (item.Overlaps(Moment)) { target.SetItem(index, target.NewCollectionItem(target.Parent, item.Item, item.StartDate, Moment)); } } } } }
internal void Register(Core.EntityCollectionBase item) { if (item == null) { return; } item.DbTransaction = this; string relationshipName = item.Relationship.Name; Dictionary <string, HashSet <Core.EntityCollectionBase> >?properties; if (!registeredCollections.TryGetValue(relationshipName, out properties)) { properties = new Dictionary <string, HashSet <Core.EntityCollectionBase> >(); registeredCollections.Add(relationshipName, properties); } string propertyName = string.Concat(item.Parent.GetEntity().Name, ".", item.ParentProperty?.Name ?? "NonExisting"); HashSet <Core.EntityCollectionBase>?values; if (!properties.TryGetValue(propertyName, out values)) { values = new HashSet <Core.EntityCollectionBase>(); values.SetCapacity(1000); properties.Add(propertyName, values); } if (values.Contains(item)) { throw new InvalidOperationException("You cannot register an already loaded collection."); } values.Add(item); }
protected override void InMemoryLogic(EntityCollectionBase target) { target.ForEach(delegate(int index, CollectionItem item) { if (target.Direction == DirectionEnum.Out) { if ((OutItem is not null && item.Parent.Equals(OutItem)) || (InItem is not null && item.Item.Equals(InItem))) { Remove(); } } else if (target.Direction == DirectionEnum.In) { if ((InItem is not null && item.Parent.Equals(InItem)) || (OutItem is not null && item.Item.Equals(OutItem))) { Remove(); } } else { throw new NotSupportedException("Please contact developer."); } void Remove() { if (item.IsAfter(Moment)) { target.RemoveAt(index); } else if (item.Overlaps(Moment)) { target.SetItem(index, target.NewCollectionItem(target.Parent, item.Item, item.StartDate, Moment)); } } }); }
protected override void InMemoryLogic(EntityCollectionBase target) { target.ForEach(delegate(int index, CollectionItem item) { if (target.Direction == DirectionEnum.Out) { if ((OutItem is not null && item.Parent.Equals(OutItem)) || (InItem is not null && item.Item.Equals(InItem))) { target.RemoveAt(index); } } else if (target.Direction == DirectionEnum.In) { if ((InItem is not null && item.Parent.Equals(InItem)) || (OutItem is not null && item.Item.Equals(OutItem))) { target.RemoveAt(index); } } else { throw new NotSupportedException("Please contact developer."); } }); }
public abstract IEnumerable <CollectionItem> Load(OGM parent, EntityCollectionBase target);