internal void AddRange(IEnumerable <TEntity> items, DateTime?moment, bool fireEvents)
        {
            LazyLoad();
            LazySet();

            LinkedList <RelationshipAction> actions = new LinkedList <RelationshipAction>();

            foreach (var item in items)
            {
                if (item is null)
                {
                    continue;
                }

                if (EagerLoadLogic != null)
                {
                    EagerLoadLogic.Invoke(item);
                }

                if (fireEvents)
                {
                    if (ParentProperty?.RaiseOnChange((OGMImpl)Parent, default(TEntity), item, moment, OperationEnum.Add) ?? false)
                    {
                        continue;
                    }
                }

                CollectionItem <TEntity> oldItem = InnerData.FirstOrDefault(item => item.Item.GetKey() == item.Item.GetKey());
                actions.AddLast(AddAction(item, (oldItem != null) ? oldItem.StartDate : moment));
            }

            ExecuteAction(actions);
        }
        internal void Add(TEntity item, DateTime?moment, bool fireEvents)
        {
            if (item is null)
            {
                return;
            }

            LazyLoad();
            LazySet();

            if (EagerLoadLogic != null)
            {
                EagerLoadLogic.Invoke(item);
            }

            if (fireEvents)
            {
                if (ParentProperty?.RaiseOnChange((OGMImpl)Parent, default(TEntity), item, moment, OperationEnum.Add) ?? false)
                {
                    return;
                }
            }

            CollectionItem <TEntity> oldItem = InnerData.FirstOrDefault(item => item.Item.GetKey() == item.Item.GetKey());

            ExecuteAction(AddAction(item, (oldItem != null) ? oldItem.StartDate : moment));
        }
Пример #3
0
        internal void Add(TEntity item, DateTime?moment, bool fireEvents)
        {
            if (item is null)
            {
                return;
            }

            LazyLoad();
            LazySet();

            if (EagerLoadLogic is not null)
            {
                EagerLoadLogic.Invoke(item);
            }

            if (fireEvents)
            {
                if (ParentProperty?.RaiseOnChange((OGMImpl)Parent, default(TEntity), item, moment, OperationEnum.Add) ?? false)
                {
                    return;
                }
            }

            ExecuteAction(AddAction(item, moment));
        }
Пример #4
0
        internal void Remove(TEntity item, DateTime?moment, bool fireEvents)
        {
            if (ForeignProperty is not null && ForeignProperty.PropertyType == PropertyType.Lookup && !ForeignProperty.Nullable)
            {
                throw new PersistenceException(string.Format("Due to a nullability constraint, you cannot delete {0} relationships directly. Consider removing the {1} objects instead.", ParentProperty?.Relationship?.Neo4JRelationshipType, ForeignEntity.Name));
            }

            if (item is null)
            {
                return;
            }

            LazyLoad();

            if (EagerLoadLogic is not null)
            {
                EagerLoadLogic.Invoke(item);
            }

            if (fireEvents)
            {
                if (ParentProperty?.RaiseOnChange <OGM>((OGMImpl)Parent, item, default(TEntity), moment, OperationEnum.Remove) ?? false)
                {
                    return;
                }
            }

            ExecuteAction(RemoveAction(item, moment));
        }
Пример #5
0
        internal void RemoveRange(IEnumerable <TEntity> items, DateTime?moment, bool fireEvents)
        {
            if (ForeignProperty is not null && ForeignProperty.PropertyType == PropertyType.Lookup && !ForeignProperty.Nullable)
            {
                throw new PersistenceException(string.Format("Due to a nullability constraint, you cannot delete {0} relationships directly. Consider removing the {1} objects instead.", ParentProperty?.Relationship?.Neo4JRelationshipType, ForeignEntity.Name));
            }

            LazySet();

            foreach (TEntity?item in items)
            {
                if (item is null)
                {
                    continue;
                }

                if (fireEvents)
                {
                    if (!(ParentProperty?.RaiseOnChange <OGM>((OGMImpl)Parent, item, default(TEntity), moment, OperationEnum.Remove) ?? false))
                    {
                        ExecuteAction(RemoveAction(item, moment));
                    }
                }
                else
                {
                    ExecuteAction(RemoveAction(item, moment));
                }
            }
        }
