Skip to content

Commit 2da2c7c

Browse files
committed
Close #45, UI improved
1 parent 0969c7d commit 2da2c7c

14 files changed

Lines changed: 205 additions & 75 deletions

Source/NETworkManager/Converters/IPAddressToStringConverter.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
using System;
22
using System.Globalization;
3+
using System.Net;
34
using System.Windows.Data;
45

56
namespace NETworkManager.Converters
67
{
7-
public sealed class NullOrEmptyToStringConverter : IValueConverter
8+
public sealed class IPAddressToStringConverter : IValueConverter
89
{
910
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
1011
{
11-
string str = value as string;
12-
13-
if (string.IsNullOrEmpty(str))
12+
if (value == null)
1413
return "-/-";
15-
16-
return str;
14+
15+
return ((IPAddress)value).ToString();
1716
}
1817

1918
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

Source/NETworkManager/Converters/IntToStringConverter.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ public sealed class IntToStringConverter : IValueConverter
88
{
99
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
1010
{
11-
long test;
11+
long.TryParse(value.ToString(), out long intValue);
1212

13-
long.TryParse(value.ToString(), out test);
14-
15-
if (test == 0)
13+
if (intValue == 0)
1614
return string.Format("-/-");
1715

1816
return value.ToString();

Source/NETworkManager/Converters/NullOrEmptyToStringConverter.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
using System;
22
using System.Globalization;
3-
using System.Net;
43
using System.Windows.Data;
54

65
namespace NETworkManager.Converters
76
{
8-
public sealed class IPAddressToStringConverter : IValueConverter
7+
public sealed class NullOrEmptyToStringConverter : IValueConverter
98
{
109
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
1110
{
12-
if (value == null)
11+
string str = value as string;
12+
13+
if (string.IsNullOrEmpty(str))
1314
return "-/-";
14-
15-
return ((IPAddress)value).ToString();
15+
16+
return str;
1617
}
1718

1819
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

Source/NETworkManager/Models/Network/DNSLookup.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,32 +51,32 @@ public void LookupAsync(string hostnameOrIPAddress, DNSLookupOptions DNSLookupOp
5151

5252
if (DNSLookupOptions.UseCustomDNSServer)
5353
DNSResolver.DnsServer = DNSLookupOptions.CustomDNSServer;
54-
54+
5555
DNSResolver.Recursion = DNSLookupOptions.Recursion;
5656
DNSResolver.TransportType = DNSLookupOptions.TransportType;
5757
DNSResolver.Retries = DNSLookupOptions.Attempts;
5858
DNSResolver.TimeOut = DNSLookupOptions.Timeout;
5959

60-
Response DNSResponse = DNSResolver.Query(hostnameOrIPAddress, DNSLookupOptions.Type, DNSLookupOptions.Class);
60+
Response dnsResponse = DNSResolver.Query(hostnameOrIPAddress, DNSLookupOptions.Type, DNSLookupOptions.Class);
6161

6262
// If there was an error... return
63-
if (!string.IsNullOrEmpty(DNSResponse.Error))
63+
if (!string.IsNullOrEmpty(dnsResponse.Error))
6464
{
65-
OnLookupError(new DNSLookupErrorArgs(DNSResponse.Error, DNSResolver.DnsServer));
65+
OnLookupError(new DNSLookupErrorArgs(dnsResponse.Error, DNSResolver.DnsServer));
6666
return;
6767
}
68-
68+
6969
// Process the results...
70-
ProcessResponse(DNSResponse);
70+
ProcessResponse(dnsResponse);
7171

7272
// If we get a CNAME back (from a result), do a second request and try to get the A, AAAA etc...
73-
if(DNSLookupOptions.ResolveCNAME && DNSLookupOptions.Type != QType.CNAME)
73+
if (DNSLookupOptions.ResolveCNAME && DNSLookupOptions.Type != QType.CNAME)
7474
{
75-
foreach (RecordCNAME r in DNSResponse.RecordsCNAME)
75+
foreach (RecordCNAME r in dnsResponse.RecordsCNAME)
7676
{
7777
Response DNSResponse2 = DNSResolver.Query(r.CNAME, DNSLookupOptions.Type, DNSLookupOptions.Class);
7878

79-
if(!string.IsNullOrEmpty(DNSResponse2.Error))
79+
if (!string.IsNullOrEmpty(DNSResponse2.Error))
8080
{
8181
OnLookupError(new DNSLookupErrorArgs(DNSResponse2.Error, DNSResolver.DnsServer));
8282
continue;
@@ -85,43 +85,43 @@ public void LookupAsync(string hostnameOrIPAddress, DNSLookupOptions DNSLookupOp
8585
ProcessResponse(DNSResponse2);
8686
}
8787
}
88-
89-
OnLookupComplete(new DNSLookupCompleteArgs(DNSResponse.RecordsA.Length + DNSResponse.RecordsAAAA.Length + DNSResponse.RecordsCNAME.Length + DNSResponse.RecordsMX.Length + DNSResponse.RecordsNS.Length + DNSResponse.RecordsPTR.Length + DNSResponse.RecordsSOA.Length + DNSResponse.RecordsTXT.Length));
88+
89+
OnLookupComplete(new DNSLookupCompleteArgs(dnsResponse.Server.ToString(), dnsResponse.Questions.Count, dnsResponse.Answers.Count, dnsResponse.Authorities.Count, dnsResponse.Additionals.Count, dnsResponse.MessageSize));
9090
});
9191
}
9292

93-
private void ProcessResponse(Response DNSResponse)
93+
private void ProcessResponse(Response dnsResponse)
9494
{
9595
// A
96-
foreach (RecordA r in DNSResponse.RecordsA)
96+
foreach (RecordA r in dnsResponse.RecordsA)
9797
OnRecordReceived(new DNSLookupRecordArgs(r.RR, r));
9898

9999
// AAAA
100-
foreach (RecordAAAA r in DNSResponse.RecordsAAAA)
100+
foreach (RecordAAAA r in dnsResponse.RecordsAAAA)
101101
OnRecordReceived(new DNSLookupRecordArgs(r.RR, r));
102102

103103
// CNAME
104-
foreach (RecordCNAME r in DNSResponse.RecordsCNAME)
104+
foreach (RecordCNAME r in dnsResponse.RecordsCNAME)
105105
OnRecordReceived(new DNSLookupRecordArgs(r.RR, r));
106106

107107
// MX
108-
foreach (RecordMX r in DNSResponse.RecordsMX)
108+
foreach (RecordMX r in dnsResponse.RecordsMX)
109109
OnRecordReceived(new DNSLookupRecordArgs(r.RR, r));
110110

111111
// NS
112-
foreach (RecordNS r in DNSResponse.RecordsNS)
112+
foreach (RecordNS r in dnsResponse.RecordsNS)
113113
OnRecordReceived(new DNSLookupRecordArgs(r.RR, r));
114114

115115
// PTR
116-
foreach (RecordPTR r in DNSResponse.RecordsPTR)
116+
foreach (RecordPTR r in dnsResponse.RecordsPTR)
117117
OnRecordReceived(new DNSLookupRecordArgs(r.RR, r));
118118

119119
// SOA
120-
foreach (RecordSOA r in DNSResponse.RecordsSOA)
120+
foreach (RecordSOA r in dnsResponse.RecordsSOA)
121121
OnRecordReceived(new DNSLookupRecordArgs(r.RR, r));
122122

123123
// TXT
124-
foreach (RecordTXT r in DNSResponse.RecordsTXT)
124+
foreach (RecordTXT r in dnsResponse.RecordsTXT)
125125
OnRecordReceived(new DNSLookupRecordArgs(r.RR, r));
126126
}
127127
#endregion

Source/NETworkManager/Models/Network/DNSLookupCompleteArgs.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22
{
33
public class DNSLookupCompleteArgs : System.EventArgs
44
{
5-
public int ResourceRecordsCount { get; set; }
5+
public string ServerAndPort { get; set; }
6+
public int QuestionsCount { get; set; }
7+
public int AnswersCount { get; set; }
8+
public int AuthoritiesCount { get; set; }
9+
public int AdditionalsCount { get; set; }
10+
public int MessageSize { get; set; }
611

712
public DNSLookupCompleteArgs()
813
{
914

1015
}
1116

12-
public DNSLookupCompleteArgs(int resourceRecordsCount)
17+
public DNSLookupCompleteArgs(string serverAndPort, int questionsCount, int answersCount, int authoritiesCount, int additionalsCount, int messageSize)
1318
{
14-
ResourceRecordsCount = resourceRecordsCount;
19+
ServerAndPort = serverAndPort;
20+
QuestionsCount = questionsCount;
21+
AnswersCount = answersCount;
22+
AuthoritiesCount = authoritiesCount;
23+
AdditionalsCount = additionalsCount;
24+
MessageSize = messageSize;
1525
}
1626
}
1727
}

Source/NETworkManager/NETworkManager.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@
369369
<Compile Include="Controls\MultiSelectDataGrid.cs" />
370370
<Compile Include="Controls\ScrollingDataGrid.cs" />
371371
<Compile Include="Converters\PortStatusToStringConverter.cs" />
372-
<Compile Include="Converters\NullOrEmptyToStringConverter.cs" />
372+
<Compile Include="Converters\IPAddressToStringConverter.cs" />
373373
<Compile Include="Converters\ValidateSettingsImportConverter.cs" />
374374
<Compile Include="Converters\ValidateSettingsResetConverter.cs" />
375375
<Compile Include="Converters\ValidateSettingsExportConverter.cs" />
@@ -494,7 +494,7 @@
494494
<Compile Include="Converters\PingTimeToStringConverter.cs" />
495495
<Compile Include="Converters\IPStatusToStringConverter.cs" />
496496
<Compile Include="Converters\BooleanOrConverter.cs" />
497-
<Compile Include="Converters\IPAddressToStringConverter.cs" />
497+
<Compile Include="Converters\NullOrEmptyToStringConverter.cs" />
498498
<Compile Include="Converters\SelectedItemsToBoolConverter.cs" />
499499
<Compile Include="Converters\IntToStringConverter.cs" />
500500
<Compile Include="Views\Settings\SettingsApplicationPortScannerView.xaml.cs">

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@
226226
<system:String x:Key="String_Override">überschreiben</system:String>
227227
<system:String x:Key="String_Add">hinzufügen</system:String>
228228
<system:String x:Key="String_NoProfilesFoundCreateOne">Keine Profile gefunden! Erstelle eins...</system:String>
229+
<system:String x:Key="String_DNSServer">DNS-Server</system:String>
230+
<system:String x:Key="String_Questions">Anfragen</system:String>
231+
<system:String x:Key="String_Answers">Antworten</system:String>
232+
<system:String x:Key="String_Authorities">Authorities</system:String>
233+
<system:String x:Key="String_Additionals">Additionals</system:String>
234+
<system:String x:Key="String_MessageSize">Nachrichtengröße</system:String>
229235

230236
<!-- Buttons -->
231237
<system:String x:Key="String_Button_Change">Wechseln</system:String>

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,13 @@
226226
<system:String x:Key="String_Override">override</system:String>
227227
<system:String x:Key="String_Add">add</system:String>
228228
<system:String x:Key="String_NoProfilesFoundCreateOne">No profiles found! Create one...</system:String>
229-
229+
<system:String x:Key="String_DNSServer">DNS Server</system:String>
230+
<system:String x:Key="String_Questions">Questions</system:String>
231+
<system:String x:Key="String_Answers">Answers</system:String>
232+
<system:String x:Key="String_Authorities">Authorities</system:String>
233+
<system:String x:Key="String_Additionals">Additionals</system:String>
234+
<system:String x:Key="String_MessageSize">Message size</system:String>
235+
230236
<!-- Buttons -->
231237
<system:String x:Key="String_Button_Change">Change</system:String>
232238
<system:String x:Key="String_Button_Default">Default</system:String>

Source/NETworkManager/ViewModels/Applications/DNSLookupViewModel.cs

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,90 @@ public DateTime? EndTime
149149
}
150150
}
151151

152+
private string _dnsServerAndPort;
153+
public string DNSServerAndPort
154+
{
155+
get { return _dnsServerAndPort; }
156+
set
157+
{
158+
if (value == _dnsServerAndPort)
159+
return;
160+
161+
_dnsServerAndPort = value;
162+
OnPropertyChanged();
163+
}
164+
}
165+
166+
private int _questions;
167+
public int Questions
168+
{
169+
get { return _questions; }
170+
set
171+
{
172+
if (value == _questions)
173+
return;
174+
175+
_questions = value;
176+
OnPropertyChanged();
177+
}
178+
}
179+
180+
private int _answers;
181+
public int Answers
182+
{
183+
get { return _answers; }
184+
set
185+
{
186+
if (value == _answers)
187+
return;
188+
189+
_answers = value;
190+
OnPropertyChanged();
191+
}
192+
}
193+
194+
private int _authorities;
195+
public int Authorities
196+
{
197+
get { return _authorities; }
198+
set
199+
{
200+
if (value == _authorities)
201+
return;
202+
203+
_authorities = value;
204+
OnPropertyChanged();
205+
}
206+
}
207+
208+
private int _additionals;
209+
public int Additionals
210+
{
211+
get { return _additionals; }
212+
set
213+
{
214+
if (value == _additionals)
215+
return;
216+
217+
_additionals = value;
218+
OnPropertyChanged();
219+
}
220+
}
221+
222+
private int _messageSize;
223+
public int MessageSize
224+
{
225+
get { return _messageSize; }
226+
set
227+
{
228+
if (value == _messageSize)
229+
return;
230+
231+
_messageSize = value;
232+
OnPropertyChanged();
233+
}
234+
}
235+
152236
private bool _expandStatistics;
153237
public bool ExpandStatistics
154238
{
@@ -205,6 +289,14 @@ private void StartLookup()
205289
DisplayStatusMessage = false;
206290
IsLookupRunning = true;
207291

292+
// Reset statistic
293+
DNSServerAndPort = string.Empty;
294+
Questions = 0;
295+
Answers = 0;
296+
Authorities = 0;
297+
Additionals = 0;
298+
MessageSize = 0;
299+
208300
// Measure the time
209301
StartTime = DateTime.Now;
210302
stopwatch.Start();
@@ -311,7 +403,14 @@ private void DNSLookup_LookupError(object sender, DNSLookupErrorArgs e)
311403

312404
private void DNSLookup_LookupComplete(object sender, DNSLookupCompleteArgs e)
313405
{
314-
if (e.ResourceRecordsCount == 0)
406+
DNSServerAndPort = e.ServerAndPort;
407+
Questions = e.QuestionsCount;
408+
Answers = e.AnswersCount;
409+
Authorities = e.AuthoritiesCount;
410+
Additionals = e.AdditionalsCount;
411+
MessageSize = e.MessageSize;
412+
413+
if (e.AnswersCount == 0)
315414
{
316415
StatusMessage = string.Format(Application.Current.Resources["String_NoDNSRecordFoundCheckYourInputAndSettings"] as string, HostnameOrIPAddress);
317416
DisplayStatusMessage = true;

0 commit comments

Comments
 (0)