Пример #1
0
        // 从 dp2003.com 安装方案
        void menu_installProjects_Click(object sender, System.EventArgs e)
        {
            string strError = "";
            int nRet = 0;
            int nInstallCount = 0;

            bool bDebugger = false;
            if (Control.ModifierKeys == Keys.Control)
                bDebugger = true;


            this.EnableControls(false);
            try
            {
                Debug.Assert(string.IsNullOrEmpty(this.DataDir) == false, "");

                // 下载projects.xml文件
                string strLocalFileName = PathUtil.MergePath(this.DataDir, "~temp_projects.xml");
                string strTempFileName = PathUtil.MergePath(this.DataDir, "~temp_download_projects.xml");

                try
                {
                    File.Delete(strLocalFileName);
                }
                catch
                {
                }
                try
                {
                    File.Delete(strTempFileName);
                }
                catch
                {
                }

                nRet = WebFileDownloadDialog.DownloadWebFile(
                    this,
                    this.ProjectsUrl,   // "http://dp2003.com/dp2batch/projects/projects.xml"
                    strLocalFileName,
                    strTempFileName,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                // 列出已经安装的方案的URL
                List<string> installed_urls = new List<string>();

                nRet = this.scriptManager.GetInstalledUrls(out installed_urls,
                out strError);
                if (nRet == -1)
                    goto ERROR1;

                SelectInstallProjectsDialog dlg = new SelectInstallProjectsDialog();
                GuiUtil.SetControlFont(dlg, this.Font);
                dlg.FilterHosts.Clear();
                Debug.Assert(string.IsNullOrEmpty(this.HostName) == false, "");
                dlg.FilterHosts.Add(this.HostName);
                dlg.XmlFilename = strLocalFileName;
                dlg.InstalledUrls = installed_urls;
                if (bDebugger == true)
                    dlg.Category = "debugger";
                dlg.StartPosition = FormStartPosition.CenterScreen;

                if (this.AppInfo != null)
                    this.AppInfo.LinkFormState(dlg,
                        "SelectInstallProjectsDialog_state");
                dlg.ShowDialog(this);
                if (this.AppInfo != null)
                    this.AppInfo.UnlinkFormState(dlg);
                if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                    return;

                foreach (ProjectItem item in dlg.SelectedProjects)
                {
                    string strLocalFileName1 = this.DataDir + "\\~install_project.projpack";
                    string strTempFileName1 = this.DataDir + "\\~temp_download_webfile";
                    string strLastModified = "";

                    nRet = WebFileDownloadDialog.DownloadWebFile(
                        this,
                        item.Url,
                        strLocalFileName1,
                        strTempFileName1,
                        "",
                        out strLastModified,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    // 安装Project
                    // return:
                    //      -1  出错
                    //      0   没有安装方案
                    //      >0  安装的方案数
                    nRet = this.scriptManager.InstallProject(
                        this,
                        "当前统计窗",
                        strLocalFileName1,
                        strLastModified,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    nInstallCount += nRet;
                }

                // 刷新树的显示
                if (nInstallCount > 0)
                {
                    this.treeView1.Nodes.Clear();
                    scriptManager.FillTree(this.treeView1);
                    treeView1_AfterSelect(null, null);
                }
            }
            finally
            {
                this.EnableControls(true);
            }


            MessageBox.Show(this, "共安装方案 " + nInstallCount.ToString() + " 个");
            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Пример #2
0
        // 从磁盘目录安装方案
        void menu_installProjectsFromDisk_Click(object sender, System.EventArgs e)
        {
            string strError = "";
            int nRet = 0;
            int nInstallCount = 0;

            bool bDebugger = false;
            if (Control.ModifierKeys == Keys.Control)
                bDebugger = true;

            FolderBrowserDialog dir_dlg = new FolderBrowserDialog();

            dir_dlg.Description = "请指定方案所在目录:";
            dir_dlg.RootFolder = Environment.SpecialFolder.MyComputer;
            dir_dlg.ShowNewFolderButton = false;

            if (dir_dlg.ShowDialog() != DialogResult.OK)
                return;

            // 寻找 projects.xml 文件
            string strProjectsFileName = PathUtil.MergePath(dir_dlg.SelectedPath, "projects.xml");
            if (File.Exists(strProjectsFileName) == false)
            {
                // strError = "您所指定的目录 '" + dir_dlg.SelectedPath + "' 中并没有包含 projects.xml 文件,无法进行安装";
                // goto ERROR1;

                // 如果没有 projects.xml 文件,则搜索全部 *.projpack 文件,并创建好一个临时的 ~projects.xml文件
                Debug.Assert(string.IsNullOrEmpty(this.DataDir) == false, "");
                strProjectsFileName = PathUtil.MergePath(this.DataDir, "~projects.xml");
                nRet = ScriptManager.BuildProjectsFile(dir_dlg.SelectedPath,
                    strProjectsFileName,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;
            }

            this.EnableControls(false);
            try
            {
                // 列出已经安装的方案的URL
                List<string> installed_urls = new List<string>();

                nRet = this.scriptManager.GetInstalledUrls(out installed_urls,
                out strError);
                if (nRet == -1)
                    goto ERROR1;

                SelectInstallProjectsDialog dlg = new SelectInstallProjectsDialog();
                GuiUtil.SetControlFont(dlg, this.Font);
                dlg.FilterHosts.Clear();
                Debug.Assert(string.IsNullOrEmpty(this.HostName) == false, "");
                dlg.FilterHosts.Add(this.HostName);
                dlg.XmlFilename = strProjectsFileName;
                dlg.InstalledUrls = installed_urls;
                if (bDebugger == true)
                    dlg.Category = "debugger";
                dlg.StartPosition = FormStartPosition.CenterScreen;

                if (this.AppInfo != null)
                    this.AppInfo.LinkFormState(dlg,
                        "SelectInstallProjectsDialog_state");
                dlg.ShowDialog(this);
                if (this.AppInfo != null)
                    this.AppInfo.UnlinkFormState(dlg);
                if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                    return;

                foreach (ProjectItem item in dlg.SelectedProjects)
                {
                    string strLastModified = "";
                    string strLocalFileName1 = "";

                    if (string.IsNullOrEmpty(item.FilePath) == false)
                    {
                        strLocalFileName1 = item.FilePath;
                    }
                    else
                    {
                        string strPureFileName = ScriptManager.GetFileNameFromUrl(item.Url);

                        strLocalFileName1 = PathUtil.MergePath(dir_dlg.SelectedPath, strPureFileName);
                    }

                    FileInfo fi = new FileInfo(strLocalFileName1);
                    if (fi.Exists == false)
                    {
                        strError = "没有找到文件 '" + strLocalFileName1 + "'";
                        //    strError = "目录 '" + dir_dlg.SelectedPath + "' 中没有找到文件 '" + strPureFileName + "'";
                        goto ERROR1;
                    }


                    strLastModified = DateTimeUtil.Rfc1123DateTimeString(fi.LastWriteTimeUtc);

                    // 安装Project
                    // return:
                    //      -1  出错
                    //      0   没有安装方案
                    //      >0  安装的方案数
                    nRet = this.scriptManager.InstallProject(
                        this,
                        "当前统计窗",
                        strLocalFileName1,
                        strLastModified,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    nInstallCount += nRet;
                }

                // 刷新树的显示
                if (nInstallCount > 0)
                {
                    this.treeView1.Nodes.Clear();
                    scriptManager.FillTree(this.treeView1);
                    treeView1_AfterSelect(null, null);
                }
            }
            finally
            {
                this.EnableControls(true);
            }

            MessageBox.Show(this, "共安装方案 " + nInstallCount.ToString() + " 个");
            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }