Skip to content

Commit

Permalink
Close #46
Browse files Browse the repository at this point in the history
  • Loading branch information
BornToBeRoot committed Sep 16, 2017
1 parent 668d9c1 commit 9307413
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 4 deletions.
14 changes: 14 additions & 0 deletions Source/NETworkManager/Models/Settings/SettingsInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,20 @@ public int Traceroute_Timeout
SettingsChanged = true;
}
}

private bool _traceroute_ExpandStatistics;
public bool Traceroute_ExpandStatistics
{
get { return _traceroute_ExpandStatistics; }
set
{
if (value == _traceroute_ExpandStatistics)
return;

_traceroute_ExpandStatistics = value;
SettingsChanged = true;
}
}
#endregion

#region Lookup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<system:String x:Key="String_Time3">Zeit 3</system:String>
<system:String x:Key="String_PreferredProtocolWhenResolvingHostname">Bevorzugtes Protokoll beim Auflösen des Hostnamens:</system:String>
<system:String x:Key="String_Hop">Hop</system:String>
<system:String x:Key="String_Hops">Hops</system:String>
<system:String x:Key="String_MaximumHopsRouter">Maximale Hops/Router</system:String>
<system:String x:Key="String_ConfirmClose">Schließen bestätigen</system:String>
<system:String x:Key="String_ConfirmCloseQuesiton">Sind Sie sicher, dass Sie die Anwendung beenden möchten?</system:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<system:String x:Key="String_Time3">Time 3</system:String>
<system:String x:Key="String_PreferredProtocolWhenResolvingHostname">Preferred protocol when resolving hostname:</system:String>
<system:String x:Key="String_Hop">Hop</system:String>
<system:String x:Key="String_Hops">Hops</system:String>
<system:String x:Key="String_MaximumHopsRouter">Maximum hops/router</system:String>
<system:String x:Key="String_ConfirmClose">Confirm close</system:String>
<system:String x:Key="String_ConfirmCloseQuesiton">Are you sure you want to close the application?</system:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Windows;
using System.Windows.Input;
using NETworkManager.Collections;
using System.Net;
using System.Net.NetworkInformation;

namespace NETworkManager.ViewModels.Applications
Expand Down
107 changes: 106 additions & 1 deletion Source/NETworkManager/ViewModels/Applications/TracerouteViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using NETworkManager.Models.Network;
using System.Threading;
using NETworkManager.Helpers;
using System.Diagnostics;
using System.Windows.Threading;

namespace NETworkManager.ViewModels.Applications
{
Expand All @@ -17,6 +19,9 @@ public class TracerouteViewModel : ViewModelBase
#region Variables
CancellationTokenSource cancellationTokenSource;

DispatcherTimer dispatcherTimer = new DispatcherTimer();
Stopwatch stopwatch = new Stopwatch();

private bool _isLoading = true;

private string _hostnameOrIPAddress;
Expand Down Expand Up @@ -118,6 +123,79 @@ public string StatusMessage
OnPropertyChanged();
}
}

private DateTime? _startTime;
public DateTime? StartTime
{
get { return _startTime; }
set
{
if (value == _startTime)
return;

_startTime = value;
OnPropertyChanged();
}
}

private TimeSpan _duration;
public TimeSpan Duration
{
get { return _duration; }
set
{
if (value == _duration)
return;

_duration = value;
OnPropertyChanged();
}
}

private DateTime? _endTime;
public DateTime? EndTime
{
get { return _endTime; }
set
{
if (value == _endTime)
return;

_endTime = value;
OnPropertyChanged();
}
}

private bool _expandStatistics;
public bool ExpandStatistics
{
get { return _expandStatistics; }
set
{
if (value == _expandStatistics)
return;

if (!_isLoading)
SettingsManager.Current.Traceroute_ExpandStatistics = value;

_expandStatistics = value;
OnPropertyChanged();
}
}

private int _hops;
public int Hops
{
get { return _hops; }
set
{
if (value == _hops)
return;

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

#region Constructor, load settings
Expand All @@ -132,6 +210,8 @@ private void LoadSettings()
{
if (SettingsManager.Current.Traceroute_HostnameOrIPAddressHistory != null)
HostnameOrIPAddressHistory = new List<string>(SettingsManager.Current.Traceroute_HostnameOrIPAddressHistory);

ExpandStatistics = SettingsManager.Current.Traceroute_ExpandStatistics;
}
#endregion

Expand Down Expand Up @@ -162,7 +242,16 @@ private async void StartTrace()
DisplayStatusMessage = false;
IsTraceRunning = true;

// Measure the time
StartTime = DateTime.Now;
stopwatch.Start();
dispatcherTimer.Tick += DispatcherTimer_Tick;
dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100);
dispatcherTimer.Start();
EndTime = null;

TraceResult.Clear();
Hops = 0;

// Try to parse the string into an IP-Address
IPAddress.TryParse(HostnameOrIPAddress, out IPAddress ipAddress);
Expand Down Expand Up @@ -239,6 +328,15 @@ private async void StartTrace()

private void TracerouteFinished()
{
// Stop timer and stopwatch
stopwatch.Stop();
dispatcherTimer.Stop();

Duration = stopwatch.Elapsed;
EndTime = DateTime.Now;

stopwatch.Reset();

CancelTrace = false;
IsTraceRunning = false;
}
Expand All @@ -259,6 +357,8 @@ private void Traceroute_HopReceived(object sender, TracerouteHopReceivedArgs e)
{
TraceResult.Add(tracerouteInfo);
}));

