Exemple #1
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));
        }
Exemple #2
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);
        }
Exemple #3
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));
                }
            }
        }
        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));
        }
        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));
        }
        private List <TChild> CheckForMatches(string text)
        {
            List <TChild> childObjs = new List <TChild>();

            if (ParentProperty != null)
            {
                List <TParent> parentObjs = ParentObjectMatcher.GetMatches(text);

                if (parentObjs != null && parentObjs.Count > 0)
                {
                    foreach (TParent parentObj in parentObjs)
                    {
                        object parentPropertyValue = ParentProperty.GetValue(parentObj, null);

                        if (ChildProperty != null)
                        {
                            List <TChild> childObjMatches = ChildObjectMatcher.GetMatches(text);

                            if (childObjMatches != null && childObjMatches.Count > 0)
                            {
                                foreach (TChild childObj in childObjMatches)
                                {
                                    ChildProperty.SetValue(childObj, parentPropertyValue, null);
                                    childObjs.Add(childObj);
                                }
                            }
                        }
                    }
                }
            }

            return(childObjs);
        }
        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);
        }
Exemple #8
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));
        }
        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);
        }
    private void SetValueImpl(object value)
    {
      //this.ValidateValue(value);
      if (ParentProperty.Validate(value))
        SetValueCore(value);

      NotifyValueChanged();
      OnRootValueChanged();
    }
