public override TDataObject GetObject<TDataObject>(TDataObject objectToGet) { int? objectToGetInternalId; if (objectToGet.IsNew) objectToGetInternalId = objectToGet.InternalObjectId; else { if((objectToGet as VisitedPlaceDataObject) == null) { _logEngine.LogError("Unable to get value which value is null", "The object you are trying to get doesn't have a value", "VisitedPlaceObjectsDataSet", null); throw new PulpException("Unable to get an element which value is null."); } objectToGetInternalId = VisitedPlaceObjectInternalIds.ContainsKey((objectToGet as VisitedPlaceDataObject).PrimaryKey) ? (int?) VisitedPlaceObjectInternalIds[(objectToGet as VisitedPlaceDataObject).PrimaryKey] : null; } if (objectToGetInternalId != null) { return VisitedPlaceObjects.ContainsKey((int)objectToGetInternalId) ? VisitedPlaceObjects[(int)objectToGetInternalId] as TDataObject : null; } return null; }
public override void RemoveObject(IDataObject objectToRemove) { if (VisitedPlaceObjects == null) return; bool completed; int? objectToRemoveInternalId; if((objectToRemove as VisitedPlaceDataObject) == null) { _logEngine.LogError("Unable to remove null object", "The object you are trying to remove is null", "VisitedPlaceObjectsDataSet.RemoveObject", null); throw new PulpException("Unable to remove Null Object."); } if (objectToRemove.IsNew) objectToRemoveInternalId = objectToRemove.InternalObjectId; else objectToRemoveInternalId = VisitedPlaceObjectInternalIds.ContainsKey((objectToRemove as VisitedPlaceDataObject).PrimaryKey) ? (int?) VisitedPlaceObjectInternalIds[(objectToRemove as VisitedPlaceDataObject).PrimaryKey] : null; if (objectToRemoveInternalId != null) { VisitedPlaceDataObject value; completed = false; var count = 0; while (!completed && count++ < 15) { completed = VisitedPlaceObjects.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 = VisitedPlaceObjectInternalIds.TryRemove((objectToRemove as VisitedPlaceDataObject).PrimaryKey, out idvalue); } } // Delete the Country FK Index if ((objectToRemove as VisitedPlaceDataObject).CountryURI != null) { if (Country_FKIndex.ContainsKey((System.String)(objectToRemove as VisitedPlaceDataObject).CountryURI) && Country_FKIndex[(System.String)(objectToRemove as VisitedPlaceDataObject).CountryURI].Contains((int)objectToRemoveInternalId)) { Country_FKIndex[(System.String)(objectToRemove as VisitedPlaceDataObject).CountryURI].Remove((int)objectToRemoveInternalId); if (!Country_FKIndex[(System.String)(objectToRemove as VisitedPlaceDataObject).CountryURI].Any()) { List<int> outvalue; var iscompleted = false; var count2 = 0; while (!iscompleted && count2++ < 15) { iscompleted = Country_FKIndex.TryRemove((System.String)(objectToRemove as VisitedPlaceDataObject).CountryURI, out outvalue); } } } CountryDataObject relatedCountry; if ((objectToRemove as VisitedPlaceDataObject)._country_NewObjectId != null) { relatedCountry = _rootObjectDataSet.GetObject(new CountryDataObject() { IsNew = true, InternalObjectId = (objectToRemove as VisitedPlaceDataObject)._country_NewObjectId }); } else { relatedCountry = _rootObjectDataSet.GetObject(new CountryDataObject((System.String)(objectToRemove as VisitedPlaceDataObject).CountryURI) { IsNew = false }); } if (relatedCountry != null && this.RootObjectDataSet.NotifyChanges) relatedCountry.NotifyPropertyChanged("VisitedPlaceItems", new SeenObjectCollection()); } // Delete the Place FK Index if ((objectToRemove as VisitedPlaceDataObject).PlaceURI != null) { if (Place_FKIndex.ContainsKey((System.String)(objectToRemove as VisitedPlaceDataObject).PlaceURI) && Place_FKIndex[(System.String)(objectToRemove as VisitedPlaceDataObject).PlaceURI].Contains((int)objectToRemoveInternalId)) { Place_FKIndex[(System.String)(objectToRemove as VisitedPlaceDataObject).PlaceURI].Remove((int)objectToRemoveInternalId); if (!Place_FKIndex[(System.String)(objectToRemove as VisitedPlaceDataObject).PlaceURI].Any()) { List<int> outvalue; var iscompleted = false; var count2 = 0; while (!iscompleted && count2++ < 15) { iscompleted = Place_FKIndex.TryRemove((System.String)(objectToRemove as VisitedPlaceDataObject).PlaceURI, out outvalue); } } } PlaceDataObject relatedPlace; if ((objectToRemove as VisitedPlaceDataObject)._place_NewObjectId != null) { relatedPlace = _rootObjectDataSet.GetObject(new PlaceDataObject() { IsNew = true, InternalObjectId = (objectToRemove as VisitedPlaceDataObject)._place_NewObjectId }); } else { relatedPlace = _rootObjectDataSet.GetObject(new PlaceDataObject((System.String)(objectToRemove as VisitedPlaceDataObject).PlaceURI) { IsNew = false }); } if (relatedPlace != null && this.RootObjectDataSet.NotifyChanges) relatedPlace.NotifyPropertyChanged("VisitedPlaceItems", new SeenObjectCollection()); } // Delete the UserProfile FK Index if ((objectToRemove as VisitedPlaceDataObject).UserProfileUri != null) { if (UserProfile_FKIndex.ContainsKey((objectToRemove as VisitedPlaceDataObject).UserProfileUri) && UserProfile_FKIndex[(objectToRemove as VisitedPlaceDataObject).UserProfileUri].Contains((int)objectToRemoveInternalId)) { UserProfile_FKIndex[(objectToRemove as VisitedPlaceDataObject).UserProfileUri].Remove((int)objectToRemoveInternalId); if (!UserProfile_FKIndex[(objectToRemove as VisitedPlaceDataObject).UserProfileUri].Any()) { List<int> outvalue; var iscompleted = false; var count2 = 0; while (!iscompleted && count2++ < 15) { iscompleted = UserProfile_FKIndex.TryRemove((objectToRemove as VisitedPlaceDataObject).UserProfileUri, out outvalue); } } } UserProfileDataObject relatedUserProfile; if ((objectToRemove as VisitedPlaceDataObject)._userProfile_NewObjectId != null) { relatedUserProfile = _rootObjectDataSet.GetObject(new UserProfileDataObject() { IsNew = true, InternalObjectId = (objectToRemove as VisitedPlaceDataObject)._userProfile_NewObjectId }); } else { relatedUserProfile = _rootObjectDataSet.GetObject(new UserProfileDataObject((objectToRemove as VisitedPlaceDataObject).UserProfileUri) { IsNew = false }); } if (relatedUserProfile != null && this.RootObjectDataSet.NotifyChanges) relatedUserProfile.NotifyPropertyChanged("VisitedPlaceItems", new SeenObjectCollection()); } } }
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 VisitedPlaceObjectsDataSet", "The object you are trying to add doesn't have an InternalObjectId", "VisitedPlaceObjectsDataSet", 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 = VisitedPlaceObjects.TryAdd(newInternalId, (VisitedPlaceDataObject)objectToAdd); } } if (!objectToAdd.IsNew && existingObject == null) { //The following if should not be necessary... var completed = false; if (VisitedPlaceObjectInternalIds.ContainsKey(((VisitedPlaceDataObject)objectToAdd).PrimaryKey)) { int value; var count2 = 0; while (!completed && count2++ < 15) { completed = VisitedPlaceObjectInternalIds.TryRemove(((VisitedPlaceDataObject)objectToAdd).PrimaryKey, out value); } } completed = false; var count = 0; while (!completed && count++ < 15) { completed = VisitedPlaceObjectInternalIds.TryAdd(((VisitedPlaceDataObject)objectToAdd).PrimaryKey, newInternalId); } } // Update relations including platform as "many" side or "one" side , pk side for one to one relations if((objectToAdd as VisitedPlaceDataObject) == null) { _logEngine.LogError("Unable to Add an object which is null", "Unable to add an object which is null", "VisitedPlaceDataObject", null); throw new PulpException("Unexpected Error: Unable to Add an object which is Null."); } // Update the Country FK Index if ((objectToAdd as VisitedPlaceDataObject).CountryURI != null) { if (!Country_FKIndex.ContainsKey((System.String)(objectToAdd as VisitedPlaceDataObject).CountryURI)) { var iscompleted = false; var count2 = 0; while (!iscompleted && count2++ < 15) { iscompleted = Country_FKIndex.TryAdd((System.String)(objectToAdd as VisitedPlaceDataObject).CountryURI, new List<int>()); } } if (!Country_FKIndex[(System.String)(objectToAdd as VisitedPlaceDataObject).CountryURI].Contains(newInternalId)) Country_FKIndex[(System.String)(objectToAdd as VisitedPlaceDataObject).CountryURI].Add(newInternalId); CountryDataObject relatedCountry; if ((objectToAdd as VisitedPlaceDataObject)._country_NewObjectId != null) { relatedCountry = _rootObjectDataSet.GetObject(new CountryDataObject() { IsNew = true, InternalObjectId = (objectToAdd as VisitedPlaceDataObject)._country_NewObjectId }); } else { relatedCountry = _rootObjectDataSet.GetObject(new CountryDataObject((System.String)(objectToAdd as VisitedPlaceDataObject).CountryURI) { IsNew = false }); } if (relatedCountry != null && this.RootObjectDataSet.NotifyChanges) relatedCountry.NotifyPropertyChanged("VisitedPlaceItems", new SeenObjectCollection()); } // Update the Place FK Index if ((objectToAdd as VisitedPlaceDataObject).PlaceURI != null) { if (!Place_FKIndex.ContainsKey((System.String)(objectToAdd as VisitedPlaceDataObject).PlaceURI)) { var iscompleted = false; var count2 = 0; while (!iscompleted && count2++ < 15) { iscompleted = Place_FKIndex.TryAdd((System.String)(objectToAdd as VisitedPlaceDataObject).PlaceURI, new List<int>()); } } if (!Place_FKIndex[(System.String)(objectToAdd as VisitedPlaceDataObject).PlaceURI].Contains(newInternalId)) Place_FKIndex[(System.String)(objectToAdd as VisitedPlaceDataObject).PlaceURI].Add(newInternalId); PlaceDataObject relatedPlace; if ((objectToAdd as VisitedPlaceDataObject)._place_NewObjectId != null) { relatedPlace = _rootObjectDataSet.GetObject(new PlaceDataObject() { IsNew = true, InternalObjectId = (objectToAdd as VisitedPlaceDataObject)._place_NewObjectId }); } else { relatedPlace = _rootObjectDataSet.GetObject(new PlaceDataObject((System.String)(objectToAdd as VisitedPlaceDataObject).PlaceURI) { IsNew = false }); } if (relatedPlace != null && this.RootObjectDataSet.NotifyChanges) relatedPlace.NotifyPropertyChanged("VisitedPlaceItems", new SeenObjectCollection()); } // Update the UserProfile FK Index if ((objectToAdd as VisitedPlaceDataObject).UserProfileUri != null) { if (!UserProfile_FKIndex.ContainsKey((objectToAdd as VisitedPlaceDataObject).UserProfileUri)) { var iscompleted = false; var count2 = 0; while (!iscompleted && count2++ < 15) { iscompleted = UserProfile_FKIndex.TryAdd((objectToAdd as VisitedPlaceDataObject).UserProfileUri, new List<int>()); } } if (!UserProfile_FKIndex[(objectToAdd as VisitedPlaceDataObject).UserProfileUri].Contains(newInternalId)) UserProfile_FKIndex[(objectToAdd as VisitedPlaceDataObject).UserProfileUri].Add(newInternalId); UserProfileDataObject relatedUserProfile; if ((objectToAdd as VisitedPlaceDataObject)._userProfile_NewObjectId != null) { relatedUserProfile = _rootObjectDataSet.GetObject(new UserProfileDataObject() { IsNew = true, InternalObjectId = (objectToAdd as VisitedPlaceDataObject)._userProfile_NewObjectId }); } else { relatedUserProfile = _rootObjectDataSet.GetObject(new UserProfileDataObject((objectToAdd as VisitedPlaceDataObject).UserProfileUri) { IsNew = false }); } if (relatedUserProfile != null && this.RootObjectDataSet.NotifyChanges) relatedUserProfile.NotifyPropertyChanged("VisitedPlaceItems", new SeenObjectCollection()); } }