Hops++;
}

private void Traceroute_MaximumHopsReached(object sender, MaximumHopsReachedArgs e)
Expand All @@ -270,7 +370,7 @@ private void Traceroute_MaximumHopsReached(object sender, MaximumHopsReachedArgs
}

private void Traceroute_UserHasCanceled(object sender, System.EventArgs e)
{
{
TracerouteFinished();

StatusMessage = Application.Current.Resources["String_CanceledByUser"] as string;
Expand All @@ -281,6 +381,11 @@ private void Traceroute_TraceComplete(object sender, System.EventArgs e)
{
TracerouteFinished();
}

private void DispatcherTimer_Tick(object sender, EventArgs e)
{
Duration = stopwatch.Elapsed;
}
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,5 @@
</Grid>
</StackPanel>
</Expander>

</Grid>
</UserControl>
42 changes: 41 additions & 1 deletion Source/NETworkManager/Views/Applications/TracerouteView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<Converter:IntToStringConverter x:Key="IntToStringConverter" />
<Converter:IPAddressToStringConverter x:Key="IPAddressToStringConverter" />
<Converter:IPStatusToStringConverter x:Key="IPStatusToStringConverter" />
<Converter:NullableDateTimeToStringConverter x:Key="NullableDateTimeToStringConverter" />
<Converter:PingTimeToStringConverter x:Key="PingTimeToStringConverter" />
</UserControl.Resources>
<Grid Margin="10">
Expand All @@ -24,6 +25,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Style="{StaticResource HeaderTextBlock}" Text="{DynamicResource String_Header_Destination}" />
<Grid Grid.Row="1" Margin="0,0,0,20">
Expand Down Expand Up @@ -104,7 +106,7 @@
<TextBlock Grid.Row="2" Foreground="{DynamicResource AccentColorBrush}" Text="{Binding StatusMessage}" Visibility="{Binding DisplayStatusMessage, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{DynamicResource DefaultTextBlock}" Margin="0,10,0,0" />
</Grid>
<TextBlock Grid.Row="2" Text="{DynamicResource String_Header_Route}" Style="{StaticResource HeaderTextBlock}" />
<Control:ScrollingDataGrid Grid.Row="3" Style="{StaticResource MetroDataGrid}" FontSize="14" mah:ControlsHelper.ContentCharacterCasing="Normal" ItemsSource="{Binding TraceResult}" CanUserResizeColumns="False" VerticalScrollBarVisibility="Auto" AutoGenerateColumns="False" IsReadOnly="True" CanUserSortColumns="False">
<Control:ScrollingDataGrid Grid.Row="3" Style="{StaticResource MetroDataGrid}" FontSize="14" mah:ControlsHelper.ContentCharacterCasing="Normal" ItemsSource="{Binding TraceResult}" CanUserResizeColumns="False" VerticalScrollBarVisibility="Auto" AutoGenerateColumns="False" IsReadOnly="True" CanUserSortColumns="False" Margin="0,0,0,20">
<Control:ScrollingDataGrid.Resources>
<Style TargetType="{x:Type ScrollBar}" BasedOn="{StaticResource ScrollingDataGridScrollBar}" />
</Control:ScrollingDataGrid.Resources>
Expand Down Expand Up @@ -138,5 +140,43 @@
<DataGridTextColumn Header="{DynamicResource String_Hostname}" Binding="{Binding Hostname}" MinWidth="150"/>
</Control:ScrollingDataGrid.Columns>
</Control:ScrollingDataGrid>
<Expander Grid.Row="4" IsExpanded="{Binding ExpandStatistics}" Style="{StaticResource DefaultExpander}">
<Expander.Header>
<TextBlock Text="{DynamicResource String_Header_Statistics}" Style="{StaticResource HeaderTextBlock}" Margin="0" />
</Expander.Header>
<StackPanel>
<Grid Margin="0,10,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.Resources>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource CenterTextBlock}" />
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextBlockAsTextBox}">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="ContextMenu" Value="{StaticResource CopyContextMenu}" />
</Style>
</Grid.Resources>
<TextBlock Grid.Column="0" Grid.Row="0" Text="{DynamicResource String_StartTime}" />
<TextBox Grid.Column="1" Grid.Row="0" Text="{Binding StartTime, Converter={StaticResource NullableDateTimeToStringConverter}}" />
<TextBlock Grid.Column="0" Grid.Row="2" Text="{DynamicResource String_Duration}" />
<TextBox Grid.Column="1" Grid.Row="2" Text="{Binding Duration, StringFormat={}{0:hh}h {0:mm}m {0:ss}s {0:ff}ms}" />
<TextBlock Grid.Column="0" Grid.Row="4" Text="{DynamicResource String_EndTime}" />
<TextBox Grid.Column="1" Grid.Row="4" Text="{Binding EndTime, Converter={StaticResource NullableDateTimeToStringConverter}}" />
<TextBlock Grid.Column="3" Grid.Row="0" Text="{DynamicResource String_Hops}" />
<TextBox Grid.Column="4" Grid.Row="0" Text="{Binding Hops}" />
</Grid>
</StackPanel>
</Expander>
</Grid>
</UserControl>

0 comments on commit 9307413

Please sign in to comment.