public override void Install(System.Collections.IDictionary stateSaver) { base.Install(stateSaver); string strParameter = this.Context.Parameters["rootdir"]; if (string.IsNullOrEmpty(strParameter) == true) { return; } #if NO string strRootDir = UnQuote(this.Context.Parameters["rootdir"]); InstanceDialog dlg = new InstanceDialog(); GuiUtil.AutoSetDefaultFont(dlg); dlg.SourceDir = strRootDir; dlg.StartPosition = FormStartPosition.CenterScreen; dlg.ShowDialog(ForegroundWindow.Instance); if (dlg.DialogResult == DialogResult.Cancel) { throw new InstallException("用户取消安装。"); } if (dlg.Changed == true) { // 兑现修改 } #endif }
public override void Uninstall(System.Collections.IDictionary savedState) { // Debug.Assert(false, ""); base.Uninstall(savedState); string strParameter = this.Context.Parameters["rootdir"]; if (string.IsNullOrEmpty(strParameter) == true) { return; } #if NO String strRootDir = UnQuote(strParameter); DialogResult result; string strText = "是否完全卸载?\r\n\r\n" + "单击'是',则把全部实例的数据目录删除,所有的库配置信息丢失,所有的实例信息丢失。以后安装时需要重新安装数据目录和数据库。\r\n\r\n" + "单击'否',不删除数据目录,仅卸载执行程序,下次安装时可以继续使用已存在的库配置信息。升级安装前的卸载应选此项。"; result = MessageBox.Show(ForegroundWindow.Instance, strText, "卸载 dp2Library", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == DialogResult.Yes) { InstanceDialog dlg = new InstanceDialog(); GuiUtil.AutoSetDefaultFont(dlg); dlg.Text = "彻底卸载所有实例和数据目录"; dlg.Comment = "下列实例将被全部卸载。请仔细确认。一旦卸载,全部数据目录和实例信息将被删除,并且无法恢复。"; dlg.UninstallMode = true; dlg.SourceDir = strRootDir; dlg.StartPosition = FormStartPosition.CenterScreen; dlg.ShowDialog(ForegroundWindow.Instance); if (dlg.DialogResult == DialogResult.Cancel) { MessageBox.Show(ForegroundWindow.Instance, "已放弃卸载全部实例和数据目录。仅仅卸载了可执行程序。"); } } #endif }
private void button_OK_Click(object sender, EventArgs e) { string strError = ""; // 检查 // 数据目录 if (String.IsNullOrEmpty(this.textBox_dataDir.Text) == true) { strError = "尚未指定数据目录"; goto ERROR1; } // dp2Kernel服务器信息 if (String.IsNullOrEmpty(this.textBox_dp2KernelDef.Text) == true) { strError = "尚未指定dp2Kernel服务器信息"; goto ERROR1; } // 协议绑定 if (String.IsNullOrEmpty(this.textBox_bindings.Text) == true) { strError = "尚未指定协议绑定信息"; goto ERROR1; } // 图书馆名 if (String.IsNullOrEmpty(this.textBox_libraryName.Text) == true) { strError = "尚未指定图书馆名"; goto ERROR1; } if (this.LineInfo == null) { this.LineInfo = new LineInfo(); } this.LineInfo.LibraryName = this.textBox_libraryName.Text; this.LineInfo.UpdateCfgsDir = this.checkBox_updateCfgsDir.Checked; // 检查是否为旧式url地址 string strKernelUrl = this.LineInfo.KernelUrl; if (strKernelUrl.IndexOf(".asmx") != -1) { strError = "安装程序发现当前使用了旧版本数据库内核的地址 '" + strKernelUrl + "',需要您将它修改为新版dp2Kernel(内核)的URL地址。"; goto ERROR1; } if (this.IsNew == true && this.m_bDataDirExist == false) { // supervisor用户信息 if (this.LineInfo.SupervisorUserName == null || this.LineInfo.SupervisorPassword == null || this.LineInfo.SupervisorRights == null) { strError = "尚未设定supervisor账户的用户名、密码、权限"; 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) { // supervisor用户信息 if (this.LineInfo.SupervisorUserName == null || this.LineInfo.SupervisorPassword == null || this.LineInfo.SupervisorRights == null) { strError = "尚未设定supervisor账户的用户名、密码、权限"; 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.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); }