Skip to content

Commit

Permalink
Feature: Show ping error in UI (#1993)
Browse files Browse the repository at this point in the history
* Feature: Show ping error in UI

* Docs: Add #1993
  • Loading branch information
BornToBeRoot authored Mar 6, 2023
1 parent 756912b commit 048655a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
49 changes: 38 additions & 11 deletions Source/NETworkManager/ViewModels/PingMonitorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,34 @@ private void InitialTimeChart()
public Func<double, string> FormatterDate { get; set; }
public Func<double, string> FormatterPingTime { get; set; }
public SeriesCollection Series { get; set; }

private string _errorMessage;
public string ErrorMessage
{
get => _errorMessage;
set
{
if (value == _errorMessage)
return;

_errorMessage = value;
OnPropertyChanged();
}
}

private bool _isErrorMessageDisplayed;
public bool IsErrorMessageDisplayed
{
get => _isErrorMessageDisplayed;
set
{
if (value == _isErrorMessageDisplayed)
return;

_isErrorMessageDisplayed = value;
OnPropertyChanged();
}
}
#endregion

#region Contructor, load settings
Expand Down Expand Up @@ -222,6 +250,7 @@ private void Ping()

private void StartPing()
{
IsErrorMessageDisplayed = false;
IsRunning = true;

// Reset history
Expand Down Expand Up @@ -260,11 +289,6 @@ private void StopPing()
_cancellationTokenSource?.Cancel();
}

private void PingFinished()
{
IsRunning = false;
}

public void ResetTimeChart()
{
if (Series == null)
Expand All @@ -283,7 +307,7 @@ public void ResetTimeChart()
}

public async Task Export()
{
{
var customDialog = new CustomDialog
{
Title = Localization.Resources.Strings.Export
Expand All @@ -295,7 +319,7 @@ public async Task Export()
try
{
ExportManager.Export(instance.FilePath, instance.FileType, new ObservableCollection<PingInfo> (_pingInfoList));
ExportManager.Export(instance.FilePath, instance.FileType, new ObservableCollection<PingInfo>(_pingInfoList));
}
catch (Exception ex)
{
Expand All @@ -314,7 +338,7 @@ public async Task Export()
DataContext = exportViewModel
};

await _dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
await _dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
}

public void OnClose()
Expand Down Expand Up @@ -374,12 +398,15 @@ private void Ping_PingReceived(object sender, PingReceivedArgs e)

private void Ping_UserHasCanceled(object sender, EventArgs e)
{
PingFinished();
IsRunning = false;
}

private void Ping_PingException(object sender, PingExceptionArgs e)
{
PingFinished();
{
IsRunning = false;

ErrorMessage = e.Message;
IsErrorMessageDisplayed = true;
}
#endregion
}
Expand Down
11 changes: 3 additions & 8 deletions Source/NETworkManager/ViewModels/TracerouteViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,7 @@ private async Task StartTrace()
IsRunning = false;
}
}

private void UserHasCanceled()
{
CancelTrace = false;
IsRunning = false;
}


private async Task Export()
{
var customDialog = new CustomDialog
Expand Down Expand Up @@ -442,7 +436,8 @@ private void Traceroute_MaximumHopsReached(object sender, MaximumHopsReachedArgs

private void Traceroute_UserHasCanceled(object sender, EventArgs e)
{
UserHasCanceled();
CancelTrace = false;
IsRunning = false;

StatusMessage = Localization.Resources.Strings.CanceledByUserMessage;
IsStatusMessageDisplayed = true;
Expand Down
5 changes: 4 additions & 1 deletion Source/NETworkManager/Views/PingMonitorView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:PingMonitorViewModel}">
<UserControl.Resources>
<converters:PercentConverter x:Key="PercentConverter" />
<converters:BooleanToVisibilityCollapsedConverter x:Key="BooleanToVisibilityCollapsedConverter" />
<converters:BooleanReverseToVisibilityCollapsedConverter x:Key="BooleanReverseToVisibilityCollapsedConverter" />
</UserControl.Resources>
<Grid Margin="10" MinWidth="800">
<Grid.ColumnDefinitions>
Expand All @@ -26,7 +28,8 @@
<ColumnDefinition Width="10" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Width="32" Height="32">
<Rectangle Grid.Column="0" Width="32" Height="32" ToolTip="{Binding ErrorMessage}" Style="{StaticResource WarnImageRectangle}" Fill="Orange" Visibility="{Binding IsErrorMessageDisplayed, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}" />
<Rectangle Grid.Column="0" Width="32" Height="32" Visibility="{Binding IsErrorMessageDisplayed, Converter={StaticResource BooleanReverseToVisibilityCollapsedConverter}}" >
<Rectangle.Resources>
<VisualBrush x:Key="VisualConnected" Stretch="Uniform" Visual="{iconPacks:Material Kind=LanConnect}"/>
<VisualBrush x:Key="VisualDisconnected" Stretch="Uniform" Visual="{iconPacks:Material Kind=LanDisconnect}"/>
Expand Down
1 change: 1 addition & 0 deletions docs/Changelog/next-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ The profiles and settings are automatically migrated to the new location when th
- Allow multiple hosts like `server-01; 1.1.1.1; example.com` as input [#1933](https://github.com/BornToBeRoot/NETworkManager/pull/1933){:target="\_blank"}
- Use a fixed size for the view and enable horizonal scrollbar [#1933](https://github.com/BornToBeRoot/NETworkManager/pull/1933){:target="\_blank"} [#1990](https://github.com/BornToBeRoot/NETworkManager/pull/1990){:target="\_blank"}
- Remove option to set the preferred IP protocol for DNS resolution (can now be set globally) [#1950](https://github.com/BornToBeRoot/NETworkManager/pull/1950){:target="\_blank"}
- Display ping error in the UI (with error message as tooltip) instead of silently aborting the ping [#1993](https://github.com/BornToBeRoot/NETworkManager/pull/1993){:target="\_blank"}
- **Traceroute**
- Add more validation (host, ip address) to input [#1932](https://github.com/BornToBeRoot/NETworkManager/pull/1932){:target="\_blank"}
- Remove option to set the preferred IP protocol for DNS resolution (can now be set globally) [#1950](https://github.com/BornToBeRoot/NETworkManager/pull/1950){:target="\_blank"}
Expand Down

0 comments on commit 048655a

Please sign in to comment.