Skip to content

Commit 94c3aa2

Browse files
committed
DNS Lookup error message added
1 parent 081bf1a commit 94c3aa2

7 files changed

Lines changed: 75 additions & 41 deletions

File tree

Source/NETworkManager/3rdParty/Heijden.DNS/Resolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ private Response TcpRequest(Request request)
409409
{
410410
IAsyncResult result = tcpClient.BeginConnect(m_DnsServers[intDnsServer].Address, m_DnsServers[intDnsServer].Port, null, null);
411411

412-
bool success = result.AsyncWaitHandle.WaitOne(m_Timeout * 1000, true);
412+
bool success = result.AsyncWaitHandle.WaitOne(m_Timeout, true);
413413

414414
if (!success || !tcpClient.Connected)
415415
{

Source/NETworkManager/Models/Network/DNSLookup.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void LookupAsync(string hostnameOrIPAddress, DNSLookupOptions dnsLookupOp
6363
// If there was an error... return
6464
if (!string.IsNullOrEmpty(dnsResponse.Error))
6565
{
66-
OnLookupError(new DNSLookupErrorArgs(dnsResponse.Error));
66+
OnLookupError(new DNSLookupErrorArgs(dnsResponse.Error, dnsResolver.DnsServer));
6767
return;
6868
}
6969

@@ -73,8 +73,18 @@ public void LookupAsync(string hostnameOrIPAddress, DNSLookupOptions dnsLookupOp
7373
// If we get a CNAME back (from a result), do a second request and try to get the A, AAAA etc...
7474
if(dnsLookupOptions.Type != QType.CNAME)
7575
{
76-
foreach(RecordCNAME r in dnsResponse.RecordsCNAME)
77-
ProcessResponse(dnsResolver.Query(r.CNAME, dnsLookupOptions.Type, dnsLookupOptions.Class));
76+
foreach (RecordCNAME r in dnsResponse.RecordsCNAME)
77+
{
78+
Response dnsResponse2 = dnsResolver.Query(r.CNAME, dnsLookupOptions.Type, dnsLookupOptions.Class);
79+
80+
if(!string.IsNullOrEmpty(dnsResponse2.Error))
81+
{
82+
OnLookupError(new DNSLookupErrorArgs(dnsResponse2.Error, dnsResolver.DnsServer));
83+
continue;
84+
}
85+
86+
ProcessResponse(dnsResponse2);
87+
}
7888
}
7989

8090
OnLookupComplete();
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
namespace NETworkManager.Models.Network
1+
using System.Net;
2+
3+
namespace NETworkManager.Models.Network
24
{
35
public class DNSLookupErrorArgs : System.EventArgs
46
{
5-
public string Error { get; set; }
6-
7+
public string ErrorCode { get; set; }
8+
public string DNSServer { get; set; }
9+
710
public DNSLookupErrorArgs()
811
{
912

1013
}
1114

12-
public DNSLookupErrorArgs(string error)
15+
public DNSLookupErrorArgs(string errorCode, string dnsServer)
1316
{
14-
Error = error;
17+
ErrorCode = errorCode;
18+
DNSServer = dnsServer;
1519
}
1620
}
1721
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@
212212
<system:String x:Key="String_Recursion">Rekursion</system:String>
213213
<system:String x:Key="String_UseResolverCache">Resolver-Cache verwenden</system:String>
214214
<system:String x:Key="String_Result">Ergebnis</system:String>
215+
<system:String x:Key="String_NoDnsRecordFoundCheckYourInputAndSettings">Kein DNS-Eintrag für "{0}" gefunden! Überprüfe deine Eingabe und die Einstellungen.</system:String>
216+
<system:String x:Key="String_UnkownError">Unbekannter Fehler!</system:String>
217+
<system:String x:Key="String_TimeoutWhenQueryingDNSServer">Timeout beim Abfragen des DNS-Servers mit der IP-Adresse "{0}"!</system:String>
215218

216219
<!-- Buttons -->
217220
<system:String x:Key="String_Button_Change">Wechseln</system:String>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@
214214
<system:String x:Key="String_Recursion">Recursion</system:String>
215215
<system:String x:Key="String_UseResolverCache">Use resolver cache</system:String>
216216
<system:String x:Key="String_Result">Result</system:String>
217+
<system:String x:Key="String_NoDnsRecordFoundCheckYourInputAndSettings">No dns record found for "{0}"! Check your input and the settings.</system:String>
218+
<system:String x:Key="String_UnkownError">Unkown error!</system:String>
219+
<system:String x:Key="String_TimeoutWhenQueryingDNSServer">Timeout when querying the DNS server with the IP-Address "{0}"!</system:String>
217220

218221
<!-- Buttons -->
219222
<system:String x:Key="String_Button_Change">Change</system:String>

Source/NETworkManager/ViewModels/Applications/DNSLookupViewModel.cs

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,48 @@ public bool IsLookupRunning
6262
OnPropertyChanged();
6363
}
6464
}
65+
66+
private AsyncObservableCollection<DNSLookupRecordInfo> _lookupResult = new AsyncObservableCollection<DNSLookupRecordInfo>();
67+
public AsyncObservableCollection<DNSLookupRecordInfo> LookupResult
68+
{
69+
get { return _lookupResult; }
70+
set
71+
{
72+
if (value == _lookupResult)
73+
return;
74+
75+
_lookupResult = value;
76+
}
77+
}
6578

66-
private bool _cancelLookup;
67-
public bool CancelLookup
79+
private bool _displayErrorMessage;
80+
public bool DisplayErrorMessage
6881
{
69-
get { return _cancelLookup; }
82+
get { return _displayErrorMessage; }
7083
set
7184
{
72-
if (value == _cancelLookup)
85+
if (value == _displayErrorMessage)
7386
return;
7487

75-
_cancelLookup = value;
88+
_displayErrorMessage = value;
7689
OnPropertyChanged();
7790
}
7891
}
7992

80-
private AsyncObservableCollection<DNSLookupRecordInfo> _lookupResult = new AsyncObservableCollection<DNSLookupRecordInfo>();
81-
public AsyncObservableCollection<DNSLookupRecordInfo> LookupResult
93+
private string _errorMessage;
94+
public string ErrorMessage
8295
{
83-
get { return _lookupResult; }
96+
get { return _errorMessage; }
8497
set
8598
{
86-
if (value == _lookupResult)
99+
if (value == _errorMessage)
87100
return;
88101

89-
_lookupResult = value;
102+
_errorMessage = value;
103+
OnPropertyChanged();
90104
}
91105
}
106+
92107
#endregion
93108

94109
#region Contructor
@@ -131,11 +146,12 @@ private void LookupAction()
131146
#region Methods
132147
private void StartLookup()
133148
{
149+
DisplayErrorMessage = false;
134150
IsLookupRunning = true;
135151

136152
// Reset the latest results
137153
LookupResult.Clear();
138-
154+
139155
HostnameOrIPAddressHistory = new List<string>(HistoryListHelper.Modify(HostnameOrIPAddressHistory, HostnameOrIPAddress, SettingsManager.Current.Application_HistoryListEntries));
140156

141157
DNSLookupOptions dnsLookupOptions = new DNSLookupOptions
@@ -174,12 +190,24 @@ private void DnsLookup_RecordReceived(object sender, DNSLookupRecordArgs e)
174190

175191
private void DnsLookup_LookupError(object sender, DNSLookupErrorArgs e)
176192
{
177-
MessageBox.Show(e.Error);
193+
if (e.ErrorCode == "Timeout Error")
194+
ErrorMessage = string.Format(Application.Current.Resources["String_TimeoutWhenQueryingDNSServer"] as string, e.DNSServer);
195+
else
196+
ErrorMessage = Application.Current.Resources["String_UnkownError"] as string;
197+
198+
DisplayErrorMessage = true;
199+
178200
IsLookupRunning = false;
179201
}
180202

181203
private void DnsLookup_LookupComplete(object sender, EventArgs e)
182204
{
205+
if (LookupResult.Count == 0)
206+
{
207+
ErrorMessage = string.Format(Application.Current.Resources["String_NoDnsRecordFoundCheckYourInputAndSettings"] as string, HostnameOrIPAddress);
208+
DisplayErrorMessage = true;
209+
}
210+
183211
IsLookupRunning = false;
184212
}
185213
#endregion

Source/NETworkManager/Views/Applications/DNSLookupView.xaml

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626
<Grid.RowDefinitions>
2727
<RowDefinition Height="Auto" />
2828
<RowDefinition Height="Auto" />
29+
<RowDefinition Height="Auto" />
2930
</Grid.RowDefinitions>
3031
<Grid Grid.Row="0">
3132
<Grid.ColumnDefinitions>
3233
<ColumnDefinition Width="*" />
3334
<ColumnDefinition Width="Auto" />
3435
</Grid.ColumnDefinitions>
35-
<ComboBox Grid.Column="0" x:Name="txtHostnameOrIPAddress" ItemsSource="{Binding HostnameOrIPAddressHistory}" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_HostnameOrIPAddress}" Validation.ErrorTemplate="{StaticResource DefaultErrorTemplate}" IsEnabled="{Binding IsPingRunning, Converter={StaticResource BooleanReverseConverter}}" Style="{StaticResource HistoryComboBox}">
36+
<ComboBox Grid.Column="0" x:Name="txtHostnameOrIPAddress" ItemsSource="{Binding HostnameOrIPAddressHistory}" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_HostnameOrIPAddress}" Validation.ErrorTemplate="{StaticResource DefaultErrorTemplate}" IsEnabled="{Binding IsLookupRunning, Converter={StaticResource BooleanReverseConverter}}" Style="{StaticResource HistoryComboBox}">
3637
<ComboBox.Text>
3738
<Binding Path="HostnameOrIPAddress" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
3839
<Binding.ValidationRules>
@@ -41,15 +42,15 @@
4142
</Binding>
4243
</ComboBox.Text>
4344
</ComboBox>
44-
<Button Grid.Column="1" Command="{Binding LookupCommand}" IsDefault="{Binding IsLookupRunning, Converter={StaticResource BooleanReverseConverter}}" IsCancel="{Binding IsLookupRunning}" HorizontalAlignment="Right" Margin="10,0,0,0">
45+
<Button Grid.Column="1" Command="{Binding LookupCommand}" IsDefault="{Binding IsLookupRunning, Converter={StaticResource BooleanReverseConverter}}" HorizontalAlignment="Right" Margin="10,0,0,0">
4546
<Button.Resources>
4647
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource ImageWithTextButton}">
4748
<Setter Property="IsEnabled" Value="True" />
4849
<Style.Triggers>
4950
<DataTrigger Binding="{Binding Path=(Validation.HasError), ElementName=txtHostnameOrIPAddress}" Value="True" >
5051
<Setter Property="IsEnabled" Value="False" />
5152
</DataTrigger>
52-
<DataTrigger Binding="{Binding CancelPing}" Value="True">
53+
<DataTrigger Binding="{Binding IsLookupRunning}" Value="True">
5354
<Setter Property="IsEnabled" Value="False" />
5455
</DataTrigger>
5556
</Style.Triggers>
@@ -70,26 +71,10 @@
7071
<Style TargetType="{x:Type Rectangle}">
7172
<Setter Property="OpacityMask" Value="{StaticResource VisualControlPlay}" />
7273
<Setter Property="Fill" Value="{DynamicResource GrayBrush3}" />
73-
<Style.Triggers>
74-
<DataTrigger Binding="{Binding IsLookupRunning}" Value="True">
75-
<Setter Property="OpacityMask" Value="{StaticResource VisualClose}" />
76-
</DataTrigger>
77-
</Style.Triggers>
7874
</Style>
7975
</Rectangle.Style>
8076
</Rectangle>
81-
<TextBlock Grid.Column="1" FontSize="14" Margin="10,5" TextAlignment="Center">
82-
<TextBlock.Style>
83-
<Style TargetType="{x:Type TextBlock}">
84-
<Setter Property="Text" Value="{DynamicResource String_Button_Lookup}"/>
85-
<Style.Triggers>
86-
<DataTrigger Binding="{Binding IsLookupRunning}" Value="True" >
87-
<Setter Property="Text" Value="{DynamicResource String_Button_Cancel}"/>
88-
</DataTrigger>
89-
</Style.Triggers>
90-
</Style>
91-
</TextBlock.Style>
92-
</TextBlock>
77+
<TextBlock Grid.Column="1" FontSize="14" Text="{DynamicResource String_Button_Lookup}" Margin="10,5" TextAlignment="Center" />
9378
</Grid>
9479
</Button.Content>
9580
</Button>
@@ -105,6 +90,7 @@
10590
</Style>
10691
</Controls:MetroProgressBar.Style>
10792
</Controls:MetroProgressBar>
93+
<TextBlock Grid.Row="2" Foreground="{DynamicResource AccentColorBrush}" Text="{Binding ErrorMessage}" Visibility="{Binding DisplayErrorMessage, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{DynamicResource DefaultTextBlock}" Margin="0,10,0,0" />
10894
</Grid>
10995
<TextBlock Grid.Row="2" Text="{DynamicResource String_Header_Result}" Style="{StaticResource HeaderTextBlock}" />
11096
<Control:ScrollingDataGrid Grid.Row="3" CanUserSortColumns="False" CanUserReorderColumns="False" Style="{StaticResource MetroDataGrid}" FontSize="14" mah:ControlsHelper.ContentCharacterCasing="Normal" ItemsSource="{Binding LookupResult}" CanUserAddRows="False" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" AutoGenerateColumns="False" IsReadOnly="True">

0 commit comments

Comments
 (0)