1+ using MahApps . Metro . Controls . Dialogs ;
2+ using NETworkManager . Models . Network ;
3+ using NETworkManager . Models . Settings ;
4+ using NETworkManager . Helpers ;
5+ using System ;
6+ using System . Collections . Generic ;
7+ using System . Linq ;
8+ using System . Net ;
9+ using System . Net . Sockets ;
10+ using System . Threading ;
11+ using System . Windows ;
12+ using System . Windows . Input ;
13+ using NETworkManager . Collections ;
14+ using System . ComponentModel ;
15+ using System . Diagnostics ;
16+ using System . Windows . Threading ;
17+
18+ namespace NETworkManager . ViewModels . Applications
19+ {
20+ public class DNSLookupViewModel : ViewModelBase
21+ {
22+ #region Variables
23+ private IDialogCoordinator dialogCoordinator ;
24+ MetroDialogSettings dialogSettings = new MetroDialogSettings ( ) ;
25+
26+ CancellationTokenSource cancellationTokenSource ;
27+
28+ private bool _isLoading = true ;
29+
30+ private string _hostnameOrIPAddress ;
31+ public string HostnameOrIPAddress
32+ {
33+ get { return _hostnameOrIPAddress ; }
34+ set
35+ {
36+ if ( value == _hostnameOrIPAddress )
37+ return ;
38+
39+ _hostnameOrIPAddress = value ;
40+ OnPropertyChanged ( ) ;
41+ }
42+ }
43+
44+ private List < string > _hostnameOrIPAddressHistory = new List < string > ( ) ;
45+ public List < string > HostnameOrIPAddressHistory
46+ {
47+ get { return _hostnameOrIPAddressHistory ; }
48+ set
49+ {
50+ if ( value == _hostnameOrIPAddressHistory )
51+ return ;
52+
53+ if ( ! _isLoading )
54+ SettingsManager . Current . Ping_HostnameOrIPAddressHistory = value ;
55+
56+ _hostnameOrIPAddressHistory = value ;
57+ OnPropertyChanged ( ) ;
58+ }
59+ }
60+
61+ private bool _isLookupRunning ;
62+ public bool IsLookupRunning
63+ {
64+ get { return _isLookupRunning ; }
65+ set
66+ {
67+ if ( value == _isLookupRunning )
68+ return ;
69+
70+ _isLookupRunning = value ;
71+ OnPropertyChanged ( ) ;
72+ }
73+ }
74+
75+ private bool _cancelLookup ;
76+ public bool CancelLookup
77+ {
78+ get { return _cancelLookup ; }
79+ set
80+ {
81+ if ( value == _cancelLookup )
82+ return ;
83+
84+ _cancelLookup = value ;
85+ OnPropertyChanged ( ) ;
86+ }
87+ }
88+
89+ private AsyncObservableCollection < PingInfo > _lookupResult = new AsyncObservableCollection < PingInfo > ( ) ;
90+ public AsyncObservableCollection < PingInfo > LookupResult
91+ {
92+ get { return _lookupResult ; }
93+ set
94+ {
95+ if ( value == _lookupResult )
96+ return ;
97+
98+ _lookupResult = value ;
99+ }
100+ }
101+ #endregion
102+
103+ #region Contructor
104+ public DNSLookupViewModel ( IDialogCoordinator instance )
105+ {
106+ dialogCoordinator = instance ;
107+
108+ dialogSettings . CustomResourceDictionary = new ResourceDictionary
109+ {
110+ Source = new Uri ( "NETworkManager;component/Resources/Styles/MetroDialogStyles.xaml" , UriKind . RelativeOrAbsolute )
111+ } ;
112+
113+ LoadSettings ( ) ;
114+
115+ _isLoading = false ;
116+ }
117+ #endregion
118+
119+ #region Load settings
120+ private void LoadSettings ( )
121+ {
122+ //if (SettingsManager.Current.Ping_HostnameOrIPAddressHistory != null)
123+ // HostnameOrIPAddressHistory = new List<string>(SettingsManager.Current.Ping_HostnameOrIPAddressHistory);
124+ }
125+ #endregion
126+
127+ #region ICommands & Actions
128+ public ICommand LookupCommand
129+ {
130+ get { return new RelayCommand ( p => LookupAction ( ) ) ; }
131+ }
132+
133+ private void LookupAction ( )
134+ {
135+ if ( IsLookupRunning )
136+ StopLookup ( ) ;
137+ else
138+ StartLookup ( ) ;
139+ }
140+ #endregion
141+
142+ #region Methods
143+ private async void StartLookup ( )
144+ {
145+ IsLookupRunning = true ;
146+
147+ // Reset the latest results
148+ LookupResult . Clear ( ) ;
149+ }
150+
151+ private void StopLookup ( )
152+ {
153+ IsLookupRunning = false ;
154+ }
155+
156+ public void OnShutdown ( )
157+ {
158+ if ( IsLookupRunning )
159+ LookupAction ( ) ;
160+ }
161+ #endregion
162+ }
163+ }
0 commit comments