Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// ------------------------------------------------------------------------------------
        private void btnClose_Click(object sender, System.EventArgs e)
        {
            GatherData();

            if (radEmail.Checked)
            {
                try
                {
                    // WARNING! This currently does not work. The main issue seems to be the length of the error report. mailto
                    // apparently has some limit on the length of the message, and we are exceeding that.
                    //make it safe, but does too much (like replacing spaces with +'s)
                    //string s = System.Web.HttpUtility.UrlPathEncode( m_details.Text);
                    string body = m_details.Text.Replace(Environment.NewLine, "%0A").Replace("\"", "%22").Replace("&", "%26");

                    Process p = new Process();
                    p.StartInfo.FileName = String.Format("mailto:{0}?subject={1}&body={2}", m_emailAddress, s_emailSubject, body);
                    p.Start();
                }
                catch (Exception)
                {
                    //swallow it
                }
//				catch(Exception ex)
//				{
//					System.Diagnostics.Debug.WriteLine(ex.Message);
//					System.Diagnostics.Debug.WriteLine(ex.StackTrace);
//				}
            }
            else if (radSelf.Checked)
            {
                if (m_emailAddress != null)
                {
                    m_details.Text = string.Format(ReportingStrings.ksPleaseEMailThisTo0WithThisExactSubject12,
                                                   m_emailAddress, s_emailSubject, m_details.Text);
                }
                // Copying to the clipboard works only if thread is STA which is not the case if
                // called from the Finalizer thread
                if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
                {
                    ClipboardUtils.SetDataObject(m_details.Text, true);
                }
                else
                {
                    Logger.WriteEvent(m_details.Text);
                }
            }

            if (!m_isLethal || ModifierKeys.Equals(Keys.Shift))
            {
                Logger.WriteEvent("Continuing...");
                return;
            }

            m_userChoseToExit = true;
            Logger.WriteEvent("Exiting...");
            Application.Exit();
        }
Example #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// show a dialog or output to the error log, as appropriate.
        /// </summary>
        /// <param name="error">the exception you want to report</param>
        /// <param name="applicationKey">The application registry key.</param>
        /// <param name="emailAddress">The e-mail address for reporting errors.</param>
        /// <param name="parent">the parent form that this error belongs to (i.e. the form
        /// show modally on)</param>
        /// <param name="isLethal">set to <c>true</c> if the error is lethal, otherwise
        /// <c>false</c>.</param>
        /// <returns>True if the error was lethal and the user chose to exit the application,
        /// false otherwise.</returns>
        /// ------------------------------------------------------------------------------------
        public static bool ReportException(Exception error, RegistryKey applicationKey,
                                           string emailAddress, Form parent, bool isLethal)
        {
            // I (TomH) think that unit tests should never show this Exception dialog.
            if (MiscUtils.RunningTests)
            {
                throw error;
            }

            // ignore message if we are showing from a previous error
            if (s_fIgnoreReport)
            {
                return(false);
            }

            if (String.IsNullOrEmpty(emailAddress))
            {
                emailAddress = "*****@*****.**";
            }

            // If the error has a message and a help link, then show that error
            if (!string.IsNullOrEmpty(error.HelpLink) && error.HelpLink.IndexOf("::/") > 0 &&
                !string.IsNullOrEmpty(error.Message))
            {
                s_fIgnoreReport = true;                 // This is presumably a hopelessly fatal error, so we
                // don't want to report any subsequent errors at all.
                // Look for the end of the basic message which will be terminated by two new lines or
                // two CRLF sequences.
                int lengthOfBasicMessage = error.Message.IndexOf("\r\n\r\n");
                if (lengthOfBasicMessage <= 0)
                {
                    lengthOfBasicMessage = error.Message.IndexOf("\n\n");
                }
                if (lengthOfBasicMessage <= 0)
                {
                    lengthOfBasicMessage = error.Message.Length;
                }

                int    iSeparatorBetweenFileNameAndTopic = error.HelpLink.IndexOf("::/");
                string sHelpFile  = error.HelpLink.Substring(0, iSeparatorBetweenFileNameAndTopic);
                string sHelpTopic = error.HelpLink.Substring(iSeparatorBetweenFileNameAndTopic + 3);

                string caption = ReportingStrings.kstidFieldWorksErrorCaption;
                string appExit = ReportingStrings.kstidFieldWorksErrorExitInfo;
                MessageBox.Show(parent, error.Message.Substring(0, lengthOfBasicMessage) + Environment.NewLine + appExit,
                                caption, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0,
                                sHelpFile, HelpNavigator.Topic, sHelpTopic);
                if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
                {
                    ClipboardUtils.SetDataObject(error.Message, true);
                }
                else
                {
                    Logger.WriteError(error);
                }
                Application.Exit();
                return(true);
            }

            using (ErrorReporter e = new ErrorReporter(isLethal, emailAddress))
            {
                e.HandleError(applicationKey, error, parent);
                return(e.m_userChoseToExit);
            }
        }
Example #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// ------------------------------------------------------------------------------------
        private void btnClose_Click(object sender, System.EventArgs e)
        {
            var body = GatherData();

            if (radEmail.Checked)
            {
                var emailProvider = EmailProviderFactory.PreferredEmailProvider();
                var emailMessage  = emailProvider.CreateMessage();
                emailMessage.To.Add(m_emailAddress);
                var emailSubject = s_emailSubject;
                if (m_fReportDuplicateGuidsASAP)
                {
                    emailSubject = "Duplicate GUIDs Error Report:";
                }
                else if (m_fSuggestion)
                {
                    emailSubject = "Suggested Improvement to FLEx:";
                }
                else if (m_fUserReport)
                {
                    emailSubject = "Manual Error Report:";
                }
                emailMessage.Subject = emailSubject;
                emailMessage.Body    = body;
                if (!emailMessage.Send(emailProvider))
                {
                    MessageBox.Show(this, ReportingStrings.kstidSendFailed, ReportingStrings.kstidSendFailedCaption,
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    radSelf.Checked = true;
                    return;
                }
            }
            else if (radSelf.Checked)
            {
                if (m_emailAddress != null)
                {
                    if (m_fUserReport)
                    {
                        body = string.Format(ReportingStrings.kstidPleaseEmailThisTo0WithASuitableSubject,
                                             m_emailAddress, body);
                    }
                    else
                    {
                        body = string.Format(ReportingStrings.ksPleaseEMailThisTo0WithThisExactSubject12,
                                             m_emailAddress, s_emailSubject, body);
                    }
                }
                // Copying to the clipboard works only if thread is STA which is not the case if
                // called from the Finalizer thread
                if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
                {
#if __MonoCS__
                    // Workaround for Xamarin bug #4959. I had a mono fix for that bug
                    // but that doesn't work with FW - I couldn't figure out why not.
                    // This is a dirty hack but at least works :-)
                    var clipboardAtom = gdk_atom_intern("CLIPBOARD", true);
                    var clipboard     = gtk_clipboard_get(clipboardAtom);
                    if (clipboard != IntPtr.Zero)
                    {
                        gtk_clipboard_set_text(clipboard, body, -1);
                        gtk_clipboard_store(clipboard);
                    }
#else
                    ClipboardUtils.SetDataObject(body, true);
#endif
                }
                else
                {
                    Logger.WriteEvent(body);
                }
            }

            if (!m_isLethal || ModifierKeys.Equals(Keys.Shift))
            {
                Logger.WriteEvent("Continuing...");
                Close();
                return;
            }

            m_userChoseToExit = true;
            Logger.WriteEvent("Exiting...");
            Application.Exit();
        }