Skip to content

Commit

Permalink
Also show exception specific properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasArdal committed Oct 10, 2023
1 parent 9681a35 commit a2a0516
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 52 deletions.
6 changes: 6 additions & 0 deletions src/ExceptionVisualizer/ExceptionUserControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ private ExceptionViewModel ToViewModel(ExceptionModel exception)
Key = d.Key,
Value = d.Value,
})),
Properties = new ObservableCollection<DataViewModel>(exception.Properties.Select(d => new DataViewModel
{
Key = d.Key,
Value = d.Value,
})),
ShowData = exception.Data.Count > 0 ? Visibility.Visible : Visibility.Collapsed,
ShowProperties = exception.Properties.Count > 0 ? Visibility.Visible : Visibility.Collapsed,
HelpLink = exception.HelpLink,
HResult = exception.HResult,
Message = exception.Message,
Expand Down
139 changes: 87 additions & 52 deletions src/ExceptionVisualizer/ExceptionUserControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<DataTemplate.Resources>
<Style TargetType="TreeView" BasedOn="{StaticResource {x:Static styles:VsResourceKeys.ThemedDialogTreeViewStyleKey}}" />
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Static styles:VsResourceKeys.TextBoxStyleKey}}" />
<Style TargetType="TabItem" BasedOn="{StaticResource {x:Static styles:VsResourceKeys.ThemedDialogTabItemNavigationStyleKey}}" />
<DataTemplate x:Key="CaptureTemplate">
<Grid>
<Grid.ColumnDefinitions>
Expand All @@ -15,8 +14,6 @@
<RowDefinition Height="30"></RowDefinition>
<RowDefinition MaxHeight="400" Height="Auto"></RowDefinition>
<RowDefinition Height="80"></RowDefinition>
<RowDefinition MaxHeight="20" Height="Auto"></RowDefinition>
<RowDefinition MaxHeight="90" Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="{Binding Type}" FontSize="16" VerticalAlignment="Center" Grid.Row="0" Margin="3"/>
Expand Down Expand Up @@ -57,55 +54,7 @@
<TextBlock Text="{Binding HResult}" Grid.Column="1" Grid.Row="2"></TextBlock>
<TextBlock Text="{Binding HelpLink}" Grid.Column="1" Grid.Row="3"></TextBlock>
</Grid>
<TextBlock Grid.Row="3" Margin="3" Visibility="{Binding ShowData}">
<TextBlock.Inlines>
<Run FontWeight="Bold" Text="Data" />
</TextBlock.Inlines>
</TextBlock>
<ScrollViewer Grid.Row="4" Margin="3" VerticalScrollBarVisibility="Auto" Visibility="{Binding ShowData}">
<DataGrid ItemsSource="{Binding Data}" RowHeaderWidth="0" BorderThickness="0" GridLinesVisibility="None" AutoGenerateColumns="False"
IsReadOnly="True" MaxHeight="90" CanUserAddRows="False" CanUserDeleteRows="False"
Background="{DynamicResource VsBrush.ToolWindowBackground}" Foreground="{DynamicResource VsBrush.ToolWindowText}">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Background" Value="{DynamicResource VsBrush.ToolWindowBackground }"/>
<Setter Property="Foreground" Value="{DynamicResource VsBrush.ToolWindowText}" />
<Setter Property="BorderBrush" Value="{DynamicResource VsBrush.ToolWindowBorder}"/>
<Setter Property="BorderThickness" Value="0 0 1 1"/>
<Setter Property="Padding" Value="5"/>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource VsBrush.Hightlight}"/>
<Setter Property="Foreground" Value="{DynamicResource VsBrush.HightlightText}"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="{DynamicResource VsBrush.ToolWindowBackground }"/>
<Setter Property="Foreground" Value="{DynamicResource VsBrush.ToolWindowText}" />
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="4"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource VsBrush.Highlight}"/>
<Setter Property="Foreground" Value="{DynamicResource VsBrush.HighlightText}"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Key" MinWidth="100" Binding="{Binding Key}"></DataGridTextColumn>
<DataGridTextColumn Header="Value" Width="* " Binding="{Binding Value}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</ScrollViewer>
<TabControl Grid.Row="5" Margin="3" Foreground="{DynamicResource VsBrush.ToolWindowText}" Background="{DynamicResource VsBrush.ToolWindowBackground }">
<TabControl Grid.Row="3" Margin="3" Foreground="{DynamicResource VsBrush.ToolWindowText}" Background="{DynamicResource VsBrush.ToolWindowBackground }">
<TabItem Header="Stack Trace">
<ScrollViewer Margin="3" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<TextBlock Text="{Binding StackTrace}" Foreground="{DynamicResource VsBrush.ToolWindowText}" Background="{DynamicResource VsBrush.ToolWindowBackground }"/>
Expand All @@ -116,6 +65,92 @@
<TextBlock Text="{Binding Demystified}" Foreground="{DynamicResource VsBrush.ToolWindowText}" Background="{DynamicResource VsBrush.ToolWindowBackground }"/>
</ScrollViewer>
</TabItem>
<TabItem Header="Data" Visibility="{Binding ShowData}">
<ScrollViewer Margin="3" VerticalScrollBarVisibility="Auto">
<DataGrid ItemsSource="{Binding Data}" RowHeaderWidth="0" BorderThickness="0" GridLinesVisibility="None" AutoGenerateColumns="False" IsReadOnly="True" MaxHeight="90" CanUserAddRows="False" CanUserDeleteRows="False" Background="{DynamicResource VsBrush.ToolWindowBackground}" Foreground="{DynamicResource VsBrush.ToolWindowText}" VerticalAlignment="Top">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Background" Value="{DynamicResource VsBrush.ToolWindowBackground }"/>
<Setter Property="Foreground" Value="{DynamicResource VsBrush.ToolWindowText}" />
<Setter Property="BorderBrush" Value="{DynamicResource VsBrush.ToolWindowBorder}"/>
<Setter Property="BorderThickness" Value="0 0 1 1"/>
<Setter Property="Padding" Value="5"/>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource VsBrush.Hightlight}"/>
<Setter Property="Foreground" Value="{DynamicResource VsBrush.HightlightText}"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="{DynamicResource VsBrush.ToolWindowBackground }"/>
<Setter Property="Foreground" Value="{DynamicResource VsBrush.ToolWindowText}" />
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="4"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource VsBrush.Highlight}"/>
<Setter Property="Foreground" Value="{DynamicResource VsBrush.HighlightText}"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Key" MinWidth="100" Binding="{Binding Key}"></DataGridTextColumn>
<DataGridTextColumn Header="Value" Width="* " Binding="{Binding Value}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</ScrollViewer>
</TabItem>
<TabItem Header="Properties" Visibility="{Binding ShowProperties}">
<ScrollViewer Margin="3" VerticalScrollBarVisibility="Auto">
<DataGrid ItemsSource="{Binding Properties}" RowHeaderWidth="0" BorderThickness="0" GridLinesVisibility="None" AutoGenerateColumns="False" IsReadOnly="True" MaxHeight="90" CanUserAddRows="False" CanUserDeleteRows="False" Background="{DynamicResource VsBrush.ToolWindowBackground}" Foreground="{DynamicResource VsBrush.ToolWindowText}" VerticalAlignment="Top">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Background" Value="{DynamicResource VsBrush.ToolWindowBackground }"/>
<Setter Property="Foreground" Value="{DynamicResource VsBrush.ToolWindowText}" />
<Setter Property="BorderBrush" Value="{DynamicResource VsBrush.ToolWindowBorder}"/>
<Setter Property="BorderThickness" Value="0 0 1 1"/>
<Setter Property="Padding" Value="5"/>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource VsBrush.Hightlight}"/>
<Setter Property="Foreground" Value="{DynamicResource VsBrush.HightlightText}"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="{DynamicResource VsBrush.ToolWindowBackground }"/>
<Setter Property="Foreground" Value="{DynamicResource VsBrush.ToolWindowText}" />
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="4"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource VsBrush.Highlight}"/>
<Setter Property="Foreground" Value="{DynamicResource VsBrush.HighlightText}"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Key" MinWidth="100" Binding="{Binding Key}"></DataGridTextColumn>
<DataGridTextColumn Header="Value" Width="* " Binding="{Binding Value}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</ScrollViewer>
</TabItem>
</TabControl>
</Grid>
</DataTemplate>
Expand Down
6 changes: 6 additions & 0 deletions src/ExceptionVisualizer/Models/ExceptionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ public class ExceptionViewModel : INotifyPropertyChanged
[DataMember]
public ObservableCollection<DataViewModel> Data { get; set; } = new ObservableCollection<DataViewModel>();

