Show all inner exceptions for connectivity dialog

maybe using a viewmodel isnt a bad idea after all...
This commit is contained in:
pizzaboxer 2023-08-02 10:37:27 +01:00
parent b1d0e11121
commit 173494641a
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8

View File

@ -16,17 +16,12 @@ namespace Bloxstrap.UI.Elements.Dialogs
{
public ConnectivityDialog(string targetName, string description, Exception exception)
{
Exception? innerException = exception.InnerException;
InitializeComponent();
TitleTextBlock.Text = $"{App.ProjectName} is unable to connect to {targetName}";
DescriptionTextBlock.Text = description;
ErrorRichTextBox.Selection.Text = $"{exception.GetType()}: {exception.Message}";
if (innerException is not null)
ErrorRichTextBox.Selection.Text += $"\n\n===== Inner Exception =====\n{innerException.GetType()}: {innerException.Message}";
AddException(exception);
CloseButton.Click += delegate
{
@ -41,5 +36,18 @@ namespace Bloxstrap.UI.Elements.Dialogs
PInvoke.FlashWindow((HWND)hWnd, true);
};
}
private void AddException(Exception exception, bool inner = false)
{
if (!inner)
ErrorRichTextBox.Selection.Text = $"{exception.GetType()}: {exception.Message}";
if (exception.InnerException is null)
return;
ErrorRichTextBox.Selection.Text += $"\n\n[Inner Exception]\n{exception.InnerException.GetType()}: {exception.InnerException.Message}";
AddException(exception.InnerException, true);
}
}
}