Пример #6
0
        internal void AddRange(IEnumerable <TEntity> items, DateTime?moment, bool fireEvents)
        {
            LazyLoad();
            LazySet();

            LinkedList <RelationshipAction> actions = new LinkedList <RelationshipAction>();

            foreach (var item in items)
            {
                if (item is null)
                {
                    continue;
                }

                if (EagerLoadLogic is not null)
                {
                    EagerLoadLogic.Invoke(item);
                }

                if (fireEvents)
                {
                    if (ParentProperty?.RaiseOnChange((OGMImpl)Parent, default(TEntity), item, moment, OperationEnum.Add) ?? false)
                    {
                        continue;
                    }
                }

                actions.AddLast(AddAction(item, moment));
            }

            ExecuteAction(actions);
        }
Пример #7
0
        internal sealed override void Add(TEntity item, bool fireEvents)
        {
            if (item is null)
            {
                return;
            }

            LazyLoad();
            LazySet();

            if (EagerLoadLogic != null)
            {
                EagerLoadLogic.Invoke(item);
            }

            if (fireEvents)
            {
                if (ParentProperty?.RaiseOnChange((OGMImpl)Parent, default(TEntity), item, null, OperationEnum.Add) ?? false)
                {
                    return;
                }
            }

            ExecuteAction(AddAction(item, null));
        }
        internal void Clear(DateTime?moment, bool fireEvents)
        {
            if (ForeignProperty != null && ForeignProperty.PropertyType == PropertyType.Lookup && !ForeignProperty.Nullable)
            {
                throw new PersistenceException(string.Format("Due to a nullability constraint, you cannot delete {0} relationships directly. Consider removing the {1} objects instead.", ParentProperty?.Relationship?.Neo4JRelationshipType, ForeignEntity.Name));
            }

            LazyLoad();

            if (InnerData.Count == 0)
            {
                return;
            }

            LazySet();

            if (fireEvents)
            {
                HashSet <CollectionItem> cancel = new HashSet <CollectionItem>();
                ForEach(delegate(int index, CollectionItem item)
                {
                    if (item is null)
                    {
                        return;
                    }

                    if (EagerLoadLogic != null)
                    {
                        EagerLoadLogic.Invoke((TEntity)item.Item);
                    }

                    if (ParentProperty?.RaiseOnChange((OGMImpl)Parent, item.Item, default(TEntity), moment, (OperationEnum)OperationEnum.Remove) ?? false)
                    {
                        cancel.Add((CollectionItem)item);
                    }
                });

                if (cancel.Count != 0)
                {
                    LinkedList <RelationshipAction> actions = new LinkedList <RelationshipAction>();

                    ForEach(delegate(int index, CollectionItem item)
                    {
                        if (cancel.Contains(item))
                        {
                            return;
                        }

                        actions.AddLast(RemoveAction(item, moment));
                    });

                    ExecuteAction(actions);

                    return;
                }
            }

            ExecuteAction(ClearAction(moment));
        }
        internal bool RemoveRange(IEnumerable <TEntity> items, DateTime?moment, bool fireEvents)
        {
            if (ForeignProperty != null && ForeignProperty.PropertyType == PropertyType.Lookup && !ForeignProperty.Nullable)
            {
                throw new PersistenceException(string.Format("Due to a nullability constraint, you cannot delete {0} relationships directly. Consider removing the {1} objects instead.", ParentProperty?.Relationship?.Neo4JRelationshipType, ForeignEntity.Name));
            }

            LazyLoad();

            LinkedList <RelationshipAction> actions = new LinkedList <RelationshipAction>();

            foreach (var item in items)
            {
                if (item != null && EagerLoadLogic != null)
                {
                    EagerLoadLogic.Invoke(item);
                }

                if (fireEvents)
                {
                    bool cancel = false;
                    ForEach(delegate(int index, CollectionItem current)
                    {
                        if (current.Item.Equals(item) && (!moment.HasValue || current.EndDate > moment.Value))
                        {
                            if (current.Item.Equals(item))
                            {
                                if (ParentProperty?.RaiseOnChange <OGM>((OGMImpl)Parent, current.Item, default(TEntity), moment, OperationEnum.Remove) ?? false)
                                {
                                    cancel = true;
                                }
                            }
                        }
                    });
                    if (cancel)
                    {
                        return(false);
                    }
                }

                ForEach(delegate(int index, CollectionItem current)
                {
                    if (current.Item.Equals(item) && (!moment.HasValue || current.EndDate > moment.Value))
                    {
                        ParentProperty?.RaiseOnChange <OGM>((OGMImpl)Parent, current.Item, default(TEntity), moment, OperationEnum.Remove);
                        actions.AddLast(RemoveAction(current, moment));
                    }
                });
            }

            if (actions.Count > 0)
            {
                ExecuteAction(actions);
                LazySet();
            }
            return(actions.Count > 0);
        }