Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Shows the dialog (handles the error, if it is one).
        /// </summary>
        /// <param name="applicationKey">The application registry key.</param>
        /// <param name="error">the exception you want to report</param>
        /// <param name="parent">the parent form that this error belongs to (i.e. the form
        /// show modally on)</param>
        /// ------------------------------------------------------------------------------------
        private void ShowDialog(RegistryKey applicationKey, Exception error, Form parent)
        {
            CheckDisposed();
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            SetDialogStringsSoLocatilizationWorks();

            m_viewDetailsOriginalText      = viewDetailsLink.Text;
            m_originalHeightWithoutDetails = Height - m_details.Height - 10;
            m_originalHeight  = Height;
            m_originalMinSize = MinimumSize;

            if (m_fUserReport)
            {
                ControlBox           = true;
                cancelButton.Visible = true;
                btnClose.Size        = cancelButton.Size;
                btnClose.Left        = cancelButton.Left - btnClose.Width - 15;
                if (m_fSuggestion)
                {
                    Text = ReportingStrings.kstidMakeSuggestionCaption;
                    m_notification.Text = ReportingStrings.kstidMakeSuggestionNotification;
                    m_stepsLabel.Text   = ReportingStrings.kstidGoalAndSuggestion;
                    m_reproduce.Text    = ReportingStrings.kstidSampleSuggestion;
                }
                else
                {
                    Text = ReportingStrings.kstidReportProblemCaption;
                    m_notification.Text = ReportingStrings.kstidReportProblemNotification;
                    m_stepsLabel.Text   = ReportingStrings.kstidProblemAndSteps;
                    m_reproduce.Text    = ReportingStrings.ksSampleProblemReport;
                }
                // Do this AFTER filling in the sample...it is disabled until they change something.
                btnClose.Enabled = false;
            }

            s_showDetails = true;             // the resource-file state of the dialog is showing.

            if (m_emailAddress == null)
            {
                radEmail.Enabled = false;
                radSelf.Checked  = true;
            }
            else
            {
                // Add the e-mail address to the dialog.
                lbl_EmailReport.Text = String.Format(lbl_EmailReport.Text, m_emailAddress);
            }

            if (!m_isLethal)
            {
                btnClose.Text = ReportingStrings.ks_Ok;
                BackColor     = m_fSuggestion
                                        ? Color.FromKnownColor(KnownColor.Control) // standard dialog background
                                        : Color.FromArgb(255, 255, 192);           //yellow
                m_notification.BackColor = BackColor;
                UpdateCrashCount(applicationKey, "NumberOfAnnoyingCrashes");
            }
            else
            {
                UpdateCrashCount(applicationKey, "NumberOfSeriousCrashes");
            }
            UpdateAppRuntime(applicationKey);

            StringBuilder detailsText        = new StringBuilder();
            Exception     innerMostException = null;

            if (error != null)
            {
                detailsText.AppendLine(ExceptionHelper.GetHiearchicalExceptionInfo(error, out innerMostException));

                // if the exception had inner exceptions, show the inner-most exception first, since
                // that is usually the one we want the developer to read.
                if (innerMostException != null)
                {
                    StringBuilder innerException = new StringBuilder();
                    innerException.AppendLine("Inner most exception:");
                    innerException.AppendLine(ExceptionHelper.GetExceptionText(innerMostException));
                    innerException.AppendLine();
                    innerException.AppendLine("Full, hierarchical exception contents:");
                    detailsText.Insert(0, innerException.ToString());
                }
            }

            detailsText.AppendLine("Additional information about the computer and project:");
            foreach (string label in s_properties.Keys)
            {
                detailsText.AppendLine(label + ": " + s_properties[label]);
            }

            if (innerMostException != null)
            {
                error = innerMostException;
            }
            if (error != null)
            {
                Logger.WriteEvent("Got exception " + error.GetType().Name);
            }

            detailsText.AppendLine(Logger.LogText);
            Debug.WriteLine(detailsText.ToString());
            m_details.Text = detailsText.ToString();

            if (m_fUserReport)
            {
                // show modeless, so they can use the program while filling in details.
                // Don't set the Ignore flag, a real crash might happen while trying to report a lesser problem.
                Show(parent);
                return;
            }
            if (s_isOkToInteractWithUser)
            {
                s_fIgnoreReport = true;
                ShowDialog((parent != null && !parent.IsDisposed) ? parent : null);
                s_fIgnoreReport = false;
            }
            else                //the test environment already prohibits dialogs but will save the contents of assertions in some log.
            {
                Debug.Fail(m_details.Text);
            }
        }