/* 发生未捕获的界面线程异常: Type: System.ComponentModel.Win32Exception Message: 找不到应用程序 Stack: 在 System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) 在 System.Diagnostics.Process.Start() 在 System.Diagnostics.Process.Start(ProcessStartInfo startInfo) 在 System.Diagnostics.Process.Start(String fileName) 在 dp2LibraryXE.MainForm.MenuItem_installDp2Opac_Click(Object sender, EventArgs e) 在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e) 在 System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e) 在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) 在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) 在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met) 在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met) 在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) 在 System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea) 在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 在 System.Windows.Forms.Control.WndProc(Message& m) 在 System.Windows.Forms.ScrollableControl.WndProc(Message& m) 在 System.Windows.Forms.ToolStrip.WndProc(Message& m) 在 System.Windows.Forms.ToolStripDropDown.WndProc(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) * */ // 安装 dp2OPAC private void MenuItem_installDp2Opac_Click(object sender, EventArgs e) { string strError = ""; int nRet = 0; AppendSectionTitle("开始安装 dp2OPAC"); bool bForce = false; if (Control.ModifierKeys == Keys.Control) { AppendString("强制安装\r\n"); bForce = true; } if (bForce == false) { if (Environment.OSVersion.Version.Major >= 6) { } else { strError = "当前 Windows 操作系统版本太低,无法安装使用 IIS Express 8.0"; goto ERROR1; } } // 首先安装 IIS Express 8 string fileName = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "iis express\\iisexpress.exe"); if (bForce == false) { if (File.Exists(fileName) == true && FileVersionInfo.GetVersionInfo(fileName).FileMajorPart >= 8) { } else { // 安装 IIS Express 8 strError = "需要先安装 IIS Express 8.0。\r\n\r\n安装完 IIS Express 后,请重新执行本命令"; AppendString(strError + "\r\n"); this.AppInfo.SetBoolean("OPAC", "installed", false); this.AppInfo.Save(); MessageBox.Show(this, strError); string install_url = "http://www.microsoft.com/zh-cn/download/details.aspx?id=34679"; try { Process.Start(install_url); } catch (Exception ex) { MessageBox.Show(this, "打开 URL '" + install_url + "' 失败: " + ex.Message); } return; } } #if NO _messageBar = new MessageBar(); _messageBar.TopMost = false; _messageBar.Font = this.Font; _messageBar.BackColor = SystemColors.Info; _messageBar.ForeColor = SystemColors.InfoText; _messageBar.Text = "dp2Library XE"; _messageBar.MessageText = "正在安装 dp2OPAC,请等待 ..."; _messageBar.StartPosition = FormStartPosition.CenterScreen; // _messageBar.TopMost = true; _messageBar.Show(this); _messageBar.Update(); #endif this._floatingMessage.Text = "正在安装 dp2OPAC,请等待 ..."; Application.DoEvents(); try { // 安装 dp2OPAC 的数据目录 // parameters: // bAutoSetup 是否自动安装。自动安装时,如果已经存在数据文件,则不会再次安装。否则会强行重新安装,但安装前会出现对话框警告 nRet = SetupOpacDataAndAppDir( false, out strError); if (nRet == -1 || nRet == 0) goto ERROR1; nRet = RegisterWebApp(out strError); if (nRet == -1) goto ERROR1; this.AppInfo.SetBoolean("OPAC", "installed", true); this.AppInfo.Save(); } finally { #if NO _messageBar.Close(); _messageBar = null; #endif this._floatingMessage.Text = ""; } string strInformation = "dp2OPAC 安装完成。\r\n\r\n在本机可以使用 " + localhost_opac_url + " 访问"; AppendString(strInformation + "\r\n"); // 检查当前超级用户帐户是否为空密码 // return: // -1 检查中出错 // 0 空密码 // 1 已经设置了密码 nRet = CheckNullPassword(out strError); if (nRet == -1) MessageBox.Show(this, "检查超级用户密码的过程出错: " + strError); if (nRet == 0) { MessageBox.Show(this, strInformation); MessageBox.Show(this, "当前超级用户 " + this.SupervisorUserName + " 的密码为空,如果启动 dp2OPAC,其他人将可能通过浏览器冒用此账户。\r\n\r\n请(使用 dp2circulation (内务前端))为此账户设置密码,然后重新启动 dp2libraryXE。\r\n\r\n为确保安全,本次未启动 dp2OPAC", "dp2library XE 警告", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { // MessageBox.Show(this, "即将启动 IIS Express。不要关闭这个窗口"); // return: // -1 出错 // 0 程序文件不存在 // 1 成功启动 nRet = StartIIsExpress("dp2Site", true, out strError); if (nRet != 1) goto ERROR1; MessageBox.Show(this, strInformation); try { Process.Start(localhost_opac_url); } catch (Exception ex) { MessageBox.Show(this, "打开 URL '" + localhost_opac_url + "' 失败: " + ex.Message); } } AppendSectionTitle("结束安装 dp2OPAC"); return; ERROR1: AppendString(strError + "\r\n"); this.AppInfo.SetBoolean("OPAC", "installed", false); this.AppInfo.Save(); MessageBox.Show(this, strError); }
private void MenuItem_updateDp2Opac_Click(object sender, EventArgs e) { string strError = ""; int nRet = 0; AppendSectionTitle("开始升级 dp2OPAC"); bool bForce = false; if (Control.ModifierKeys == Keys.Control) { AppendString("强制安装\r\n"); bForce = true; } if (bForce == false) { if (Environment.OSVersion.Version.Major >= 6) { } else { strError = "当前 Windows 操作系统版本太低,无法安装使用 IIS Express 8.0"; goto ERROR1; } } string fileName = Path.Combine( this.OpacAppDir, "book.aspx"); if (bForce == false) { if (File.Exists(fileName) == true) { } else { strError = "尚未安装 dp2OPAC"; goto ERROR1; } } #if NO _messageBar = new MessageBar(); _messageBar.TopMost = false; _messageBar.Font = this.Font; _messageBar.BackColor = SystemColors.Info; _messageBar.ForeColor = SystemColors.InfoText; _messageBar.Text = "dp2Library XE"; _messageBar.MessageText = "正在升级 dp2OPAC,请等待 ..."; _messageBar.StartPosition = FormStartPosition.CenterScreen; // _messageBar.TopMost = true; _messageBar.Show(this); _messageBar.Update(); #endif this._floatingMessage.Text = "正在升级 dp2OPAC,请等待 ..."; Application.DoEvents(); try { nRet = dp2OPAC_UpdateAppDir(true, out strError); if (nRet == -1) goto ERROR1; } finally { #if NO _messageBar.Close(); _messageBar = null; #endif this._floatingMessage.Text = ""; } AppendSectionTitle("结束升级 dp2OPAC"); return; ERROR1: AppendString(strError + "\r\n"); MessageBox.Show(this, strError); }
// return: // -1 出错。包括出错后重试然后放弃 // 0 成功 int DeleteDataDir(string strDataDir, out string strError) { strError = ""; REDO_DELETE_DATADIR: try { MessageBar bar = new MessageBar(); bar.MessageText = "正在删除目录 '" + strDataDir + "',请等待 ..."; bar.StartPosition = FormStartPosition.CenterScreen; bar.Show(this); bar.Update(); try { Directory.Delete(strDataDir, true); } finally { bar.Close(); } return 0; } catch (Exception ex) { strError = "删除数据目录 '" + strDataDir + "' 时出错: " + ex.Message; } DialogResult temp_result = MessageBox.Show(ForegroundWindow.Instance, strError + "\r\n\r\n是否重试?", "删除数据目录 '" + strDataDir + "'", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (temp_result == DialogResult.Retry) goto REDO_DELETE_DATADIR; return -1; }
// 启动后要执行的初始化操作 void Initialize() { string strError = ""; int nRet = 0; #if SN nRet = VerifySerialCode(out strError); if (nRet == -1) { Application.Exit(); return; } GetMaxClients(); GetLicenseType(); GetFunction(); #else this.MenuItem_resetSerialCode.Visible = false; #endif #if NO _messageBar = new MessageBar(); _messageBar.TopMost = false; _messageBar.Font = this.Font; _messageBar.BackColor = SystemColors.Info; _messageBar.ForeColor = SystemColors.InfoText; _messageBar.Text = "dp2Library XE"; _messageBar.MessageText = "正在启动 dp2Library XE,请等待 ..."; _messageBar.StartPosition = FormStartPosition.CenterScreen; _messageBar.Show(this); _messageBar.Update(); #endif this._floatingMessage.Text = "正在启动 dp2Library XE,请等待 ..."; Application.DoEvents(); try { nRet = CopyUserBinDirectory(out strError); if (nRet == -1) { MessageBox.Show(this, "复制用户目录的 bin 子目录到程序目录时出错: " + strError); } // 首次运行自动安装数据目录 { nRet = SetupKernelDataDir( true, out strError); if (nRet == -1) { WriteKernelEventLog("dp2Library XE 自动初始化数据目录出错: " + strError, EventLogEntryType.Error); MessageBox.Show(this, strError); } else { WriteKernelEventLog("dp2Library XE 自动初始化数据目录成功", EventLogEntryType.Information); } nRet = SetupLibraryDataDir( true, out strError); if (nRet == -1) { WriteLibraryEventLog("dp2Library XE 自动初始化数据目录出错: " + strError, EventLogEntryType.Error); MessageBox.Show(this, strError); } else { WriteLibraryEventLog("dp2Library XE 自动初始化数据目录成功", EventLogEntryType.Information); } } // 更新数据目录 UpdateCfgs(); // 启动两个后台服务 nRet = dp2Kernel_start(true, out strError); if (nRet == -1) { WriteKernelEventLog("dp2Library XE 启动 dp2Kernel 时出错: " + strError, EventLogEntryType.Error); MessageBox.Show(this, strError); } nRet = dp2Library_start(true, out strError); if (nRet == -1) { WriteLibraryEventLog("dp2Library XE 启动 dp2Library 时出错: " + strError, EventLogEntryType.Error); MessageBox.Show(this, strError); } bool bInstalled = this.AppInfo.GetBoolean("OPAC", "installed", false); if (bInstalled == true) { nRet = dp2OPAC_UpdateAppDir(false, out strError); if (nRet == -1) MessageBox.Show(this, "自动升级 dp2OPAC 程序目录过程出错: " + strError); // 2015/7/17 // 自动升级 dp2OPAC 的数据目录中的 style 子目录 // 使用 opac_style.zip 来更新 // 更新 dp2OPAC 数据目录中的 style 子目录 // parameters: // bAuto 是否自动更新。true 表示(.zip 文件发生了变化)有必要才更新; false 表示无论如何均更新 nRet = UpdateOpacStyles(true, out strError); if (nRet == -1) MessageBox.Show(this, "自动升级 dp2OPAC 数据目录的 style 子目录过程出错: " + strError); // 检查当前超级用户帐户是否为空密码 // return: // -1 检查中出错 // 0 空密码 // 1 已经设置了密码 nRet = CheckNullPassword(out strError); if (nRet == -1) MessageBox.Show(this, "检查超级用户密码的过程出错: " + strError); if (nRet == 0) { AutoCloseMessageBox.Show(this, "当前超级用户 " + this.SupervisorUserName + " 的密码为空,如果启动 dp2OPAC,其他人将可能通过浏览器冒用此账户。\r\n\r\n请(使用 dp2circulation (内务前端))为此账户设置密码,然后重新启动 dp2libraryXE。\r\n\r\n为确保安全,本次未启动 dp2OPAC", 20 * 1000, "dp2library XE 警告"); #if NO MessageBox.Show(this, "当前超级用户 " + this.SupervisorUserName + " 的密码为空,如果启动 dp2OPAC,其他人将可能通过浏览器冒用此账户。\r\n\r\n请(使用 dp2circulation (内务前端))为此账户设置密码,然后重新启动 dp2libraryXE。\r\n\r\n为确保安全,本次未启动 dp2OPAC", "dp2library XE 警告", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif } else { // return: // -1 出错 // 0 程序文件不存在 // 1 成功启动 nRet = StartIIsExpress("dp2Site", true, out strError); if (nRet != 1) MessageBox.Show(this, strError); } } // 2014/11/16 try { EventWaitHandle.OpenExisting("dp2libraryXE V1 library host started").Set(); } catch { } } finally { #if NO _messageBar.Close(); _messageBar = null; #endif this._floatingMessage.Text = ""; this.SetTitle(); } #if NO if (this.AutoStartDp2circulation == true) { try { System.Diagnostics.Process.Start("http://dp2003.com/dp2circulation/v2/dp2circulation.application"); } catch (Exception ex) { MessageBox.Show(this, "启动 dp2Circulation 时出错: " + ex.Message); } } #endif }
public static void CrashReport(string strText) { // MainForm main_form = Form.ActiveForm as MainForm; MessageBar _messageBar = null; _messageBar = new MessageBar(); _messageBar.TopMost = false; //_messageBar.BackColor = SystemColors.Info; //_messageBar.ForeColor = SystemColors.InfoText; _messageBar.Text = "dp2Catalog 出现异常"; _messageBar.MessageText = "正在向 dp2003.com 发送异常报告 ..."; _messageBar.StartPosition = FormStartPosition.CenterScreen; _messageBar.Show(_mainForm); _messageBar.Update(); int nRet = 0; string strError = ""; try { string strSender = ""; // if (_mainForm != null) strSender = "@MAC:" + GetMacAddressString(); // 崩溃报告 nRet = LibraryChannel.CrashReport( strSender, "dp2catalog", strText, out strError); } catch (Exception ex) { strError = "CrashReport() 过程出现异常: " + ExceptionUtil.GetDebugText(ex); nRet = -1; } finally { _messageBar.Close(); _messageBar = null; } if (nRet == -1) { strError = "向 dp2003.com 发送异常报告时出错,未能发送成功。详细情况: " + strError; MessageBox.Show(_mainForm, strError); // 写入错误日志 if (_mainForm != null) _mainForm.WriteErrorLog(strError); else WriteWindowsLog(strError, EventLogEntryType.Error); } }
// 验证性连接服务器 int TestConnectServer(out string strError) { strError = ""; MessageBar _messageBar = null; _messageBar = new MessageBar(); _messageBar.TopMost = false; _messageBar.Font = this.Font; _messageBar.BackColor = SystemColors.Info; _messageBar.ForeColor = SystemColors.InfoText; _messageBar.Text = "欢迎使用 dp2Catalog"; _messageBar.MessageText = "正在验证连接服务器,请等待 ..."; _messageBar.StartPosition = FormStartPosition.CenterScreen; _messageBar.Show(this); _messageBar.Update(); try { int nRet = TouchServer(true, out strError); if (nRet == -1) return -1; return 0; } finally { _messageBar.Close(); _messageBar = null; } }
// parameters: // bLocal 是否从本地启动。 false 表示连安装带启动 public static void StartDp2libraryXe( IWin32Window owner, string strDialogTitle, Font font, bool bLocal) { MessageBar messageBar = null; messageBar = new MessageBar(); messageBar.TopMost = false; if (font != null) messageBar.Font = font; messageBar.BackColor = SystemColors.Info; messageBar.ForeColor = SystemColors.InfoText; messageBar.Text = "dp2 内务"; messageBar.MessageText = "正在启动 dp2Library XE,请等待 ..."; messageBar.StartPosition = FormStartPosition.CenterScreen; messageBar.Show(owner); messageBar.Update(); Application.DoEvents(); try { TimeSpan waitTime = new TimeSpan(0, 1, 0); string strShortcutFilePath = ""; if (bLocal == true) strShortcutFilePath = PathUtil.GetShortcutFilePath("DigitalPlatform/dp2 V2/dp2Library XE"); else { strShortcutFilePath = "http://dp2003.com/dp2libraryxe/v1/dp2libraryxe.application"; waitTime = new TimeSpan(0, 5, 0); // 安装需要的等待时间更长 } // TODO: detect if already started using (EventWaitHandle eventWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset, "dp2libraryXE V1 library host started")) { Application.DoEvents(); Process.Start(strShortcutFilePath); DateTime start = DateTime.Now; while (true) { Application.DoEvents(); // wait till started // http://stackoverflow.com/questions/6816782/windows-net-cross-process-synchronization if (eventWaitHandle.WaitOne(100, false) == true) break; // if timeout, prompt continue wait if (DateTime.Now - start > waitTime) { DialogResult result = MessageBox.Show(owner, "dp2libraryXE 暂时没有响应。\r\n\r\n是否继续等待其响应?", strDialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == System.Windows.Forms.DialogResult.No) break; start = DateTime.Now; // } } } } finally { messageBar.Close(); } }
// 验证性连接服务器 int TestConnectServer(out string strError) { strError = ""; // 如果是即将访问 dp2libraryXE 单机版,这里要启动它 if (string.Compare(this.textBox_server_dp2LibraryServerUrl.Text, CirculationLoginDlg.dp2LibraryXEServerUrl, true) == 0) { string strShortcutFilePath = PathUtil.GetShortcutFilePath("DigitalPlatform/dp2 V2/dp2Library XE"); if (File.Exists(strShortcutFilePath) == false) { // 安装和启动 DialogResult result = MessageBox.Show(this, "dp2libraryXE 在本机尚未安装。\r\ndp2Circulation (内务)即将访问 dp2LibraryXE 单机版服务器,需要安装它才能正常使用。\r\n\r\n是否立即从 dp2003.com 下载安装?", "dp2Circulation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == System.Windows.Forms.DialogResult.Yes) StartDp2libraryXe( this, "dp2Circulation", this.Font, false); } else { if (HasDp2libraryXeStarted() == false) { StartDp2libraryXe( this, "dp2Circulation", this.Font, true); } } } MessageBar _messageBar = null; _messageBar = new MessageBar(); _messageBar.TopMost = false; _messageBar.Font = this.Font; _messageBar.BackColor = SystemColors.Info; _messageBar.ForeColor = SystemColors.InfoText; _messageBar.Text = "欢迎使用 dp2Circulation"; _messageBar.MessageText = "正在验证连接服务器,请等待 ..."; _messageBar.StartPosition = FormStartPosition.CenterScreen; _messageBar.Show(this); _messageBar.Update(); try { int nRet = TouchServer(true, out strError); if (nRet == -1) return -1; return 0; } finally { _messageBar.Close(); _messageBar = null; } }
// 2015/9/15 public static void EnvironmentReport(MainForm mainForm) { #if NO MessageBar _messageBar = null; _messageBar = new MessageBar(); _messageBar.TopMost = false; //_messageBar.BackColor = SystemColors.Info; //_messageBar.ForeColor = SystemColors.InfoText; _messageBar.Text = "dp2Circulation 出现异常"; _messageBar.MessageText = "正在向 dp2003.com 发送异常报告 ..."; _messageBar.StartPosition = FormStartPosition.CenterScreen; _messageBar.Show(_mainForm); _messageBar.Update(); #endif int nRet = 0; string strError = ""; try { string strSender = ""; if (mainForm != null) strSender = mainForm.GetCurrentUserName() + "@" + mainForm.ServerUID; // 崩溃报告 nRet = LibraryChannel.CrashReport( strSender, "dp2circulation 环境报告", GetEnvironmentDescription().Replace("\t", " "), out strError); } catch (Exception ex) { strError = "CrashReport() 过程出现异常: " + ExceptionUtil.GetDebugText(ex); nRet = -1; } finally { #if NO _messageBar.Close(); _messageBar = null; #endif } #if NO if (nRet == -1) { strError = "向 dp2003.com 发送异常报告时出错,未能发送成功。详细情况: " + strError; MessageBox.Show(_mainForm, strError); // 写入错误日志 if (_mainForm != null) _mainForm.WriteErrorLog(strError); else WriteWindowsLog(strError, EventLogEntryType.Error); } #endif }