M src/PacketLogger/ViewModels/DocumentViewModel.cs => src/PacketLogger/ViewModels/DocumentViewModel.cs +35 -14
@@ 106,7 106,8 @@ public class DocumentViewModel : Document, INotifyPropertyChanged, IDisposable
var openResult = await provider.Open();
if (!openResult.IsSuccess)
{
- Console.WriteLine("Could not open the file.");
+ Error = "File could not be opened. " + openResult.ToFullString();
+ Loading = false;
return;
}
@@ 127,7 128,8 @@ public class DocumentViewModel : Document, INotifyPropertyChanged, IDisposable
(process.Process, _ctSource.Token, ct);
if (!connectionResult.IsDefined(out var connection))
{
- Console.WriteLine(connectionResult.ToFullString());
+ Error = "An error has occurred upon establishing a connection: " + connectionResult.ToFullString();
+ Loading = false;
return;
}
@@ 142,7 144,8 @@ public class DocumentViewModel : Document, INotifyPropertyChanged, IDisposable
if (!contractResult.IsDefined(out var handshakeResponse))
{
repository.Remove(connection.Client);
- Console.WriteLine(contractResult.ToFullString());
+ Error = "An error has occurred upon sending handshake: " + contractResult.ToFullString();
+ Loading = false;
return;
}
@@ 150,7 153,8 @@ public class DocumentViewModel : Document, INotifyPropertyChanged, IDisposable
if (!handshakeInitResponse.IsSuccess)
{
repository.Remove(connection.Client);
- Console.WriteLine(handshakeInitResponse.ToFullString());
+ Error = "An error has occurred during handshaking: " + handshakeInitResponse.ToFullString();
+ Loading = false;
return;
}
@@ 176,16 180,18 @@ public class DocumentViewModel : Document, INotifyPropertyChanged, IDisposable
);
OpenSender = ReactiveCommand.Create<IPacketProvider>
- (
- provider =>
- {
- Loading = true;
- NestedViewModel = new PacketSenderViewModel(provider);
- Title = $"Sender ({provider.Name})";
- Loaded = true;
- Loading = false;
- }
- );
+ (
+ provider =>
+ {
+ Loading = true;
+ NestedViewModel = new PacketSenderViewModel(provider);
+ Title = $"Sender ({provider.Name})";
+ Loaded = true;
+ Loading = false;
+ }
+ );
+
+ ClearError = ReactiveCommand.Create(() => Error = null);
}
/// <summary>
@@ 214,6 220,16 @@ public class DocumentViewModel : Document, INotifyPropertyChanged, IDisposable
public bool Loaded { get; private set; }
/// <summary>
+ /// Gets or sets the current error.
+ /// </summary>
+ public string? Error { get; private set; }
+
+ /// <summary>
+ /// Gets or sets whether there is an error.
+ /// </summary>
+ public bool HasError => Error is not null;
+
+ /// <summary>
/// Gets the log tab view model.
/// </summary>
public ViewModelBase? NestedViewModel { get; private set; }
@@ 234,6 250,11 @@ public class DocumentViewModel : Document, INotifyPropertyChanged, IDisposable
public ReactiveCommand<Unit, Unit> OpenFile { get; }
/// <summary>
+ /// Gets the command to clear the error.
+ /// </summary>
+ public ReactiveCommand<Unit, string?> ClearError { get; }
+
+ /// <summary>
/// Gets the command for opening a process / connecting to a process.
/// </summary>
public ReactiveCommand<NostaleProcess, Unit> OpenProcess { get; }
M src/PacketLogger/Views/DocumentView.axaml => src/PacketLogger/Views/DocumentView.axaml +18 -3
@@ 12,12 12,27 @@
</Design.DataContext>
<Grid>
- <Border IsVisible="{Binding !Loaded}"
+ <Border Grid.Row="1" IsVisible="{Binding !Loaded}"
MaxWidth="1000" MaxHeight="600"
CornerRadius="25"
Background="{DynamicResource SystemControlPageBackgroundChromeLowBrush}">
- <Grid Margin="50">
- <Grid ColumnDefinitions="*,*" RowDefinitions="60, 80, 80, *">
+ <Grid RowDefinitions="Auto,*" Margin="50">
+ <Border IsVisible="{Binding HasError}"
+ MaxWidth="600"
+ Margin="10"
+ Grid.Row="0" Background="Red" CornerRadius="10">
+ <StackPanel Margin="10" Orientation="Vertical">
+ <Grid ColumnDefinitions="*,30">
+ <TextBlock Grid.Column="0" FontSize="20" FontStyle="Oblique" Text="Notification" />
+ <Button Padding="0" Margin="0" Command="{Binding ClearError}" Grid.Column="1" Width="20" Height="20">
+ <i:Icon FontSize="12" Value="mdi-close" />
+ </Button>
+ </Grid>
+ <TextBlock Text="{Binding Error}" TextWrapping="Wrap" />
+ </StackPanel>
+ </Border>
+
+ <Grid Grid.Row="1" ColumnDefinitions="*,*" RowDefinitions="60, 80, 80, *">
<Grid.Styles>
<Style Selector="Button.open">
<Setter Property="FontSize" Value="24"></Setter>
M src/PacketLogger/Views/PacketLogView.axaml => src/PacketLogger/Views/PacketLogView.axaml +1 -0
@@ 61,6 61,7 @@
x:Name="PacketsLog"
SelectionMode="Multiple"
SelectedItem="{Binding SelectedPacket, Mode=TwoWay}"
+ VerticalAlignment="Stretch"
SelectionChanged="PacketsLog_OnSelectionChanged">
<ListBox.Styles>
<Style Selector="ListBoxItem">