// 验证性连接服务器 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; } }
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 = "dp2Circulation 出现异常"; _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 = _mainForm.GetCurrentUserName() + "@" + _mainForm.ServerUID; } // 崩溃报告 nRet = LibraryChannel.CrashReport( strSender, "dp2circulation", 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); } } }
static void CrashReport(string strText) { MessageBar _messageBar = null; _messageBar = new MessageBar { TopMost = false, Text = $"{ProgramName} 出现异常", MessageText = "正在向 dp2003.com 发送异常报告 ...", StartPosition = FormStartPosition.CenterScreen }; _messageBar.Show(MainForm); _messageBar.Update(); int nRet = 0; string strError = ""; try { string strSender = ""; if (MainForm != null) { strSender = MainForm.GetCurrentUserName() + "@" + MainForm.ServerUID; } // 崩溃报告 nRet = LibraryChannel.CrashReport( strSender, $"{ProgramName}", 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); // 写入错误日志 WriteErrorLog(strError); } }
private void ShowRecoveryMessages() { // Make sure we are dealing with the correct set of files. new RecoveryDatabase(RecoveryVersion.Current).SetToLastRun(); RecoveryDatabase recovery = new RecoveryDatabase(RecoveryVersion.LastRun); if (recovery.ItemsExist()) { MessageBar msgBar = new MessageBar(); msgBar.Title = "RECOVERY"; msgBar.Message = "Daytimer shut down unexpectedly. We recovered your work, and need you to confirm what we should keep."; msgBar.ButtonText = "_View Items"; msgBar.Icon = new BitmapImage(new Uri("pack://application:,,,/Daytimer.Images;component/Images/info_mdm.png", UriKind.Absolute)); msgBar.Closed += (m, args) => { Close(msgBar); }; msgBar.ButtonClick += (b, args) => { Autorecover recover = new Autorecover(); recover.Owner = this; if (recover.ShowDialog() == true) { foreach (DatabaseObject each in recover.SelectedItems) { if (each is Appointment) { RecoverAppointment(each as Appointment); } else if (each is Contact) { RecoverContact(each as Contact); } else if (each is UserTask) { RecoverTask(each as UserTask); } } if (!recovery.ItemsExist()) { msgBar.Close(); } } }; messageBar.Children.Add(msgBar); UpdateMessageBarVisibility(); } }
// 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 }
// 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; } }