Exemplo n.º 1
0
        // 构造一个Project对象
        // strLocate	方案所在磁盘目录
        // Exceptions:
        //      Exception   MakeProjectFile()可能抛出此异常
        static public Project MakeProject(string strNamePath,
            string strLocate)
        {
            Project project = new Project();

            project.NamePath = strNamePath;
            project.Locate = strLocate;

            // 将目录中所有文件逐个打包
            DirectoryInfo di = new DirectoryInfo(strLocate);

            FileInfo[] afi = di.GetFiles();

            for (int i = 0; i < afi.Length; i++)
            {
                string strFileName = afi[i].Name;
                if (strFileName.Length > 0
                    && strFileName[0] == '~')
                    continue;	// 忽略临时文件

                project.Add(ProjectFile.MakeProjectFile(afi[i].FullName));
            }

            return project;
        }
Exemplo n.º 2
0
        // 将Project对象Paste到管理界面中
        // bRestoreOriginNamePath	是否恢复到原始名字路径。==false,表示恢复到treeview当前目录
        private int PasteProject(Project project,
            string strLastModified,
            bool bRestoreOriginNamePath,
            out string strError)
        {
            strError = "";

            string strPath;
            string strName;

            // 纯Project名
            ScriptManager.SplitProjectPathName(project.NamePath,
                out strPath,
                out strName);

            string strCurPath = "";

            // 插入的目录

            int nRet;
            TreeNode node = null;
            TreeNode parent = null;

            // 恢复原始名字路径
            if (bRestoreOriginNamePath == true)
            {
                if (strPath == "")
                    parent = null;
                XmlNode xmlNode = scriptManager.LocateDirNode(
                    strPath);
                if (xmlNode == null)
                {
                    xmlNode = scriptManager.NewDirNode(
                        strPath);
                    // 兑现显示?
                    scriptManager.RefreshTree(treeView1);
                    TreeViewUtil.SelectTreeNode(treeView1,
                        strPath,
                        '/');
                }
                else
                {
                    TreeViewUtil.SelectTreeNode(treeView1,
                        strPath,
                        '/');
                }

            }

            // 恢复到当前目录
            {
                node = treeView1.SelectedNode;
                // 当前已选择的node
                if (node == null)
                {
                    // 根
                }
                else
                {
                    if (node.ImageIndex == 0) // 目录
                    {
                        parent = node;
                        strCurPath = node.FullPath;
                    }
                    else
                    {
                        parent = node.Parent;
                        if (parent != null)
                            strCurPath = parent.FullPath;
                    }
                }
            }

            // 看看当前目录下是否已经存在同名Project

            string strLocate;
            // 获得方案参数
            // strProjectNamePath	方案名,或者路径
            // return:
            //		-1	error
            //		0	not found project
            //		1	found
            nRet = scriptManager.GetProjectData(
                ScriptManager.MakeProjectPathName(strCurPath, strName),
                out strLocate);
            if (nRet == -1)
            {
                strError = "GetProjectData " + ScriptManager.MakeProjectPathName(strCurPath, strName) + " error";
                return -1;
            }

            int nPrefixNumber = 0;

            if (nRet == 0)
            {
                nPrefixNumber = -1;
            }
            else
            {
                // 换名paste进入

                // 在儿子中找到一个不重复的名字
                strName = GetTempProjectName(treeView1,
                    parent,
                    strName,
                    ref nPrefixNumber);
            }

            string strLocatePrefix = "";
            if (project.Locate == "")
            {
                strLocatePrefix = strName;
            }
            else
            {
                strLocatePrefix = PathUtil.PureName(project.Locate);
            }

            strLocate = scriptManager.NewProjectLocate(
                strLocatePrefix,
                ref nPrefixNumber);

            string strNamePath = ScriptManager.MakeProjectPathName(strCurPath, strName);

            // 直接paste
            project.WriteToLocate(strLocate,
                true);

            // 实际插入project参数
            XmlNode projNode = scriptManager.NewProjectNode(
                strNamePath,
                strLocate,
                false);	// false表示不需要创建目录和缺省文件

            DomUtil.SetAttr(projNode, "lastModified",
strLastModified);

            // 兑现显示?
            scriptManager.FillOneLevel(treeView1,
                parent,
                projNode.ParentNode);
            TreeViewUtil.SelectTreeNode(treeView1,
                scriptManager.GetNodePathName(projNode),
                '/');

            scriptManager.Save();

            TreeViewUtil.SelectTreeNode(treeView1,
                strNamePath,
                '/');

            return 0;
        }