コード例 #1
0
ファイル: MainForm.cs プロジェクト: paopaofeng/dp2
        // 卸载 dp2library
        private void MenuItem_dp2library_uninstall_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

            this._floatingMessage.Text = "正在卸载 dp2library - 图书馆应用服务器 ...";
            try
            {
                AppendSectionTitle("卸载 dp2library 开始");

                AppendString("正在获得可执行文件目录 ...\r\n");

                Application.DoEvents();

                string strExePath = GetPathOfService("dp2LibraryService");
                if (string.IsNullOrEmpty(strExePath) == true)
                {
                    strError = "dp2library 未曾安装过";
                    goto ERROR1;
                }
                strExePath = Unquote(strExePath);

                {
                    AppendString("正在停止 dp2library 服务 ...\r\n");

                    nRet = StopService("dp2LibraryService",
            out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    AppendString("dp2library 服务已经停止\r\n");
                }

                try
                {
                    DigitalPlatform.LibraryServer.InstanceDialog dlg = new DigitalPlatform.LibraryServer.InstanceDialog();
                    GuiUtil.AutoSetDefaultFont(dlg);

                    dlg.Text = "dp2Library - 彻底卸载所有实例和数据目录";
                    dlg.Comment = "下列实例将被全部卸载。请仔细确认。一旦卸载,全部数据目录、数据库和实例信息将被删除,并且无法恢复。";
                    dlg.UninstallMode = true;
                    dlg.CopyFiles += dlg_dp2Library_CopyFiles;
                    dlg.StartPosition = FormStartPosition.CenterScreen;
                    dlg.ShowDialog(this);

                    if (dlg.DialogResult == DialogResult.Cancel)
                    {
                        AppendString("放弃卸载\r\n");
                        return;
                    }

                    if (string.IsNullOrEmpty(dlg.DebugInfo) == false)
                        AppendString("卸载实例时的调试信息:\r\n" + dlg.DebugInfo + "\r\n");

                    if (dlg.Changed == true)
                    {
                        // 兑现修改

                    }

                    AppendString("注销 Windows Service 开始\r\n");

                    Application.DoEvents();

                    // 注销 Windows Service
                    nRet = InstallService(strExePath,
            false,
            out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    AppendString("注销 Windows Service 结束\r\n");

                // 删除程序目录
                REDO_DELETE_PROGRAMDIR:
                    try
                    {
                        PathUtil.DeleteDirectory(Path.GetDirectoryName(strExePath));
                    }
                    catch (Exception ex)
                    {
                        DialogResult temp_result = MessageBox.Show(this,
        "删除程序目录 '" + Path.GetDirectoryName(strExePath) + "' 出错:" + ex.Message + "\r\n\r\n是否重试?\r\n\r\n(Retry: 重试; Cancel: 不重试,继续后续卸载过程)",
        "卸载 dp2Library",
        MessageBoxButtons.RetryCancel,
        MessageBoxIcon.Question,
        MessageBoxDefaultButton.Button1);
                        if (temp_result == DialogResult.Retry)
                            goto REDO_DELETE_PROGRAMDIR;
                    }

                    this.Refresh_dp2library_MenuItems();
                }
                finally
                {
                    AppendSectionTitle("卸载 dp2library 结束");
                }

            }
            finally
            {
                this._floatingMessage.Text = "";
            }
            return;
        ERROR1:
            AppendString("出错: " + strError + "\r\n");
            MessageBox.Show(this, strError);
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: paopaofeng/dp2
        private void MenuItem_dp2library_instanceManagement_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

            bool bControl = Control.ModifierKeys == Keys.Control;
            bool bInstalled = true;

            this._floatingMessage.Text = "正在配置 dp2library 实例 ...";

            try
            {
                AppendSectionTitle("配置实例开始");

                AppendString("正在获得可执行文件目录 ...\r\n");

                Application.DoEvents();

                string strExePath = GetPathOfService("dp2LibraryService");
                if (string.IsNullOrEmpty(strExePath) == true)
                {
                    if (bControl == false)
                    {
                        strError = "dp2library 未曾安装过";
                        goto ERROR1;
                    }
                    bInstalled = false;
                }

                //strExePath = Unquote(strExePath);
                //string strRootDir = Path.GetDirectoryName(strExePath);

                // MessageBox.Show(this, "为进行配置,将首先停止 dp2library 服务。配置完成后 dp2library 会重新启动");

                if (bInstalled == true)
                {
                    AppendString("正在停止 dp2library 服务 ...\r\n");

                    nRet = StopService("dp2LibraryService",
            out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    AppendString("dp2library 服务已经停止\r\n");
                }

                List<string> new_instance_names = null;

                try
                {
                    DigitalPlatform.LibraryServer.InstanceDialog dlg = new DigitalPlatform.LibraryServer.InstanceDialog();
                    GuiUtil.AutoSetDefaultFont(dlg);

                    // dlg.SourceDir = strRootDir;
                    dlg.CopyFiles += dlg_dp2Library_CopyFiles;
                    dlg.StartPosition = FormStartPosition.CenterScreen;
                    dlg.ShowDialog(this);

                    if (dlg.DialogResult == DialogResult.Cancel)
                        return;

                    if (string.IsNullOrEmpty(dlg.DebugInfo) == false)
                        AppendString("创建实例时的调试信息:\r\n" + dlg.DebugInfo + "\r\n");

                    if (dlg.Changed == true)
                    {
                        // 兑现修改

                    }

                    new_instance_names = dlg.NewInstanceNames;
                }
                finally
                {
                    if (bInstalled == true)
                    {
                        AppendString("正在重新启动 dp2library 服务 ...\r\n");
                        nRet = StartService("dp2LibraryService",
        out strError);
                        if (nRet == -1)
                        {
                            AppendString("dp2library 服务启动失败: " + strError + "\r\n");
                            MessageBox.Show(this, strError);
                        }
                        else
                        {
                            AppendString("dp2library 服务启动成功\r\n");
                        }
                    }

                    AppendSectionTitle("配置实例结束");
                }

                CreateDefaultDatabases(new_instance_names);
            }
            finally
            {
                this._floatingMessage.Text = "";
            }
            return;
        ERROR1:
            AppendString("出错: " + strError + "\r\n");
            MessageBox.Show(this, strError);
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: paopaofeng/dp2
        // 首次安装 dp2library
        private void MenuItem_dp2library_install_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

            this._floatingMessage.Text = "正在安装 dp2library - 图书馆应用服务器 ...";
            try
            {

                AppendSectionTitle("安装 dp2library 开始");

                AppendString("正在获得可执行文件目录 ...\r\n");

                Application.DoEvents();

                string strExePath = GetPathOfService("dp2LibraryService");
                if (string.IsNullOrEmpty(strExePath) == false)
                {
                    strError = "dp2library 已经安装过了,不能重复安装";
                    goto ERROR1;
                }
                // strExePath = Unquote(strExePath);

                // program files (x86)/digitalplatform/dp2library
                string strProgramDir = GetProductDirectory("dp2library");

                PathUtil.CreateDirIfNeed(strProgramDir);

                string strZipFileName = Path.Combine(this.DataDir, "library_app.zip");

                AppendString("安装可执行文件 ...\r\n");

                // 更新可执行目录
                // return:
                //      -1  出错
                //      0   没有必要刷新
                //      1   已经刷新
                nRet = RefreshBinFiles(
                    false,
                    strZipFileName,
                    strProgramDir,
                    null,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                // 还需要把 library_data.zip 的内容都展开到程序目录的 temp 子目录中,以兼容以前的 Installer 功能
                string strTempDir = Path.Combine(strProgramDir, "temp");
                PathUtil.CreateDirIfNeed(strTempDir);
                nRet = dp2Library_extractPartDir(strTempDir,
        "cfgs,templates,other",
        out strError);
                if (nRet == -1)
                    goto ERROR1;

                List<string> new_instance_names = null;

                // 创建实例
                AppendString("创建实例 ...\r\n");

                try
                {

                    DigitalPlatform.LibraryServer.InstanceDialog dlg = new DigitalPlatform.LibraryServer.InstanceDialog();
                    GuiUtil.AutoSetDefaultFont(dlg);

                    // dlg.DataZipFileName = Path.Combine(this.DataDir, "library_data.zip");
                    dlg.CopyFiles += dlg_dp2Library_CopyFiles;
                    dlg.StartPosition = FormStartPosition.CenterScreen;
                    dlg.ShowDialog(this);   // ForegroundWindow.Instance

                    // TODO: 是否必须要创建至少一个实例?
                    if (dlg.DialogResult == DialogResult.Cancel)
                    {
                        AppendSectionTitle("放弃创建实例 ...");
                        return;
                    }

                    if (string.IsNullOrEmpty(dlg.DebugInfo) == false)
                        AppendString("创建实例时的调试信息:\r\n" + dlg.DebugInfo + "\r\n");

                    if (dlg.Changed == true)
                    {
                        // 兑现修改

                    }

                    new_instance_names = dlg.NewInstanceNames;
                }
                finally
                {
                    AppendString("创建实例结束 ...\r\n");
                }


                // 注册为 Windows Service
                strExePath = Path.Combine(strProgramDir, "dp2library.exe");

                AppendString("注册 Windows Service ...\r\n");

                nRet = InstallService(strExePath,
        true,
        out strError);
                if (nRet == -1)
                    goto ERROR1;

                AppendSectionTitle("安装 dp2library 结束");
                Refresh_dp2library_MenuItems();

                CreateDefaultDatabases(new_instance_names);
            }
            finally
            {
                this._floatingMessage.Text = "";
            }
            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }