Beispiel #1
0
        /// <summary>
        /// 移动一个节点
        /// </summary>
        /// <param name="srcNode">要移动的节点</param>
        /// <param name="detNode">父节点</param>
        /// <returns>返回移动成功的节点</returns>
        public GxTreeNode moveNode(GxTreeNode srcNode, GxTreeNode dstNode)
        {
            if (srcNode == null || dstNode == null)
            {
                Logger.Error("srcNode == null || dstNode == null.");
                return(null);
            }

            if (srcNode == dstNode)
            {
                Logger.Error("srcNode is equals to dstNode.");
                return(null);
            }

            if (findNode(srcNode) == false || findNode(dstNode) == false)
            {
                Logger.Error("srcNode or dstNode not in NodeCollection");
                return(null);
            }

            //目标节点不能是源节点的子节点
            if (findNode(dstNode, srcNode) == true)
            {
                Logger.Error("dstNode is the childNode of srcNode");
                return(null);
            }

            //判断目标节点是否文件夹节点或工程节点
            GXNodeType dstNodeType = dstNode.getGxNodeType();

            if (dstNodeType != GXNodeType.GX_NODE_TYPE_DIRECTORY && dstNodeType != GXNodeType.GX_NODE_TYPE_PROJECT)
            {
                Logger.Error("destination node is not directory type or not project type.");
                return(null);
            }

            //取得场景目录完整路径
            string sceneDirFullPath = GxEnvManager.getEnv(GxEnvVarType.GXENV_PROJECT_SCENE_DIR);

            //如果原节点是目录
            if (srcNode.getGxNodeType() == GXNodeType.GX_NODE_TYPE_DIRECTORY)
            {
                //取得源目录完整路径
                GxNodeData srcNodeData    = (GxNodeData)srcNode.Tag;
                string     srcDirFullPath = srcNodeData.getPath();
                if (Directory.Exists(srcDirFullPath) == false)
                {
                    Logger.Error("srcNode dir path not exists.");
                    return(null);
                }

                //DirectoryInfo srcDirInfo = new DirectoryInfo(srcDirFullPath);
                string srcDirName = Path.GetFileName(srcDirFullPath);

                //取得目标目录完整路径,默认为场景根目录
                GxNodeData dstNodeData    = (GxNodeData)dstNode.Tag;
                string     dstDirFullPath = dstNodeData.getPath();

                if (Directory.Exists(dstDirFullPath) == false)
                {
                    Logger.Error("dstNode dir path not exists.");
                    return(null);
                }

                //取得移动后的目录路径
                string newDirFullPath = dstDirFullPath + "\\" + srcDirName;

                //检查目标路径是否存在了
                if (Directory.Exists(newDirFullPath) == true)
                {
                    Logger.Error("Destination dir is exists!");
                    return(null);
                }

                //检查目标路径是否与自己相等
                if (srcDirFullPath == newDirFullPath)
                {
                    Logger.Error("Two path equals.");
                    return(null);
                }

                //移动目录
                Directory.Move(srcDirFullPath, newDirFullPath);
                Logger.Debug(string.Format("Direcotry [{0}] moved to [{1}] finished!", srcDirFullPath, newDirFullPath));

                //取得节点相关XML元素
                XmlNode srcRelatedXmlNode = srcNodeData.getRelatedXmlNode();
                XmlNode dstRelatedXmlNode = dstNodeData.getRelatedXmlNode();

                //复制源xml节点的副本
                XmlNode appendNode = srcRelatedXmlNode.CloneNode(true);

                //把复制的副本插入到目标节点中
                dstRelatedXmlNode.AppendChild(appendNode);

                //把源xml节点删除
                srcRelatedXmlNode.ParentNode.RemoveChild(srcRelatedXmlNode);

                //更新源节点的关联XMLNode
                srcNodeData.setRelatedXmlNode(appendNode);

                //取得父节点的基本数据
                string newPath = IOUtil.getRelPath(newDirFullPath, sceneDirFullPath);
                srcNodeData.saveRealPathToXml(newPath, srcNode, true);
            }

            //移除原节点
            srcNode.Remove();

            //加到目标节点
            dstNode.Nodes.Add(srcNode);

            return(srcNode);
        }
