// Avoids reallocation of returned children ArrayList private void GetChildren( object oObj, ChildrenListFilter pfChildrenListFilter, object oChildrenListFilterCriteria, ObjectFilter pfObjectFilter, object oObjectFilterCriteria, EntityRelation enRelation, bool bRecursive, ICollection <object> oOutChildren) { // Get TypeInfo of specified object EntityTypeInfo oEntityTypeInfo = GetEntityTypeInfo(oObj); // Get the ChildrenLists according to EntityRelation filter EntityChildrenListInfo[] ChildrenLists = GetChildrenListsInfo( oEntityTypeInfo, enRelation); // Iterate ChildrenLists foreach (EntityChildrenListInfo oChildrenList in ChildrenLists) { // Obtain list object INamedObjectList oContainer = oChildrenList.GetValue(oObj) as INamedObjectList; if (oContainer != null) { // Check if container passes filter bool bContainerPassedFilter = (pfChildrenListFilter == null) || pfChildrenListFilter(oChildrenList, oChildrenListFilterCriteria); object oEl; for (int i = 0; i < oContainer.Count; i++) { oEl = oContainer[oContainer.NameByIndex(i)]; if (bContainerPassedFilter && (pfObjectFilter == null || pfObjectFilter(oEl, oObjectFilterCriteria))) { // If elements filter passed oOutChildren.Add(oEl); } if (bRecursive) { // Recursive call for each children GetChildren( oEl, pfChildrenListFilter, oChildrenListFilterCriteria, pfObjectFilter, oObjectFilterCriteria, enRelation, bRecursive, oOutChildren); } } } } }
private void RemoveObjects( INamedObjectList oList, ICollection oObjects) { foreach (INamedObject oObj in oObjects) { oList.Remove(oObj.Name); } }
private void UpdateNonOwnerContainer( INamedObject oObj, INamedObjectList oContainer) { AddChildCommon( oContainer, oObj, false); }
private void AddChildCommon( INamedObjectList oContainer, INamedObject oChild, bool bOwner) { // Register the container as parent of the entity (oChild as IEntityBase).AddParentContainer(oContainer, bOwner); SetUniqueParentLinkIfNeeded(oChild); }
private void UpdateOwnerContainer( INamedObject oObj, INamedObjectList oContainer) { // Set child "OwnerParent" field SetObjectOwnerParent( oObj, this); AddChildCommon( oContainer, oObj, true); }
public void RemoveParentContainer(INamedObjectList oParentContainer) { int ind; if ((ind = Array.IndexOf(ParentContainers, oParentContainer)) < 0) { throw new TisException( "Entity [{0}] don't contain [{1}] as parent", this, oParentContainer); } m_ParentContainers.RemoveAt(ind); }
private IEnumerator GetListEnumerator(INamedObjectList oList) { INamedObjectOrder oOrder = oList as INamedObjectOrder; IEnumerator oEnumerator = null; if (oOrder != null) { oEnumerator = oOrder.GetOrderedEnumerator(); } else { oEnumerator = oList.GetEnumerator(); } return(oEnumerator); }
private int GetOrderInOwnerContainer(EntityBase oEntity) { INamedObjectList oOwnerContainer = oEntity.OwnerContainter; int nOrder = -1; if (oOwnerContainer != null) { INamedObjectOrder oOrder = oOwnerContainer as INamedObjectOrder; if (oOrder != null) { nOrder = oOrder.GetOrderByName(oEntity.Name); } } return(nOrder); }
public void RemoveObjectsFromSource() { ArrayList oAllRoots = new ArrayList(); oAllRoots.AddRange(m_oCopyRoots.Keys); oAllRoots.AddRange(m_oForeignRoots); foreach (EntityBase oEntity in oAllRoots) { INamedObjectList oOwnerContainer = oEntity.OwnerContainter as INamedObjectList; // GetOwnerContainer(oEntity); if (oOwnerContainer == null) { continue; } oOwnerContainer.Remove(oEntity.Name); } }
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 CloneChildrenTo( ITisDataLayerTreeNode oTargetObj, ICollection <ITisEntityChildInfo> ChildrenInfoCollection, EntityCloneSpec enEntityCloneSpec) { foreach (ITisEntityChildInfo oChildInfo in ChildrenInfoCollection) { // Get source list INamedObjectList oSrcList = oChildInfo.GetChildList(this); // Get destination list INamedObjectList oDstList = oChildInfo.GetChildList(oTargetObj); // Add cloned objects to destination list TisDataLayerTreeNode oChildNode; for (int i = 0; i < oSrcList.Count; i++) { if (oSrcList is INamedObjectOrder) { oChildNode = ((oSrcList as INamedObjectOrder).GetByOrder(i)) as TisDataLayerTreeNode; } else { oChildNode = (oSrcList[oSrcList.NameByIndex(i)]) as TisDataLayerTreeNode; } // Clone ITisDataLayerTreeNode oClonedChildNode = oChildNode.Clone(enEntityCloneSpec); // Add to list oDstList.Add(oClonedChildNode); } } }
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); } }
public void AddParentContainer( INamedObjectList oParentContainer, bool bOwner) { if (m_ParentContainers == null) { m_ParentContainers = new List <INamedObjectList>(); } if (m_ParentContainers.Count == 0) { // Owner m_ParentContainers.Add(oParentContainer); } else { try { if (bOwner) { m_ParentContainers.Insert(0, oParentContainer); } else { m_ParentContainers.Add(oParentContainer); } } catch (Exception e) { throw new TisException(e, "Entity [{0}] already contains has [{1}] as parent", this, oParentContainer); } } }
private CollisionAction GetCollisionAction( ref string sObjectName, string sObjTypeName, INamedObjectList oTargetList) { // const string IMPORTED_SUFFIX = "_Imported"; // // System.Text.StringBuilder oNewObjectName = new System.Text.StringBuilder(); // oNewObjectName.Append(sObjectName); // oNewObjectName.Append(IMPORTED_SUFFIX); // // int nImportedSuffixIndex = sObjectName.IndexOf(IMPORTED_SUFFIX); // // if(nImportedSuffixIndex >= 0) // { // string sImportNum = // sObjectName.Substring(nImportedSuffixIndex + IMPORTED_SUFFIX.Length); // // int nImportNum = 1; // // if(sImportNum.Length > 0) // { // try // { // nImportNum = int.Parse(sImportNum) + 1; // } // catch // { // } // } // // oNewObjectName.Append(nImportNum.ToString()); // } // // sObjectName = oNewObjectName.ToString(); // // return CollisionAction.Rename; if (OnObjectExists != null) { string sPrevObjectName = sObjectName; ImportOverwriteInfo oOverwriteInfo = new ImportOverwriteInfo( false, // Overwrite sObjectName); string sCurrObjName = sObjectName; // If rename specified, loop until a valid name is provided do { OnObjectExists( sCurrObjName, sObjTypeName, oOverwriteInfo); sCurrObjName = oOverwriteInfo.NewObjectName; }while (oOverwriteInfo.Overwrite && sCurrObjName != sPrevObjectName && oTargetList[sCurrObjName] != null); sObjectName = sCurrObjName; // Currently callback misses the specific Rename & KeepOriginal flags // so we need to check if the NewObjectName was set to other name in order // to determine Rename action. if (oOverwriteInfo.Overwrite) { if (sObjectName != sPrevObjectName) { return(CollisionAction.Rename); } return(CollisionAction.Overwrite); } else { return(CollisionAction.KeepOriginal); } } // Default return(CollisionAction.KeepOriginal); }
private IEntityBase CopyObject( INamedObjectList oDstList, IEntityBase oEntity, bool bWithOwnedChildren) { IEntityBase oClonedEntity = PerformClone(oEntity); IEntityBase oDstListEntity = oClonedEntity; try { oDstList.Add(oClonedEntity); } catch { // Collision string sObjName = oEntity.Name; // Determine what to do CollisionAction enCollisionAction = GetCollisionAction( ref sObjName, oEntity.TypeInfo.TheType.Name, oDstList); bool bRetryAdd = true; switch (enCollisionAction) { case CollisionAction.Rename: oClonedEntity.Rename(sObjName); break; case CollisionAction.Overwrite: oDstList.Remove(oEntity.Name); break; case CollisionAction.KeepOriginal: oDstListEntity = (EntityBase)oDstList[oEntity.Name]; bRetryAdd = false; break; } if (bRetryAdd) { oDstList.Add(oClonedEntity); } } m_oGraph[oEntity] = oDstListEntity; if (bWithOwnedChildren) { CopyOwnedChildren( oEntity, oDstListEntity, true // Recursive ); } return(oDstListEntity); }
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); } }