1111using NETworkManager . Helpers ;
1212using System . Diagnostics ;
1313using System . Windows . Threading ;
14+ using System . ComponentModel ;
15+ using System . Windows . Data ;
1416
1517namespace NETworkManager . ViewModels . Applications
1618{
@@ -24,33 +26,33 @@ public class TracerouteViewModel : ViewModelBase
2426
2527 private bool _isLoading = true ;
2628
27- private string _hostnameOrIPAddress ;
28- public string HostnameOrIPAddress
29+ private string _hostname ;
30+ public string Hostname
2931 {
30- get { return _hostnameOrIPAddress ; }
32+ get { return _hostname ; }
3133 set
3234 {
33- if ( value == _hostnameOrIPAddress )
35+ if ( value == _hostname )
3436 return ;
3537
36- _hostnameOrIPAddress = value ;
38+ _hostname = value ;
3739 OnPropertyChanged ( ) ;
3840 }
3941 }
4042
41- private List < string > _hostnameOrIPAddressHistory = new List < string > ( ) ;
42- public List < string > HostnameOrIPAddressHistory
43+ private List < string > _hostnameHistory = new List < string > ( ) ;
44+ public List < string > HostnameHistory
4345 {
44- get { return _hostnameOrIPAddressHistory ; }
46+ get { return _hostnameHistory ; }
4547 set
4648 {
47- if ( value == _hostnameOrIPAddressHistory )
49+ if ( value == _hostnameHistory )
4850 return ;
4951
5052 if ( ! _isLoading )
51- SettingsManager . Current . Traceroute_HostnameOrIPAddressHistory = value ;
53+ SettingsManager . Current . Traceroute_HostnameHistory = value ;
5254
53- _hostnameOrIPAddressHistory = value ;
55+ _hostnameHistory = value ;
5456 OnPropertyChanged ( ) ;
5557 }
5658 }
@@ -96,6 +98,26 @@ public ObservableCollection<TracerouteHopInfo> TraceResult
9698 }
9799 }
98100
101+ private ICollectionView _traceResultView ;
102+ public ICollectionView TraceResultView
103+ {
104+ get { return _traceResultView ; }
105+ }
106+
107+ private TracerouteHopInfo _selectedTraceResult ;
108+ public TracerouteHopInfo SelectedTraceResult
109+ {
110+ get { return _selectedTraceResult ; }
111+ set
112+ {
113+ if ( value == _selectedTraceResult )
114+ return ;
115+
116+ _selectedTraceResult = value ;
117+ OnPropertyChanged ( ) ;
118+ }
119+ }
120+
99121 private bool _displayStatusMessage ;
100122 public bool DisplayStatusMessage
101123 {
@@ -201,15 +223,17 @@ public int Hops
201223 #region Constructor, load settings
202224 public TracerouteViewModel ( )
203225 {
226+ _traceResultView = CollectionViewSource . GetDefaultView ( TraceResult ) ;
227+
204228 LoadSettings ( ) ;
205229
206230 _isLoading = false ;
207231 }
208232
209233 private void LoadSettings ( )
210234 {
211- if ( SettingsManager . Current . Traceroute_HostnameOrIPAddressHistory != null )
212- HostnameOrIPAddressHistory = new List < string > ( SettingsManager . Current . Traceroute_HostnameOrIPAddressHistory ) ;
235+ if ( SettingsManager . Current . Traceroute_HostnameHistory != null )
236+ HostnameHistory = new List < string > ( SettingsManager . Current . Traceroute_HostnameHistory ) ;
213237
214238 ExpandStatistics = SettingsManager . Current . Traceroute_ExpandStatistics ;
215239 }
@@ -228,6 +252,66 @@ private void TraceAction()
228252 else
229253 StartTrace ( ) ;
230254 }
255+
256+ public ICommand CopySelectedHopCommand
257+ {
258+ get { return new RelayCommand ( p => CopySelectedHopAction ( ) ) ; }
259+ }
260+
261+ private void CopySelectedHopAction ( )
262+ {
263+ Clipboard . SetText ( SelectedTraceResult . Hop . ToString ( ) ) ;
264+ }
265+
266+ public ICommand CopySelectedTime1Command
267+ {
268+ get { return new RelayCommand ( p => CopySelectedTime1Action ( ) ) ; }
269+ }
270+
271+ private void CopySelectedTime1Action ( )
272+ {
273+ Clipboard . SetText ( SelectedTraceResult . Time1 . ToString ( ) ) ;
274+ }
275+
276+ public ICommand CopySelectedTime2Command
277+ {
278+ get { return new RelayCommand ( p => CopySelectedTime2Action ( ) ) ; }
279+ }
280+
281+ private void CopySelectedTime2Action ( )
282+ {
283+ Clipboard . SetText ( SelectedTraceResult . Time2 . ToString ( ) ) ;
284+ }
285+
286+ public ICommand CopySelectedTime3Command
287+ {
288+ get { return new RelayCommand ( p => CopySelectedTime3Action ( ) ) ; }
289+ }
290+
291+ private void CopySelectedTime3Action ( )
292+ {
293+ Clipboard . SetText ( SelectedTraceResult . Time3 . ToString ( ) ) ;
294+ }
295+
296+ public ICommand CopySelectedIPAddressCommand
297+ {
298+ get { return new RelayCommand ( p => CopySelectedIPAddressAction ( ) ) ; }
299+ }
300+
301+ private void CopySelectedIPAddressAction ( )
302+ {
303+ Clipboard . SetText ( SelectedTraceResult . IPAddress . ToString ( ) ) ;
304+ }
305+
306+ public ICommand CopySelectedHostnameCommand
307+ {
308+ get { return new RelayCommand ( p => CopySelectedHostnameAction ( ) ) ; }
309+ }
310+
311+ private void CopySelectedHostnameAction ( )
312+ {
313+ Clipboard . SetText ( SelectedTraceResult . Hostname ) ;
314+ }
231315 #endregion
232316
233317 #region Methods
@@ -254,14 +338,14 @@ private async void StartTrace()
254338 Hops = 0 ;
255339
256340 // Try to parse the string into an IP-Address
257- IPAddress . TryParse ( HostnameOrIPAddress , out IPAddress ipAddress ) ;
341+ IPAddress . TryParse ( Hostname , out IPAddress ipAddress ) ;
258342
259343 try
260344 {
261345 // Try to resolve the hostname
262346 if ( ipAddress == null )
263347 {
264- IPHostEntry ipHostEntrys = await Dns . GetHostEntryAsync ( HostnameOrIPAddress ) ;
348+ IPHostEntry ipHostEntrys = await Dns . GetHostEntryAsync ( Hostname ) ;
265349
266350 foreach ( IPAddress ip in ipHostEntrys . AddressList )
267351 {
@@ -308,13 +392,13 @@ private async void StartTrace()
308392 traceroute . TraceAsync ( ipAddress , tracerouteOptions , cancellationTokenSource . Token ) ;
309393
310394 // Add the hostname or ip address to the history
311- HostnameOrIPAddressHistory = new List < string > ( HistoryListHelper . Modify ( HostnameOrIPAddressHistory , HostnameOrIPAddress , SettingsManager . Current . Application_HistoryListEntries ) ) ;
395+ HostnameHistory = new List < string > ( HistoryListHelper . Modify ( HostnameHistory , Hostname , SettingsManager . Current . Application_HistoryListEntries ) ) ;
312396 }
313397 catch ( SocketException ) // This will catch DNS resolve errors
314398 {
315399 TracerouteFinished ( ) ;
316400
317- StatusMessage = string . Format ( Application . Current . Resources [ "String_CouldNotResolveHostnameFor" ] as string , HostnameOrIPAddress ) ;
401+ StatusMessage = string . Format ( Application . Current . Resources [ "String_CouldNotResolveHostnameFor" ] as string , Hostname ) ;
318402 DisplayStatusMessage = true ;
319403 }
320404 catch ( Exception ex ) // This will catch any exception
0 commit comments