Beispiel #2
0
        /// <summary>
        /// 移动一个节点
        /// </summary>
        /// <param name="srcNode">要移动的节点</param>
        /// <param name="detNode">父节点</param>
        /// <returns>返回移动成功的节点</returns>
        public GxTreeNode moveNode(GxTreeNode srcNode, GxTreeNode dstNode)
        {
            if (srcNode == null || dstNode == null)
            {
                Logger.Error("srcNode == null || dstNode == null.");
                return null;
            }

            if (srcNode == dstNode)
            {
                Logger.Error("srcNode is equals to dstNode.");
                return null;
            }

            if (findNode(srcNode) == false || findNode(dstNode) == false)
            {
                Logger.Error("srcNode or dstNode not in NodeCollection");
                return null;
            }

            //目标节点不能是源节点的子节点
            if (findNode(dstNode, srcNode) == true)
            {
                Logger.Error("dstNode is the childNode of srcNode");
                return null;
            }

            //判断目标节点是否文件夹节点或工程节点
            GXNodeType dstNodeType = dstNode.getGxNodeType();
            if (dstNodeType != GXNodeType.GX_NODE_TYPE_DIRECTORY && dstNodeType != GXNodeType.GX_NODE_TYPE_PROJECT)
            {
                Logger.Error("destination node is not directory type or not project type.");
                return null;
            }

            //取得场景目录完整路径
            string sceneDirFullPath = GxEnvManager.getEnv(GxEnvVarType.GXENV_PROJECT_SCENE_DIR);

            //如果原节点是目录
            if (srcNode.getGxNodeType() == GXNodeType.GX_NODE_TYPE_DIRECTORY)
            {
                //取得源目录完整路径
                GxNodeData srcNodeData = (GxNodeData)srcNode.Tag;
                string srcDirFullPath = srcNodeData.getPath();
                if (Directory.Exists(srcDirFullPath) == false)
                {
                    Logger.Error("srcNode dir path not exists.");
                    return null;
                }

                //DirectoryInfo srcDirInfo = new DirectoryInfo(srcDirFullPath);
                string srcDirName = Path.GetFileName(srcDirFullPath);

                //取得目标目录完整路径,默认为场景根目录
                GxNodeData dstNodeData = (GxNodeData)dstNode.Tag;
                string dstDirFullPath = dstNodeData.getPath();

                if (Directory.Exists(dstDirFullPath) == false)
                {
                    Logger.Error("dstNode dir path not exists.");
                    return null;
                }

                //取得移动后的目录路径
                string newDirFullPath = dstDirFullPath + "\\" + srcDirName;

                //检查目标路径是否存在了
                if (Directory.Exists(newDirFullPath) == true)
                {
                    Logger.Error("Destination dir is exists!");
                    return null;
                }

                //检查目标路径是否与自己相等
                if (srcDirFullPath == newDirFullPath)
                {
                    Logger.Error("Two path equals.");
                    return null;
                }

                //移动目录
                Directory.Move(srcDirFullPath, newDirFullPath);
                Logger.Debug(string.Format("Direcotry [{0}] moved to [{1}] finished!", srcDirFullPath, newDirFullPath));

                //取得节点相关XML元素
                XmlNode srcRelatedXmlNode = srcNodeData.getRelatedXmlNode();
                XmlNode dstRelatedXmlNode = dstNodeData.getRelatedXmlNode();

                //复制源xml节点的副本
                XmlNode appendNode = srcRelatedXmlNode.CloneNode(true);

                //把复制的副本插入到目标节点中
                dstRelatedXmlNode.AppendChild(appendNode);

                //把源xml节点删除
                srcRelatedXmlNode.ParentNode.RemoveChild(srcRelatedXmlNode);

                //更新源节点的关联XMLNode
                srcNodeData.setRelatedXmlNode(appendNode);

                //取得父节点的基本数据
                string newPath = IOUtil.getRelPath(newDirFullPath, sceneDirFullPath);
                srcNodeData.saveRealPathToXml(newPath, srcNode, true);
            }

            //移除原节点
            srcNode.Remove();

            //加到目标节点
            dstNode.Nodes.Add(srcNode);

            return srcNode;
        }