Exemple #12
0
        public override object GetValue(object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
        {
            var parentObject = ParentProperty.GetValue(obj, invokeAttr, binder, index, culture);

            if (parentObject == null)
            {
                return(null);
            }
            return(Property.GetValue(parentObject, invokeAttr, binder, index, culture));
        }
Exemple #13
0
        public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
        {
            var parentObject = ParentProperty.GetValue(obj, invokeAttr, binder, index, culture);

            if (parentObject == null)
            {
                throw new ArgumentNullException("Could not set nested property value: Parent object was null");
            }
            Property.SetValue(ParentProperty.GetValue(obj, invokeAttr, binder, index, culture), value, invokeAttr, binder, index, culture);
        }
        private async void AddBtnClick(object sender, EventArgs e)
        {
            if (dgv.SelectedRows.Count != 0 && dgv.SelectedRows[0].DataBoundItem is Parent parent)
            {
                if (_validator.CheckAll() && prop_cmbx.SelectedItem is Property property)
                {
                    var item = new ParentProperty()
                    {
                        ParentId   = parent.ParentId,
                        PropertyId = property.PropertyId,
                        Value      = text_txbx.Text
                    };
                    if (parent.Properties.Any(x => x.PropertyId == property.PropertyId))
                    {
                        var chproperty = parent.Properties
                                         .FirstOrDefault(x => x.PropertyId == property.PropertyId &&
                                                         x.ParentId == parent.ParentId);
                        if (chproperty != null)
                        {
                            chproperty.Value    = text_txbx.Text;
                            chproperty.Property = null;
                            chproperty.Parent   = null;
                            await _dataService.UpdateEntityAsync(chproperty);
                        }

                        parent.Properties =
                            await _dataService.GetEntitiesAsync <ParentProperty>(x => x.ParentId == parent.ParentId);

                        propdgv.DataSource = parent.Properties;
                    }
                    else
                    {
                        await _dataService.AddEntityAsync(item);

                        parent.Properties =
                            await _dataService.GetEntitiesAsync <ParentProperty>(x => x.ParentId == parent.ParentId);

                        propdgv.DataSource = parent.Properties;
                    }

                    prop_cmbx.SelectedItem = null;
                    text_txbx.Text         = string.Empty;
                }
            }
            else
            {
                MessageBox.Show(@"Родитель не выбран!",
                                @"Ошибка",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
 /// <summary>
 /// Removes this design item from its parent property/collection.
 /// </summary>
 public void Remove()
 {
     if (ParentProperty != null)
     {
         if (ParentProperty.IsCollection)
         {
             ParentProperty.CollectionElements.Remove(this);
         }
         else
         {
             ParentProperty.Reset();
         }
     }
 }
Exemple #16
0
        /// <summary>
        /// Checks the text for matches
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        private List <TChild> CheckForMatches(string text)
        {
            // create a list of child objects
            List <TChild> childObjs = new List <TChild>();

            if (ParentProperty != null)
            {
                // get parent object matches
                List <TParent> parentObjs = ParentObjectMatcher.GetMatches(text);

                // if there were any parent matches, get child objects
                if (parentObjs != null && parentObjs.Count > 0)
                {
                    // for each parent, check for children
                    foreach (TParent parentObj in parentObjs)
                    {
                        // get the value of the parent linking property
                        object parentPropertyValue = ParentProperty.GetValue(parentObj, null);

                        // if the child property is set
                        if (ChildProperty != null)
                        {
                            // find child object matches
                            List <TChild> childObjMatches = ChildObjectMatcher.GetMatches(text);

                            // if any child matches were found, add them to the collection
                            if (childObjMatches != null && childObjMatches.Count > 0)
                            {
                                // for each child match, set the child's parent property and add to the collection
                                foreach (TChild childObj in childObjMatches)
                                {
                                    ChildProperty.SetValue(childObj, parentPropertyValue, null);
                                    childObjs.Add(childObj);
                                }
                            }
                        }
                    }
                }
            }

            return(childObjs);
        }
Exemple #17
0
        public IyTreeModel CreateModel(IList list)
        {
            var genericList = list.Cast <TNode>().Where(x => ParentProperty.GetValue(x, null) == null).ToList();

            return(new RecursiveTreeModel <TNode>(genericList, this));
        }
Exemple #18
0
 set => SetValue(ParentProperty, value);
        protected override void SetItem(TEntity?item, DateTime?moment)
        {
            LazyLoad();
            LazySet();

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

            List <CollectionItem <TEntity> > currentItem = InnerData.ToList();

            if (!currentItem.FirstOrDefault()?.Item?.Equals(item) ?? !ReferenceEquals(item, null))
            {
                if (ForeignProperty != null && ForeignProperty.PropertyType == PropertyType.Lookup)
                {
                    OGM?oldForeignValue = (item == null) ? null : (OGM)ForeignProperty.GetValue(item, moment);
                    if (oldForeignValue != null)
                    {
                        ParentProperty?.ClearLookup(oldForeignValue, null);
                    }

                    foreach (TEntity entity in currentItem.Select(iitem => iitem.Item).Distinct())
                    {
                        ForeignProperty.ClearLookup(entity, null);
                    }
                }

                if (item == null)
                {
                    if (currentItem.Count > 0)
                    {
                        if (ParentProperty?.PropertyType == PropertyType.Lookup)
                        {
                            Remove(currentItem[0].Item);
                        }

                        if (Count > 0)
                        {
                            Clear(false); // Clear should not be called here as this is for lookup.
                        }
                    }
                }
                else
                {
                    if (currentItem.Count == 1 && currentItem[0].Item.Equals(item))
                    {
                        return;
                    }

                    if (currentItem.Count > 0)
                    {
                        if (ParentProperty?.PropertyType == PropertyType.Lookup)
                        {
                            Remove(currentItem[0].Item);
                        }

                        if (Count > 0)
                        {
                            Clear(false); // Clear should not be called here as this is for lookup.
                        }
                    }

                    if (Count == 0)
                    {
                        Add(item, false);
                    }
                }
            }
        }
        protected override void SetItem(TEntity?item, DateTime?moment)
        {
            LazyLoad();
            LazySet();

            if (!moment.HasValue)
            {
                moment = RunningTransaction.TransactionDate;
            }

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

            List <CollectionItem <TEntity> > currentItem = InnerData.Where(e => e.Overlaps(moment, null)).ToList();

            if (!currentItem.FirstOrDefault()?.Item?.Equals(item) ?? !ReferenceEquals(item, null))
            {
                if (ForeignProperty != null && ForeignProperty.PropertyType == PropertyType.Lookup)
                {
                    OGM?oldForeignValue = (item is null) ? null : (OGM)ForeignProperty.GetValue(item, moment);
                    if (oldForeignValue != null)
                    {
                        ParentProperty?.ClearLookup(oldForeignValue, null);
                    }

                    foreach (TEntity entity in currentItem.Select(iitem => iitem.Item).Distinct())
                    {
                        ForeignProperty.ClearLookup(entity, moment);
                    }
                }

                if (item == null)
                {
                    if (ParentProperty?.PropertyType == PropertyType.Lookup)
                    {
                        Remove(currentItem[0].Item, moment);
                    }

                    if (currentItem.Count > 0)
                    {
                        Clear(moment, false);
                    }
                }
                else
                {
                    if (currentItem.Count == 1 && currentItem[0].Item.Equals(item))
                    {
                        return;
                    }

                    if (ParentProperty?.PropertyType == PropertyType.Lookup && currentItem.Count == 1)
                    {
                        Remove(currentItem[0].Item, moment);
                    }

                    if (currentItem.Count > 0)
                    {
                        Clear(moment, false);
                    }

                    if (CountAt(moment) == 0)
                    {
                        Add(item, moment, false);
                    }
                }
            }
        }
Exemple #21
0
 public override int GetHashCode()
 {
     unchecked
     {
         return(((ModelName != null ? ModelName.GetHashCode() : 0) * 397) ^ (ParentProperty != null ? ParentProperty.GetHashCode() : 0));
     }
 }
Exemple #22
0
        protected override void SetItem(TEntity?item, DateTime?moment)
        {
            if (ParentProperty?.PropertyType != PropertyType.Lookup)
            {
                throw new NotSupportedException("You cannot use SetItem on a property thats not a lookup.");
            }

            LazyLoad();
            LazySet();

            //if (!moment.HasValue)
            //	moment = RunningTransaction.TransactionDate;

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

            List <CollectionItem <TEntity> > currentItem = InnerData.Where(e => e.Overlaps(moment, null)).ToList();

            if (NeedsToAssign(currentItem, item, moment))
            {
                if (ForeignProperty is not null && ForeignProperty.PropertyType == PropertyType.Lookup)
                {
                    OGM?oldForeignValue = (item is null) ? null : (OGM)ForeignProperty.GetValue(item, moment);
                    if (oldForeignValue is not null)
                    {
                        ParentProperty?.ClearLookup(oldForeignValue, moment);
                    }

                    foreach (TEntity entity in currentItem.Select(iitem => iitem.Item).Distinct())
                    {
                        ForeignProperty.ClearLookup(entity, moment);
                    }
                }

                if (item is null)
                {
                    if (currentItem.Count > 0)
                    {
                        if (ParentProperty?.PropertyType == PropertyType.Lookup)
                        {
                            foreach (CollectionItem <TEntity> current in currentItem)
                            {
                                if (current?.Item is not null)
                                {
                                    Remove(current.Item, moment);
                                }
                            }
                        }

                        if (Count() > 0)
                        {
                            Clear(moment, false);                             // Clear should not be called here as this is for lookup.
                        }
                    }
                }
                else
                {
                    if (currentItem.Count > 0)
                    {
                        if (ParentProperty?.PropertyType == PropertyType.Lookup)
                        {
                            foreach (CollectionItem <TEntity> current in currentItem)
                            {
                                if (current?.Item is not null)
                                {
                                    Remove(current.Item, moment);
                                }
                            }
                        }

                        if (Count() > 0)
                        {
                            Clear(moment, false);                             // Clear should not be called here as this is for lookup.
                        }
                    }

                    if (Count() == 0)
                    {
                        Add(item, moment, false);
                    }
                }
            }