Exemple #1
0
        /// <summary>
        /// 加载子节点(递归方法)
        /// </summary>
        /// <param name="childNode"></param>
        /// <param name="treeNode"></param>
        private void loadNodes(XmlNode childNode, GxTreeNode parentNode)
        {
            //如果父节点为空则默认为工程根节点
            if (parentNode == null)
            {
                parentNode = _projectNode;
            }

            //老衲要开始遍历了!
            foreach (XmlNode node in childNode.ChildNodes)
            {
                if (node.Name == "IncludeNode")
                {
                    string name = node.Attributes["Name"].Value;
                    string path = GxEnvManager.getEnv(GxEnvVarType.GXENV_PROJECT_SCENE_DIR) + "\\" + node.Attributes["Path"].Value;
                    string type = node.Attributes["Type"].Value;

                    //如果节点是目录
                    if (type == "DirectoryType")
                    {
                        GxSceneDirectory gxDirectory = new GxSceneDirectory(path, node);
                        GxTreeNode       gxTreeNode  = new GxTreeNode(
                            name,
                            gxDirectory,
                            GXNodeType.GX_NODE_TYPE_DIRECTORY,
                            ICON_TYPE.ICON_SCENE_DIR,
                            ICON_TYPE.ICON_SCENE_DIR
                            );

                        parentNode.Nodes.Add(gxTreeNode);

                        if (node.ChildNodes.Count > 0)
                        {
                            loadNodes(node, gxTreeNode);
                        }
                    }
                    else if (type == "SceneFileType")
                    {
                        int        sceneId    = Convert.ToInt32(node.Attributes["Id"].Value);
                        GxScene    gxScene    = new GxScene(sceneId, path);
                        GxTreeNode gxTreeNode = new GxTreeNode(
                            name,
                            gxScene,
                            GXNodeType.GX_NODE_TYPE_SCENE,
                            ICON_TYPE.ICON_SCENE,
                            ICON_TYPE.ICON_SCENE
                            );

                        parentNode.Nodes.Add(gxTreeNode);
                    }
                    else
                    {
                        Logger.Error("Invalid node type.");
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 创建一个新的场景文件
        /// </summary>
        /// <param name="sceneName"></param>
        /// <param name="filename"></param>
        /// <param name="parentNode"></param>
        /// <returns></returns>

        /*public bool createNewScene(string sceneName, string filename, GxTreeNode parentNode = null)
         * {
         *  if (sceneName.Length == 0 || filename.Length == 0)
         *  {
         *      Logger.Warn("sceneName.Length == 0 || filename.Length == 0");
         *      return false;
         *  }
         *
         *  //如果文件已经存在则返回
         *  if (File.Exists(filename) == true)
         *  {
         *      Logger.Error("Create scene file failed, file is exists.");
         *      return false;
         *  }
         *
         *  XmlDocument newSceneXmlDoc = new XmlDocument();
         *  newSceneXmlDoc.Save(filename);
         *
         *  return true;
         * }*/

        /// <summary>
        /// 以默认目录名新建一个目录
        /// </summary>
        /// <param name="directoryName"></param>
        /// <param name="dirPath"></param>
        /// <returns></returns>
        public bool createNewDirectory(GxTreeNode parentNode)
        {
            GxTreeNode treeNode = (GxTreeNode)parentNode;

            if (treeNode == null)
            {
                return(false);
            }

            GxNodeData nodeDataBase = (GxNodeData)parentNode.Tag;

            if (nodeDataBase != null)
            {
                string parentPath = "";

                //if (treeNode.getGxNodeType() == GXNodeType.GX_NODE_TYPE_DIRECTORY)
                //{
                parentPath = nodeDataBase.getPath();
                //}
                // else if (treeNode.getGxNodeType() == GXNodeType.GX_NODE_TYPE_PROJECT)
                //{
                //   parentPath = GxEnvManager.getEnv(GxEnvVarType.GXENV_PROJECT_SCENE_DIR);
                //}

                Logger.Debug("parent full path = " + Path.GetFullPath(parentPath));
                if (Directory.Exists(parentPath) == true)
                {
                    //循环创建文件夹并找到一个不存在的计数,作为默认文件夹
                    int          count = 1;
                    const string defaultDirectoryName = "新建场景目录";

                    string newDirectoryName     = "";
                    string newDirectoryFullPath = "";

                    while (true)
                    {
                        newDirectoryName     = defaultDirectoryName + count.ToString();
                        newDirectoryFullPath = parentPath + "\\" + newDirectoryName;

                        //目录如果存在,则计数+1
                        if (Directory.Exists(newDirectoryFullPath) == true)
                        {
                            Logger.Info("[" + newDirectoryFullPath + "] is exists.");
                            count++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    //取得父节点XML对象,创建文件夹节点到XML
                    XmlNode    parentXmlNode          = nodeDataBase.getRelatedXmlNode();
                    XmlElement newDirectoryXmlElement = null;
                    if (parentXmlNode != null)
                    {
                        //创建一个IncludeNode节点
                        newDirectoryXmlElement = _document.CreateElement("IncludeNode");
                        newDirectoryXmlElement.SetAttribute("Name", newDirectoryName);
                        newDirectoryXmlElement.SetAttribute("Type", "DirectoryType");
                        newDirectoryXmlElement.SetAttribute("Path", newDirectoryFullPath);

                        //插入到父节点
                        parentXmlNode.AppendChild(newDirectoryXmlElement);
                        parentXmlNode.OwnerDocument.Save(GxEnvManager.getEnv(GxEnvVarType.GXENV_PROJECT_PATH));
                    }
                    else
                    {
                        Logger.Error("parentXmlNode == null");
                        return(false);
                    }

                    //创建目录到硬盘
                    Directory.CreateDirectory(Path.GetFullPath(newDirectoryFullPath));

                    //添加TreeView节点到场景列表
                    GxSceneDirectory sceneDir         = new GxSceneDirectory(newDirectoryFullPath, newDirectoryXmlElement);
                    GxTreeNode       newDirectoryNode = new GxTreeNode(newDirectoryName, sceneDir, GXNodeType.GX_NODE_TYPE_DIRECTORY, ICON_TYPE.ICON_SCENE_DIR, ICON_TYPE.ICON_SCENE_DIR);
                    parentNode.Nodes.Add(newDirectoryNode);
                }
                else
                {
                    Logger.Error("Parent directory is not exists.");
                    return(false);
                }
            }
            else
            {
                Logger.Error("nodeDataBase == null");
                return(false);
            }

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// 创建一个新的场景文件
        /// </summary>
        /// <param name="sceneName"></param>
        /// <param name="filename"></param>
        /// <param name="parentNode"></param>
        /// <returns></returns>
        /*public bool createNewScene(string sceneName, string filename, GxTreeNode parentNode = null)
        {
            if (sceneName.Length == 0 || filename.Length == 0)
            {
                Logger.Warn("sceneName.Length == 0 || filename.Length == 0");
                return false;
            }

            //如果文件已经存在则返回
            if (File.Exists(filename) == true)
            {
                Logger.Error("Create scene file failed, file is exists.");
                return false;
            }

            XmlDocument newSceneXmlDoc = new XmlDocument();
            newSceneXmlDoc.Save(filename);

            return true;
        }*/
        /// <summary>
        /// 以默认目录名新建一个目录
        /// </summary>
        /// <param name="directoryName"></param>
        /// <param name="dirPath"></param>
        /// <returns></returns>
        public bool createNewDirectory(GxTreeNode parentNode)
        {
            GxTreeNode treeNode = (GxTreeNode)parentNode;
            if (treeNode == null)
            {
                return false;
            }

            GxNodeData nodeDataBase = (GxNodeData)parentNode.Tag;
            if (nodeDataBase != null)
            {
                string parentPath = "";

                //if (treeNode.getGxNodeType() == GXNodeType.GX_NODE_TYPE_DIRECTORY)
                //{
                    parentPath = nodeDataBase.getPath();
                //}
               // else if (treeNode.getGxNodeType() == GXNodeType.GX_NODE_TYPE_PROJECT)
                //{
                 //   parentPath = GxEnvManager.getEnv(GxEnvVarType.GXENV_PROJECT_SCENE_DIR);
                //}

                Logger.Debug("parent full path = " + Path.GetFullPath(parentPath));
                if (Directory.Exists(parentPath) == true)
                {
                    //循环创建文件夹并找到一个不存在的计数,作为默认文件夹
                    int count = 1;
                    const string defaultDirectoryName = "新建场景目录";

                    string newDirectoryName = "";
                    string newDirectoryFullPath = "";

                    while (true)
                    {
                        newDirectoryName = defaultDirectoryName + count.ToString();
                        newDirectoryFullPath = parentPath + "\\" + newDirectoryName;

                        //目录如果存在,则计数+1
                        if (Directory.Exists(newDirectoryFullPath) == true)
                        {
                            Logger.Info("[" + newDirectoryFullPath + "] is exists.");
                            count++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    //取得父节点XML对象,创建文件夹节点到XML
                    XmlNode parentXmlNode = nodeDataBase.getRelatedXmlNode();
                    XmlElement newDirectoryXmlElement = null;
                    if (parentXmlNode != null)
                    {
                        //创建一个IncludeNode节点
                        newDirectoryXmlElement = _document.CreateElement("IncludeNode");
                        newDirectoryXmlElement.SetAttribute("Name", newDirectoryName);
                        newDirectoryXmlElement.SetAttribute("Type", "DirectoryType");
                        newDirectoryXmlElement.SetAttribute("Path", newDirectoryFullPath);

                        //插入到父节点
                        parentXmlNode.AppendChild(newDirectoryXmlElement);
                        parentXmlNode.OwnerDocument.Save(GxEnvManager.getEnv(GxEnvVarType.GXENV_PROJECT_PATH));
                    }
                    else
                    {
                        Logger.Error("parentXmlNode == null");
                        return false;
                    }

                    //创建目录到硬盘
                    Directory.CreateDirectory(Path.GetFullPath(newDirectoryFullPath));

                    //添加TreeView节点到场景列表
                    GxSceneDirectory sceneDir = new GxSceneDirectory(newDirectoryFullPath, newDirectoryXmlElement);
                    GxTreeNode newDirectoryNode = new GxTreeNode(newDirectoryName, sceneDir, GXNodeType.GX_NODE_TYPE_DIRECTORY, ICON_TYPE.ICON_SCENE_DIR, ICON_TYPE.ICON_SCENE_DIR);
                    parentNode.Nodes.Add(newDirectoryNode);
                }
                else
                {
                    Logger.Error("Parent directory is not exists.");
                    return false;
                }
            }
            else
            {
                Logger.Error("nodeDataBase == null");
                return false;
            }

            return true;
        }
Exemple #4
0
        /// <summary>
        /// 加载子节点(递归方法)
        /// </summary>
        /// <param name="childNode"></param>
        /// <param name="treeNode"></param>
        private void loadNodes(XmlNode childNode, GxTreeNode parentNode)
        {
            //如果父节点为空则默认为工程根节点
            if (parentNode == null)
            {
                parentNode = _projectNode;
            }

            //老衲要开始遍历了!
            foreach (XmlNode node in childNode.ChildNodes)
            {
                if (node.Name == "IncludeNode")
                {
                    string name = node.Attributes["Name"].Value;
                    string path = GxEnvManager.getEnv(GxEnvVarType.GXENV_PROJECT_SCENE_DIR) + "\\" + node.Attributes["Path"].Value;
                    string type = node.Attributes["Type"].Value;

                    //如果节点是目录
                    if (type == "DirectoryType")
                    {
                        GxSceneDirectory gxDirectory = new GxSceneDirectory(path, node);
                        GxTreeNode gxTreeNode = new GxTreeNode(
                            name,
                            gxDirectory,
                            GXNodeType.GX_NODE_TYPE_DIRECTORY,
                            ICON_TYPE.ICON_SCENE_DIR,
                            ICON_TYPE.ICON_SCENE_DIR
                            );

                        parentNode.Nodes.Add(gxTreeNode);

                        if (node.ChildNodes.Count > 0)
                        {
                            loadNodes(node, gxTreeNode);
                        }
                    }
                    else if (type == "SceneFileType")
                    {
                        int sceneId = Convert.ToInt32(node.Attributes["Id"].Value);
                        GxScene gxScene = new GxScene(sceneId,path);
                        GxTreeNode gxTreeNode = new GxTreeNode(
                            name,
                            gxScene,
                            GXNodeType.GX_NODE_TYPE_SCENE,
                            ICON_TYPE.ICON_SCENE,
                            ICON_TYPE.ICON_SCENE
                            );

                        parentNode.Nodes.Add(gxTreeNode);
                    }
                    else
                    {
                        Logger.Error("Invalid node type.");
                    }
                }
            }
        }