Example #1
0
        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);
                }
            }
        }
Example #2
0
        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);
        }