Skip to content

Commit 26b49c0

Browse files
committed
Done #25 - Error messages improved
1 parent 225d3ea commit 26b49c0

5 files changed

Lines changed: 213 additions & 154 deletions

File tree

Source/NETworkManager/Resources/Localization/Resources.de-DE.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@
217217
<system:String x:Key="String_TimeoutWhenQueryingDNSServer">Timeout beim Abfragen des DNS-Servers mit der IP-Adresse "{0}"!</system:String>
218218
<system:String x:Key="String_ResolveCNAME">CNAME auflösen</system:String>
219219
<system:String x:Key="String_Host">Host</system:String>
220+
<system:String x:Key="String_CouldNotResolveHostnameFor">Hostname konnte nicht aufgelöst werden für: "{0}"</system:String>
221+
<system:String x:Key="String_NothingToDoCheckYourInput">Nichts zu tun. Überprüfen Sie Ihre Eingabe!</system:String>
220222

221223
<!-- Buttons -->
222224
<system:String x:Key="String_Button_Change">Wechseln</system:String>

Source/NETworkManager/Resources/Localization/Resources.en-US.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@
219219
<system:String x:Key="String_TimeoutWhenQueryingDNSServer">Timeout when querying the DNS server with the IP-Address "{0}"!</system:String>
220220
<system:String x:Key="String_ResolveCNAME">Resolve CNAME</system:String>
221221
<system:String x:Key="String_Host">Host</system:String>
222-
222+
<system:String x:Key="String_CouldNotResolveHostnameFor">Could not resolve hostname for: "{0}"</system:String>
223+
<system:String x:Key="String_NothingToDoCheckYourInput">Nothing to do. Check your input!</system:String>
224+
223225
<!-- Buttons -->
224226
<system:String x:Key="String_Button_Change">Change</system:String>
225227
<system:String x:Key="String_Button_Default">Default</system:String>

Source/NETworkManager/ViewModels/Applications/DNSLookupViewModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public string ErrorMessage
103103
OnPropertyChanged();
104104
}
105105
}
106-
107106
#endregion
108107

109108
#region Contructor

Source/NETworkManager/ViewModels/Applications/PortScannerViewModel.cs

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,34 @@ public bool PreparingScan
167167
OnPropertyChanged();
168168
}
169169
}
170+
171+
private bool _displayErrorMessage;
172+
public bool DisplayErrorMessage
173+
{
174+
get { return _displayErrorMessage; }
175+
set
176+
{
177+
if (value == _displayErrorMessage)
178+
return;
179+
180+
_displayErrorMessage = value;
181+
OnPropertyChanged();
182+
}
183+
}
184+
185+
private string _errorMessage;
186+
public string ErrorMessage
187+
{
188+
get { return _errorMessage; }
189+
set
190+
{
191+
if (value == _errorMessage)
192+
return;
193+
194+
_errorMessage = value;
195+
OnPropertyChanged();
196+
}
197+
}
170198
#endregion
171199

172200
#region Constructor, Load settings
@@ -214,29 +242,33 @@ private void ScanAction()
214242
#region Methods
215243
private async void StartScan()
216244
{
245+
DisplayErrorMessage = false;
246+
ErrorMessage = string.Empty;
247+
217248
IsScanRunning = true;
218249
PreparingScan = true;
219250

220251
PortScanResult.Clear();
221252

222253
cancellationTokenSource = new CancellationTokenSource();
223254

224-
string[] HostnameOrIPAddresses = HostnameOrIPAddress.Split(';');
255+
string[] hosts = HostnameOrIPAddress.Split(';');
225256

226257
List<Tuple<IPAddress, string>> hostData = new List<Tuple<IPAddress, string>>();
227258

228-
for (int i = 0; i < HostnameOrIPAddresses.Length; i++)
259+
for (int i = 0; i < hosts.Length; i++)
229260
{
230-
string hostname = HostnameOrIPAddresses[i];
231-
IPAddress.TryParse(hostname, out IPAddress ipAddress);
261+
string host = hosts[i].Trim();
262+
string hostname = string.Empty;
263+
IPAddress.TryParse(host, out IPAddress ipAddress);
232264

233265
try
234266
{
235267
// Resolve DNS
236268
// Try to resolve the hostname
237269
if (ipAddress == null)
238270
{
239-
IPHostEntry ipHostEntry = await Dns.GetHostEntryAsync(HostnameOrIPAddress);
271+
IPHostEntry ipHostEntry = await Dns.GetHostEntryAsync(host);
240272

241273
foreach (IPAddress ip in ipHostEntry.AddressList)
242274
{
@@ -261,18 +293,28 @@ private async void StartScan()
261293
continue;
262294
}
263295
}
296+
297+
hostname = host;
264298
}
265299
else
266300
{
267-
IPHostEntry ipHostEntry = await Dns.GetHostEntryAsync(ipAddress);
301+
try
302+
{
303+
IPHostEntry ipHostEntry = await Dns.GetHostEntryAsync(ipAddress);
268304

269-
if (ipHostEntry != null)
270305
hostname = ipHostEntry.HostName;
306+
}
307+
catch { }
271308
}
272309
}
273310
catch (SocketException) // This will catch DNS resolve errors
274311
{
275-
await dialogCoordinator.ShowMessageAsync(this, Application.Current.Resources["String_Header_DnsError"] as string, Application.Current.Resources["String_CouldNotResolveHostnameMessage"] as string, MessageDialogStyle.Affirmative, dialogSettings);
312+
if (!string.IsNullOrEmpty(ErrorMessage))
313+
ErrorMessage += Environment.NewLine;
314+
315+
ErrorMessage += string.Format(Application.Current.Resources["String_CouldNotResolveHostnameFor"] as string, host);
316+
DisplayErrorMessage = true;
317+
276318
continue;
277319
}
278320

@@ -282,7 +324,9 @@ private async void StartScan()
282324
if (hostData.Count == 0)
283325
{
284326
IsScanRunning = false;
285-
await dialogCoordinator.ShowMessageAsync(this, Application.Current.Resources["String_Header_DnsError"] as string, "Nothing to do", MessageDialogStyle.Affirmative, dialogSettings);
327+
328+
ErrorMessage += Environment.NewLine + Application.Current.Resources["String_NothingToDoCheckYourInput"] as string;
329+
DisplayErrorMessage = true;
286330

287331
return;
288332
}
@@ -318,17 +362,21 @@ private async void StartScan()
318362
catch (Exception ex) // This will catch any exception
319363
{
320364
IsScanRunning = false;
321-
await dialogCoordinator.ShowMessageAsync(this, Application.Current.Resources["String_Header_Error"] as string, ex.Message, MessageDialogStyle.Affirmative, dialogSettings);
365+
366+
ErrorMessage = ex.Message;
367+
DisplayErrorMessage = true;
322368
}
323369
}
324370

325371
#region Events
326-
private async void PortScanner_UserHasCanceled(object sender, EventArgs e)
372+
private void PortScanner_UserHasCanceled(object sender, EventArgs e)
327373
{
328374
CancelScan = false;
329375
IsScanRunning = false;
330376

331-
await dialogCoordinator.ShowMessageAsync(this, Application.Current.Resources["String_Header_CanceledByUser"] as string, Application.Current.Resources["String_CanceledByUserMessage"] as string, MessageDialogStyle.Affirmative, dialogSettings);
377+
ErrorMessage = Application.Current.Resources["String_CanceledByUserMessage"] as string;
378+
DisplayErrorMessage = true;
379+
332380
}
333381

334382
private void PortScanner_ProgressChanged(object sender, ProgressChangedArgs e)

0 commit comments

Comments
 (0)