示例#1
0
        private void ShowExceptionDialog()
        {
            if (_exceptionDialogVisible)
            {
                return;
            }

            _exceptionDialogVisible = true;
            bool exceptionFatal = false;

            try
            {
                while (true)
                {
                    QueuedException qex = null;
                    lock ( _exceptionQueue )
                    {
                        if (_exceptionQueue.Count > 0)
                        {
                            qex = (QueuedException)_exceptionQueue.Dequeue();
                        }
                    }
                    if (qex == null)
                    {
                        break;
                    }

                    if ((qex.Flags & ExceptionReportFlags.Fatal) != 0)
                    {
                        exceptionFatal = true;
                    }

                    Exception ex = qex.Exception;
                    if (ex is AsyncProcessorException)
                    {
                        ex = ex.InnerException;
                    }
                    if (ex is TargetInvocationException)
                    {
                        ex = ex.InnerException;
                    }

                    ISettingStore ini = Core.SettingStore;
                    using (ExceptionReportForm dlg = new ExceptionReportForm())
                    {
                        ProxySettings proxySettings = new ProxySettings();
                        try
                        {
                            string address = ini.ReadString("HttpProxy", "Address");
                            proxySettings.CustomProxy = address.Length > 0;
                            if (proxySettings.CustomProxy)
                            {
                                proxySettings.Host     = address;
                                proxySettings.Port     = ini.ReadInt("HttpProxy", "Port", 3128);
                                proxySettings.Login    = ini.ReadString("HttpProxy", "User");
                                proxySettings.Password = ini.ReadString("HttpProxy", "Password");
                            }
                            dlg.SetProxy(proxySettings);
                        }
                        catch (Exception pex)
                        {
                            Trace.WriteLine("Failed to set exception reporter proxy: " + pex.ToString());
                        }
                        // Setup our submitter
                        dlg.Submitter  = new RPCExceptionSubmitter();
                        dlg.ProjectKey = "OM";
                        dlg.DisplaySubmissionResult = true;
                        string userName = ini.ReadString("ErrorReport", "UserName");
                        string password = ini.ReadString("ErrorReport", "Password");
                        if (userName.Length > 0 && password.Length > 0)
                        {
                            dlg.SetITNLogin(userName, password);
                        }
                        else
                        {
                            dlg.SetDefaultLogin("om_anonymous", "guest");
                        }

                        if ((qex.Flags & ExceptionReportFlags.AttachLog) != 0)
                        {
                            dlg.AttachLog = true;
                        }

                        dlg.SetBuildNumber(Assembly.GetExecutingAssembly().GetName().Version.Build);

                        IWin32Window ownerWindow = (_ownerControl == null || _ownerControl.IsDisposed) ? null : _ownerControl;

                        if (dlg.ReportException(ownerWindow, ex, GetExceptionDescription()) == DialogResult.OK)
                        {
                            if (dlg.ITNUserName != "om_anonymous")
                            {
                                ini.WriteString("ErrorReport", "UserName", dlg.ITNUserName);
                                ini.WriteString("ErrorReport", "Password", dlg.ITNPassword);
                            }

                            if (dlg.AttachLog)
                            {
                                LogManager.SubmitErrorLog();
                            }
                            proxySettings = dlg.ProxySettings;
                            if (!proxySettings.CustomProxy)
                            {
                                ini.WriteString("HttpProxy", "Address", string.Empty);
                            }
                            else
                            {
                                ini.WriteString("HttpProxy", "Address", proxySettings.Host);
                                ini.WriteInt("HttpProxy", "Port", proxySettings.Port);
                                ini.WriteString("HttpProxy", "User", proxySettings.Login);
                                ini.WriteString("HttpProxy", "Password", proxySettings.Password);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(null, "An exception has occured in the application, and the exception reporter failed to present it.\n\n" + ex.Message + "\n\nThe application will now be terminated.", "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                exceptionFatal = true;
            }
            _exceptionDialogVisible = false;

            if (exceptionFatal)
            {
                (Core.MainWindow as MainFrame).ForceClose();
            }
        }