[DataMember]
public ObservableCollection<DataViewModel> Properties { get; set; } = new ObservableCollection<DataViewModel>();

[DataMember]
public Visibility ShowData { get; set; } = Visibility.Collapsed;

[DataMember]
public Visibility ShowProperties { get; set; } = Visibility.Collapsed;

[DataMember]
public ObservableCollection<ExceptionViewModel> InnerExceptions { get; set; } = new ObservableCollection<ExceptionViewModel>();

Expand Down
3 changes: 3 additions & 0 deletions src/ExceptionVisualizerSource/ExceptionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class ExceptionModel
[DataMember]
public List<KeyValuePair<string, string>> Data { get; set; } = new List<KeyValuePair<string, string>>();

[DataMember]
public List<KeyValuePair<string, string>> Properties { get; set; } = new List<KeyValuePair<string, string>>();

[DataMember]
public List<ExceptionModel> InnerExceptions { get; set; } = new List<ExceptionModel>();

Expand Down
9 changes: 9 additions & 0 deletions src/ExceptionVisualizerSource/ExceptionModelSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Collections;
using System.Diagnostics;
using System.Reflection;

namespace ExceptionVisualizerSource
{
Expand Down Expand Up @@ -45,6 +46,14 @@ private static ExceptionModel Convert(Exception e)
.Cast<object>()
.Where(k => !string.IsNullOrWhiteSpace(k.ToString()))
.Select(i => new KeyValuePair<string, string>(i.ToString(), Value(e.Data, i))));
model.Properties = e
.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
.Where(p => p.CanRead)
.Where(p => p.PropertyType.IsSubclassOf(typeof(ValueType)) || p.PropertyType.Equals(typeof(string)))
.Where(p => p.Name != "Message" && p.Name != "Source" && p.Name != "HResult" && p.Name != "HelpLink" && p.Name != "TargetSite" && p.Name != "StackTrace" && p.GetValue(e) != null)
.Select(p => new KeyValuePair<string, string>(p.Name, p.GetValue(e)?.ToString()))
.ToList();
var stackTrace = new EnhancedStackTrace(e);
if (stackTrace.FrameCount > 0)
{
Expand Down

0 comments on commit a2a0516

Please sign in to comment.