using System; using System.Linq; using System.Reflection; using System.Windows.Forms; using Core.Common.Controls.Properties; namespace Core.Common.Controls.Dialogs { /// /// Class for showing an exception dialog. /// The exception dialog can return the following results: /// /// /// : this result represents a request for restarting the application. /// /// /// : this result represents a request for closing the application. /// /// /// public partial class ExceptionDialog : DialogBase { private Action openLogClicked; /// /// Constructs a new . /// /// The exception to show in the dialog. public ExceptionDialog(Exception exception) : base(Resources.bug__exclamation) { InitializeComponent(); buttonOpenLog.Visible = false; exceptionTextBox.Text = GetExceptionText(exception); } /// /// Gets or sets the action that should be performed after clicking the log button. /// /// The log button is only visible when this action is set. public Action OpenLogClicked { private get { return openLogClicked; } set { openLogClicked = value; buttonOpenLog.Visible = openLogClicked != null; } } protected override Button GetCancelButton() { return buttonExit; } private void ButtonRestartClick(object sender, EventArgs e) { DialogResult = DialogResult.OK; Close(); } private void ButtonExitClick(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); } private void ButtonCopyTextToClipboardClick(object sender, EventArgs e) { Clipboard.SetDataObject(exceptionTextBox.Text, true); } private void ButtonOpenLogClick(object sender, EventArgs e) { OpenLogClicked(); } private string GetExceptionText(Exception exception) { if (exception == null) { return ""; } var str = exception.ToString(); if (exception.InnerException != null) { str += string.Format(Resources.ExceptionDialog_GetExceptionText_Inner_exceptions_0_, exception.InnerException); } var reflectionTypeLoadException = exception as ReflectionTypeLoadException; if (reflectionTypeLoadException != null) { str += Resources.ExceptionDialog_GetExceptionText_Loader_exceptions; str = reflectionTypeLoadException.LoaderExceptions.Aggregate(str, (current, ex) => current + (ex + Environment.NewLine)); } return str; } } }