internal void ShowDialog(UIMode uiMode, UIProvider uiProvider) { var exception = new SerializableException(new ArgumentException("Argument exception preview.", new Exception("Inner exception for argument exception."))); var report = new Report(exception); var consoleOut = new StringWriter(); Console.SetOut(consoleOut); if (uiProvider == UIProvider.Console) { ConsoleUI.ShowDialog(uiMode, exception, report); this.consoleOutputTextBox.Text = consoleOut.ToString(); this.ShowDialog(); } else if (uiProvider == UIProvider.WinForms) { WinFormsUI.ShowDialog(uiMode, exception, report); this.Close(); } else if (uiProvider == UIProvider.WPF) { WPFUI.ShowDialog(uiMode, exception, report); this.Close(); } else if (uiProvider == UIProvider.Custom) { CustomUI.ShowDialog(uiMode, exception, report); this.Close(); } else { throw new ArgumentException("Parameter supplied for UIProvider argument is invalid."); } }
internal static UIDialogResult DisplayBugReportUI(ExceptionThread exceptionThread, SerializableException serializableException, Report report) { if (exceptionThread == ExceptionThread.Task) { // Do not interfere with the default behaviour for continuation on background thread exceptions. Just log and send'em (no UI...) return(new UIDialogResult(ExecutionFlow.ContinueExecution, SendReport.Send)); } if (Settings.UIMode == UIMode.Auto) { // First of, test to see if the call is from an UI thread and if so, use the same UI type (WinForms, WPF, etc.) if (exceptionThread == ExceptionThread.UI_WinForms) { return(WinFormsUI.ShowDialog(UIMode.Minimal, serializableException, report)); } if (exceptionThread == ExceptionThread.UI_WPF) { return(WPFUI.ShowDialog(UIMode.Minimal, serializableException, report)); } if (exceptionThread == ExceptionThread.Main) { // If the call is not from a non-UI thread like the main app thread, it may be from the current appdomain but // the application may still be using an UI. Or it may be coming from an exception filter where UI type is undefined yet. switch (DiscoverUI()) { case UIProvider.WinForms: return(WinFormsUI.ShowDialog(UIMode.Minimal, serializableException, report)); case UIProvider.WPF: return(WPFUI.ShowDialog(UIMode.Minimal, serializableException, report)); case UIProvider.Console: return(ConsoleUI.ShowDialog(UIMode.Minimal, serializableException, report)); case UIProvider.Custom: return(CustomUI.ShowDialog(UIMode.Minimal, serializableException, report)); default: throw new NBugRuntimeException("UISelector.DiscoverUI() returned an invalid UI type."); } } throw new NBugRuntimeException(string.Format("Parameter supplied for '{0}' is not valid.", typeof(ExceptionThread).Name)); } if (Settings.UIMode == UIMode.None) { // Do not display an UI for UIMode.None if (Settings.ExitApplicationImmediately) { return(new UIDialogResult(ExecutionFlow.BreakExecution, SendReport.Send)); } return(new UIDialogResult(ExecutionFlow.ContinueExecution, SendReport.Send)); } if (Settings.UIProvider == UIProvider.Console) { return(ConsoleUI.ShowDialog(Settings.UIMode, serializableException, report)); } if (Settings.UIProvider == UIProvider.WinForms) { return(WinFormsUI.ShowDialog(Settings.UIMode, serializableException, report)); } if (Settings.UIProvider == UIProvider.WPF) { return(WPFUI.ShowDialog(Settings.UIMode, serializableException, report)); } if (Settings.UIProvider == UIProvider.Custom) { return(CustomUI.ShowDialog(UIMode.Minimal, serializableException, report)); } if (Settings.UIProvider == UIProvider.Auto) { // In this case, UIProvider = Auto & UIMode != Auto so just discover the UI provider and use the selected UI mode switch (DiscoverUI()) { case UIProvider.WinForms: return(WinFormsUI.ShowDialog(Settings.UIMode, serializableException, report)); case UIProvider.WPF: return(WPFUI.ShowDialog(Settings.UIMode, serializableException, report)); case UIProvider.Console: return(ConsoleUI.ShowDialog(Settings.UIMode, serializableException, report)); case UIProvider.Custom: return(CustomUI.ShowDialog(UIMode.Minimal, serializableException, report)); default: throw new NBugRuntimeException("UISelector.DiscoverUI() returned an invalid UI type."); } } throw NBugConfigurationException.Create(() => Settings.UIProvider, "Parameter supplied for settings property is invalid."); }