예제 #1
0
        public override void RemoveObject(IDataObject objectToRemove)
        {
            if (GOGroupObjects == null)
            {
                return;
            }
            bool completed;
            int? objectToRemoveInternalId;

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

            if (objectToRemove.IsNew)
            {
                objectToRemoveInternalId = objectToRemove.InternalObjectId;
            }
            else
            {
                objectToRemoveInternalId = GOGroupObjectInternalIds.ContainsKey((objectToRemove as GOGroupDataObject).PrimaryKey) ? (int?)GOGroupObjectInternalIds[(objectToRemove as GOGroupDataObject).PrimaryKey] : null;
            }

            if (objectToRemoveInternalId != null)
            {
                GOGroupDataObject value;
                completed = false;
                var count = 0;
                while (!completed && count++ < 15)
                {
                    completed = GOGroupObjects.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 = GOGroupObjectInternalIds.TryRemove((objectToRemove as GOGroupDataObject).PrimaryKey, out idvalue);
                    }
                }
            }
        }
예제 #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 GOGroupObjectsDataSet", "The object you are trying to add doesn't have an InternalObjectId", "GOGroupObjectsDataSet", 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 = GOGroupObjects.TryAdd(newInternalId, (GOGroupDataObject)objectToAdd);
                }
            }

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

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