public virtual void Rename( string sNewName) { // Optimization if (this.Name == sNewName) { return; } using (AutoTreeChangeNotify oChangeNotify = new AutoTreeChangeNotify( this, EntityTreeChange.Rename, this, null, EntityRelation.Undefined, sNewName)) { Hashtable oNamesMap = new Hashtable(); foreach (INamedObjectList oParentContainer in ParentContainers) { string sPrevName = oParentContainer[this.Name].Name; oNamesMap.Add(oParentContainer, sPrevName); } PreFullContextNameChangeNotify(sNewName); // Set new name m_sName = sNewName; // Notify all containers that object name was changed foreach (INamedObjectList oParentContainer in ParentContainers) { // Keep previous name string sPrevName = (string)(oNamesMap[oParentContainer]); string sName = oParentContainer[sPrevName].Name; oParentContainer.ObjectRenamed(sPrevName, sName); } } }
private void OwnedChildrenList_OnAdd(object sender, NamedEventArgs e) { INamedObjectList oContainer = (INamedObjectList)sender; IEntityBase oChildEntity = e.NamedObject as IEntityBase; if (oChildEntity == null) { return; } using (AutoTreeChangeNotify oChangeNotify = new AutoTreeChangeNotify( this, EntityTreeChange.ChildAdd, this, oChildEntity, EntityRelation.Owner, null)) { UpdateOwnerContainer(oChildEntity, oContainer); } }
private void LinkedChildrenList_OnRemove(object sender, NamedEventArgs e) { INamedObjectList oContainer = (INamedObjectList)sender; IEntityBase oChildEntity = e.NamedObject as IEntityBase; if (oChildEntity == null) { return; } using (AutoTreeChangeNotify oChangeNotify = new AutoTreeChangeNotify( this, EntityTreeChange.ChildRemove, this, oChildEntity, EntityRelation.Link, null)) { // Register the container as parent of the entity oChildEntity.RemoveParentContainer(oContainer); RemoveUniqueParentLinkIfNeeded(oChildEntity); } }
private void OwnedChildrenList_OnRemove(object sender, NamedEventArgs e) { INamedObjectList oContainer = (INamedObjectList)sender; IEntityBase oChildEntity = e.NamedObject as IEntityBase; if (oChildEntity == null) { return; } using (AutoTreeChangeNotify oChangeNotify = new AutoTreeChangeNotify( this, EntityTreeChange.ChildRemove, this, oChildEntity, EntityRelation.Owner, null)) { // // The object oChild that we are it's owner is detached from the tree. // 1. All links to this object should be removed, i.e it should be removed // from all containers listed in m_ParentContainers. // 2. Reset UniqueParentLink of all linked children of the removed object. // // Remove all links to child object // TODO: !!! Revert to INamedObjectList when RemoveObject will be part // of INamedObjectList interface foreach (INamedObjectList oParentContainer in oChildEntity.ParentContainers) { try { // We don't want to remove from owner (our) container, since // This operation is already done if (oParentContainer != oContainer) { oParentContainer.Remove(oChildEntity.Name); } } catch (Exception oExc) { Log.WriteError( "Object [{0}] was not removed from parent container " + " [{1}]", oChildEntity, oParentContainer); Log.WriteException(oExc); } } // Detach all linked children of the removed object oChildEntity.DetachAllChildren(); // Remove links from child object to parents RemoveUniqueParentLinkIfNeeded(oChildEntity); // Reset child "OwnerParent" field SetObjectOwnerParent( oChildEntity, null); } }