コード例 #1
0
        public override void RemoveObject(IDataObject objectToRemove)
        {
            if (GOUserGroupObjects == null)
            {
                return;
            }
            bool completed;
            int? objectToRemoveInternalId;

            if ((objectToRemove as GOUserGroupDataObject) == null)
            {
                _logEngine.LogError("Unable to remove null object", "The object you are trying to remove is null", "GOUserGroupObjectsDataSet.RemoveObject", null);
                throw new PulpException("Unable to remove Null Object.");
            }

            if (objectToRemove.IsNew)
            {
                objectToRemoveInternalId = objectToRemove.InternalObjectId;
            }
            else
            {
                objectToRemoveInternalId = GOUserGroupObjectInternalIds.ContainsKey((objectToRemove as GOUserGroupDataObject).PrimaryKeysCollection) ? (int?)GOUserGroupObjectInternalIds[(objectToRemove as GOUserGroupDataObject).PrimaryKeysCollection] : null;
            }

            if (objectToRemoveInternalId != null)
            {
                GOUserGroupDataObject value;
                completed = false;
                var count = 0;
                while (!completed && count++ < 15)
                {
                    completed = GOUserGroupObjects.TryRemove((int)objectToRemoveInternalId, out value);
                }

                // Reinit InternalObjectId only if the object to remove is part of the current dataset
                if (ReferenceEquals(objectToRemove.ObjectsDataSet, this._rootObjectDataSet))
                {
                    objectToRemove.InternalObjectId = null;
                }

                if (!objectToRemove.IsNew)
                {
                    int idvalue;
                    completed = false;
                    count     = 0;
                    while (!completed && count++ < 15)
                    {
                        completed = GOUserGroupObjectInternalIds.TryRemove((objectToRemove as GOUserGroupDataObject).PrimaryKeysCollection, out idvalue);
                    }
                }

                // Delete the Group FK Index
                if ((objectToRemove as GOUserGroupDataObject).GOGroupName != null)
                {
                    if (Group_FKIndex.ContainsKey((objectToRemove as GOUserGroupDataObject).GOGroupName) && Group_FKIndex[(objectToRemove as GOUserGroupDataObject).GOGroupName].Contains((int)objectToRemoveInternalId))
                    {
                        Group_FKIndex[(objectToRemove as GOUserGroupDataObject).GOGroupName].Remove((int)objectToRemoveInternalId);

                        if (!Group_FKIndex[(objectToRemove as GOUserGroupDataObject).GOGroupName].Any())
                        {
                            List <int> outvalue;
                            var        iscompleted = false;
                            var        count2      = 0;
                            while (!iscompleted && count2++ < 15)
                            {
                                iscompleted = Group_FKIndex.TryRemove((objectToRemove as GOUserGroupDataObject).GOGroupName, out outvalue);
                            }
                        }
                    }

                    GOGroupDataObject relatedGroup;
                    if ((objectToRemove as GOUserGroupDataObject)._group_NewObjectId != null)
                    {
                        relatedGroup = _rootObjectDataSet.GetObject(new GOGroupDataObject()
                        {
                            IsNew = true, InternalObjectId = (objectToRemove as GOUserGroupDataObject)._group_NewObjectId
                        });
                    }
                    else
                    {
                        relatedGroup = _rootObjectDataSet.GetObject(new GOGroupDataObject((objectToRemove as GOUserGroupDataObject).GOGroupName)
                        {
                            IsNew = false
                        });
                    }

                    if (relatedGroup != null && this.RootObjectDataSet.NotifyChanges)
                    {
                        relatedGroup.NotifyPropertyChanged("UserGroupItems", new SeenObjectCollection());
                    }
                }

                // Delete the User FK Index
                if (User_FKIndex.ContainsKey((objectToRemove as GOUserGroupDataObject).GOUserId) && User_FKIndex[(objectToRemove as GOUserGroupDataObject).GOUserId].Contains((int)objectToRemoveInternalId))
                {
                    User_FKIndex[(objectToRemove as GOUserGroupDataObject).GOUserId].Remove((int)objectToRemoveInternalId);

                    if (!User_FKIndex[(objectToRemove as GOUserGroupDataObject).GOUserId].Any())
                    {
                        List <int> outvalue;
                        var        iscompleted = false;
                        var        count2      = 0;
                        while (!iscompleted && count2++ < 15)
                        {
                            iscompleted = User_FKIndex.TryRemove((objectToRemove as GOUserGroupDataObject).GOUserId, out outvalue);
                        }
                    }
                }

                GOUserDataObject relatedUser;
                if ((objectToRemove as GOUserGroupDataObject)._user_NewObjectId != null)
                {
                    relatedUser = _rootObjectDataSet.GetObject(new GOUserDataObject()
                    {
                        IsNew = true, InternalObjectId = (objectToRemove as GOUserGroupDataObject)._user_NewObjectId
                    });
                }
                else
                {
                    relatedUser = _rootObjectDataSet.GetObject(new GOUserDataObject((objectToRemove as GOUserGroupDataObject).GOUserId)
                    {
                        IsNew = false
                    });
                }

                if (relatedUser != null && this.RootObjectDataSet.NotifyChanges)
                {
                    relatedUser.NotifyPropertyChanged("UserGroupItems", new SeenObjectCollection());
                }
            }
        }
コード例 #2
0
        public override void AddObject(IDataObject objectToAdd, bool replaceIfExists)
        {
            var existingObject = GetObject(objectToAdd);

            if (!replaceIfExists && existingObject != null)
            {
                throw new PulpException("Object already exists");
            }

            int newInternalId;

            if (existingObject != null)
            {
                //RemoveObject(existingObject);
                if (existingObject.InternalObjectId == null)
                {
                    _logEngine.LogError("Error while trying to Add Object to the GOUserGroupObjectsDataSet", "The object you are trying to add doesn't have an InternalObjectId", "GOUserGroupObjectsDataSet", null);
                    throw new PulpException("Error while trying to add an object to the dataset without InternalObjectId");
                }
                newInternalId = (int)existingObject.InternalObjectId;
                objectToAdd.InternalObjectId = newInternalId;
                existingObject.CopyValuesFrom(objectToAdd, false);
            }
            else
            {
                newInternalId = GetNextNewInternalObjectId();
                objectToAdd.InternalObjectId = newInternalId;

                var completed = false;
                var count     = 0;
                while (!completed && count++ < 15)
                {
                    completed = GOUserGroupObjects.TryAdd(newInternalId, (GOUserGroupDataObject)objectToAdd);
                }
            }

            if (!objectToAdd.IsNew && existingObject == null)
            {
                //The following if should not be necessary...
                var completed = false;
                if (GOUserGroupObjectInternalIds.ContainsKey(((GOUserGroupDataObject)objectToAdd).PrimaryKeysCollection))
                {
                    int value;
                    var count2 = 0;
                    while (!completed && count2++ < 15)
                    {
                        completed = GOUserGroupObjectInternalIds.TryRemove(((GOUserGroupDataObject)objectToAdd).PrimaryKeysCollection, out value);
                    }
                }

                completed = false;
                var count = 0;
                while (!completed && count++ < 15)
                {
                    completed = GOUserGroupObjectInternalIds.TryAdd(((GOUserGroupDataObject)objectToAdd).PrimaryKeysCollection, newInternalId);
                }
            }
            // Update relations including platform as "many" side or "one" side , pk side for one to one relations
            if ((objectToAdd as GOUserGroupDataObject) == null)
            {
                _logEngine.LogError("Unable to Add an object which is null", "Unable to add an object which is null", "GOUserGroupDataObject", null);
                throw new PulpException("Unexpected Error: Unable to Add an object which is Null.");
            }

            // Update the Group FK Index
            if ((objectToAdd as GOUserGroupDataObject).GOGroupName != null)
            {
                if (!Group_FKIndex.ContainsKey((objectToAdd as GOUserGroupDataObject).GOGroupName))
                {
                    var iscompleted = false;
                    var count2      = 0;
                    while (!iscompleted && count2++ < 15)
                    {
                        iscompleted = Group_FKIndex.TryAdd((objectToAdd as GOUserGroupDataObject).GOGroupName, new List <int>());
                    }
                }

                if (!Group_FKIndex[(objectToAdd as GOUserGroupDataObject).GOGroupName].Contains(newInternalId))
                {
                    Group_FKIndex[(objectToAdd as GOUserGroupDataObject).GOGroupName].Add(newInternalId);
                }

                GOGroupDataObject relatedGroup;
                if ((objectToAdd as GOUserGroupDataObject)._group_NewObjectId != null)
                {
                    relatedGroup = _rootObjectDataSet.GetObject(new GOGroupDataObject()
                    {
                        IsNew = true, InternalObjectId = (objectToAdd as GOUserGroupDataObject)._group_NewObjectId
                    });
                }
                else
                {
                    relatedGroup = _rootObjectDataSet.GetObject(new GOGroupDataObject((objectToAdd as GOUserGroupDataObject).GOGroupName)
                    {
                        IsNew = false
                    });
                }

                if (relatedGroup != null && this.RootObjectDataSet.NotifyChanges)
                {
                    relatedGroup.NotifyPropertyChanged("UserGroupItems", new SeenObjectCollection());
                }
            }

            // Update the User FK Index
            if (!User_FKIndex.ContainsKey((objectToAdd as GOUserGroupDataObject).GOUserId))
            {
                var iscompleted = false;
                var count2      = 0;
                while (!iscompleted && count2++ < 15)
                {
                    iscompleted = User_FKIndex.TryAdd((objectToAdd as GOUserGroupDataObject).GOUserId, new List <int>());
                }
            }

            if (!User_FKIndex[(objectToAdd as GOUserGroupDataObject).GOUserId].Contains(newInternalId))
            {
                User_FKIndex[(objectToAdd as GOUserGroupDataObject).GOUserId].Add(newInternalId);
            }

            GOUserDataObject relatedUser;

            if ((objectToAdd as GOUserGroupDataObject)._user_NewObjectId != null)
            {
                relatedUser = _rootObjectDataSet.GetObject(new GOUserDataObject()
                {
                    IsNew = true, InternalObjectId = (objectToAdd as GOUserGroupDataObject)._user_NewObjectId
                });
            }
            else
            {
                relatedUser = _rootObjectDataSet.GetObject(new GOUserDataObject((objectToAdd as GOUserGroupDataObject).GOUserId)
                {
                    IsNew = false
                });
            }

            if (relatedUser != null && this.RootObjectDataSet.NotifyChanges)
            {
                relatedUser.NotifyPropertyChanged("UserGroupItems", new SeenObjectCollection());
            }
        }