Ejemplo n.º 1
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            string strError = "";

            // 检查

            // 数据目录
            if (String.IsNullOrEmpty(this.textBox_dataDir.Text) == true)
            {
                strError = "尚未指定数据目录";
                goto ERROR1;
            }

            if (String.IsNullOrEmpty(this.comboBox_sqlServerType.Text) == true)
            {
                strError = "尚未指定 SQL 服务器类型";
                goto ERROR1;
            }

            // sql服务器信息
            if (String.IsNullOrEmpty(this.textBox_sqlDef.Text) == true)
            {
                strError = "尚未指定 SQL 服务器信息";
                goto ERROR1;
            }

            // 协议绑定
            if (String.IsNullOrEmpty(this.textBox_bindings.Text) == true)
            {
                strError = "尚未指定协议绑定信息";
                goto ERROR1;
            }


            if (this.IsNew == true &&
                this.m_bDataDirExist == false)
            {
                // root用户信息
                if (this.LineInfo.RootUserName == null ||
                    this.LineInfo.RootPassword == null ||
                    this.LineInfo.RootUserRights == null)
                {
                    strError = "尚未设定root账户的用户名、密码、权限";
                    goto ERROR1;
                }
            }

            // 如果修改时,需要创建新的数据目录
            if (this.IsNew == false)
            {
                // 探测数据目录,是否已经存在数据,是不是属于升级情形
                // return:
                //      -1  error
                //      0   数据目录不存在
                //      1   数据目录存在,但是xml文件不存在
                //      2   xml文件已经存在
                int nRet = InstanceDialog.DetectDataDir(this.textBox_dataDir.Text,
                                                        out strError);
                if (nRet == -1)
                {
                    strError = "探测数据目录 '" + this.textBox_dataDir.Text + "' 是否存在时,出现错误: " + strError;
                    goto ERROR1;
                }

                if (nRet == 0 || nRet == 1)
                {
                    // root用户信息
                    if (this.LineInfo.RootUserName == null ||
                        this.LineInfo.RootPassword == null ||
                        this.LineInfo.RootUserRights == null)
                    {
                        strError = "尚未设定root账户的用户名、密码、权限";
                        goto ERROR1;
                    }
                }
            }

            // TODO: 如果在编辑状态,需要排除和listview中自己重的情况

            if (this.VerifyInstanceName != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.textBox_instanceName.Text;
                this.VerifyInstanceName(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            if (this.VerifyDataDir != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.textBox_dataDir.Text;
                this.VerifyDataDir(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            if (this.VerifyDatabases != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value  = this.textBox_dataDir.Text;
                e1.Value1 = this.textBox_instanceName.Text;
                this.VerifyDatabases(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            if (this.VerifyBindings != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.textBox_bindings.Text;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
            return;

ERROR1:
            MessageBox.Show(this, strError);
        }
Ejemplo n.º 2
0
        // 首次安装 dp2kernel
        private void MenuItem_dp2kernel_install_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

            this._floatingMessage.Text = "正在安装 dp2kernel - 数据库内核 ...";

            try
            {
                AppendSectionTitle("安装 dp2kernel 开始");

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

                Application.DoEvents();

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

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

                PathUtil.CreateDirIfNeed(strProgramDir);

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

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

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

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

                try
                {

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

                    // dlg.SourceDir = strRootDir;
                    dlg.DataZipFileName = Path.Combine(this.DataDir, "kernel_data.zip");
                    dlg.StartPosition = FormStartPosition.CenterScreen;
                    dlg.ShowDialog(this);

                    // 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)
                    {
                        // 兑现修改

                    }

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


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

#if NO
            try
            {
                ManagedInstallerClass.InstallHelper(new[] { strExePath });
            }
            catch (Exception ex)
            {
                strError = "注册 Windows Service 的过程发生错误: " + ex.Message;
                goto ERROR1;
            }
#endif
                AppendString("注册 Windows Service ...\r\n");

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

#if NO
            AppendString("启动 dp2kernel 服务 ...\r\n");
            nRet = StartService("dp2KernelService",
    out strError);
            if (nRet == -1)
                goto ERROR1;
            AppendString("dp2kernel 服务启动成功\r\n");
#endif

                AppendSectionTitle("安装 dp2kernel 结束");
                Refresh_dp2kernel_MenuItems();
            }
            finally
            {
                this._floatingMessage.Text = "";
            }
            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Ejemplo n.º 3
0
        // 卸载 dp2kernel
        // TODO: 可以仿照卸载 dp2library 过程重新编写。到底是先注销 Service,还是先删除数据实例 ?
        private void MenuItem_dp2kernel_uninstall_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

            this._floatingMessage.Text = "正在卸载 dp2kernel - 数据库内核 ...";

            try
            {
                AppendSectionTitle("卸载 dp2Kernel 开始");

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

                Application.DoEvents();

                string strExePath = GetPathOfService("dp2KernelService");
                if (string.IsNullOrEmpty(strExePath) == true)
                {
                    strError = "dp2kernel 尚未安装和注册为 Windows Service,无法进行注销";
                    goto ERROR1;
                }
                strExePath = Unquote(strExePath);

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

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

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

#if NO
            DialogResult result = MessageBox.Show(this,
"确实要卸载 dp2Kernel? ",
"dp2Install",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
            if (result != DialogResult.Yes)
                return;   // cancelled
#endif


                {
                    DigitalPlatform.rms.InstanceDialog dlg = new DigitalPlatform.rms.InstanceDialog();
                    GuiUtil.AutoSetDefaultFont(dlg);
                    dlg.Text = "dp2Kernel - 彻底卸载所有实例和数据目录";
                    dlg.Comment = "下列实例将被全部卸载。请仔细确认。一旦卸载,全部数据目录、数据库和实例信息将被删除,并且无法恢复。";
                    dlg.UninstallMode = true;
                    dlg.SourceDir = ""; // Path.GetDirectoryName(strExePath);
                    dlg.StartPosition = FormStartPosition.CenterScreen;
                    dlg.ShowDialog(this);

                    if (dlg.DialogResult == DialogResult.Cancel)
                    {
                        MessageBox.Show(this,
                            "已放弃卸载全部实例和数据目录。仅仅卸载了执行程序。");
                    }
                    else
                    {
                        AppendString("已删除全部数据目录\r\n");
                    }
                }


                // 探测 .exe 是否为新版本。新版本中 Installer.Uninstall 动作不会删除数据目录

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

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

                AppendString("删除程序目录\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: 不重试,继续后续卸载过程)",
    "卸载 dp2Kernel",
    MessageBoxButtons.RetryCancel,
    MessageBoxIcon.Question,
    MessageBoxDefaultButton.Button1);
                    if (temp_result == DialogResult.Retry)
                        goto REDO_DELETE_PROGRAMDIR;
                }

                AppendSectionTitle("卸载 dp2Kernel 结束");
                this.Refresh_dp2kernel_MenuItems();
            }
            finally
            {
                this._floatingMessage.Text = "";
            }
            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Ejemplo n.º 4
0
        private void MenuItem_dp2kernel_instanceManagement_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

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

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

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

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

                Application.DoEvents();

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

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

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

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

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

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


                try
                {

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

                    // dlg.SourceDir = strRootDir;
                    dlg.DataZipFileName = Path.Combine(this.DataDir, "kernel_data.zip");
                    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)
                    {
                        // 兑现修改

                    }

                }
                finally
                {

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

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

            }
            finally
            {
                this._floatingMessage.Text = "";
            }
            return;
        ERROR1:
            AppendString("出错: " + strError + "\r\n");
            MessageBox.Show(this, strError);
        }