Skip to content

Commit fc31339

Browse files
BornToBeRootclaude
andcommitted
Feature: RDAP cancel, localized timeout and copy context menu
- A running query can be canceled (button switches to Cancel, Esc) and is stopped when the tab is closed. - Timeouts have their own error kind (next server is tried) and a localized message instead of a hard-coded English text. - Copy context menu for the events, nameservers, DNSSEC and contacts grids (single row), Export for multiple rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 7890270 commit fc31339

7 files changed

Lines changed: 280 additions & 16 deletions

File tree

‎Source/NETworkManager.Localization/Resources/Strings.Designer.cs‎

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Source/NETworkManager.Localization/Resources/Strings.resx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4815,4 +4815,7 @@ Cloudflare may log your IP address and network information. See Cloudflare's pri
48154815
<data name="EnterValidRDAPQuery" xml:space="preserve">
48164816
<value>Enter a valid domain, IP address, AS number or entity handle!</value>
48174817
</data>
4818+
<data name="RDAPTimeoutAfterXSeconds" xml:space="preserve">
4819+
<value>The RDAP server did not respond within {0} seconds.</value>
4820+
</data>
48184821
</root>

‎Source/NETworkManager.Models/RDAP/RDAPClient.cs‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public async Task<RDAPResult> QueryAsync(RDAPQuery query, string cacheDirectory,
118118

119119
RDAPException lastNetworkError = null;
120120

121-
// Try the next server only on network errors. Any HTTP answer is authoritative for the query.
121+
// Try the next server only on network errors and timeouts. Any HTTP answer is authoritative for the query.
122122
foreach (var baseUrl in baseUrls)
123123
{
124124
try
@@ -131,7 +131,7 @@ public async Task<RDAPResult> QueryAsync(RDAPQuery query, string cacheDirectory,
131131

132132
return result;
133133
}
134-
catch (RDAPException ex) when (ex.Kind == RDAPErrorKind.Network)
134+
catch (RDAPException ex) when (ex.Kind is RDAPErrorKind.Network or RDAPErrorKind.Timeout)
135135
{
136136
Log.Warn($"RDAP request to {ex.RequestUrl} failed: {ex.Message}");
137137
lastNetworkError = ex;
@@ -239,11 +239,16 @@ private async Task<RDAPResult> GetAsync(RDAPQuery query, string url, TimeSpan ti
239239
// Blocked by ConnectToPublicAddressAsync.
240240
throw new RDAPException(inner.Kind, inner.Message, ex) { RequestUrl = currentUrl.AbsoluteUri };
241241
}
242-
catch (Exception ex) when (ex is HttpRequestException or OperationCanceledException)
242+
catch (OperationCanceledException ex)
243243
{
244-
var message = ex is OperationCanceledException ? $"Timeout after {timeout.TotalSeconds} s." : ex.Message;
245-
246-
throw new RDAPException(RDAPErrorKind.Network, message, ex) { RequestUrl = currentUrl.AbsoluteUri };
244+
// The message is only logged, the view model shows a localized one.
245+
throw new RDAPException(RDAPErrorKind.Timeout,
246+
FormattableString.Invariant($"Timeout after {timeout.TotalSeconds} s."), ex)
247+
{ RequestUrl = currentUrl.AbsoluteUri };
248+
}
249+
catch (HttpRequestException ex)
250+
{
251+
throw new RDAPException(RDAPErrorKind.Network, ex.Message, ex) { RequestUrl = currentUrl.AbsoluteUri };
247252
}
248253

249254
using (response)

‎Source/NETworkManager.Models/RDAP/RDAPException.cs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,14 @@ public enum RDAPErrorKind
6868
InvalidResponse,
6969

7070
/// <summary>
71-
/// DNS, connection, TLS or timeout error for all known servers.
71+
/// DNS, connection or TLS error for all known servers.
7272
/// </summary>
73-
Network
73+
Network,
74+
75+
/// <summary>
76+
/// The server did not respond within the timeout.
77+
/// </summary>
78+
Timeout
7479
}
7580

7681
/// <summary>

‎Source/NETworkManager/ViewModels/RDAPViewModel.cs‎

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Collections.Generic;
1616
using System.ComponentModel;
1717
using System.Linq;
18+
using System.Threading;
1819
using System.Threading.Tasks;
1920
using System.Windows;
2021
using System.Windows.Data;
@@ -30,6 +31,7 @@ public class RDAPViewModel : ViewModelBase
3031

3132
private readonly Guid _tabId;
3233
private readonly bool _isLoading;
34+
private CancellationTokenSource _cancellationTokenSource;
3335
private bool _firstLoad = true;
3436
private bool _closed;
3537

@@ -82,6 +84,19 @@ public bool IsRunning
8284
}
8385
}
8486

87+
public bool IsCanceling
88+
{
89+
get;
90+
set
91+
{
92+
if (value == field)
93+
return;
94+
95+
field = value;
96+
OnPropertyChanged();
97+
}
98+
}
99+
85100
public bool IsResultVisible
86101
{
87102
get;
@@ -238,7 +253,10 @@ private bool Query_CanExecute(object parameter)
238253

239254
private void QueryAction()
240255
{
241-
_ = RunQuery();
256+
if (IsRunning)
257+
Stop();
258+
else
259+
_ = RunQuery();
242260
}
243261

244262
public ICommand OpenInWhoisCommand => new RelayCommand(_ => OpenInWhoisAction());
@@ -293,11 +311,14 @@ private async Task RunQuery()
293311
return;
294312
}
295313

314+
_cancellationTokenSource?.Dispose();
315+
_cancellationTokenSource = new CancellationTokenSource();
316+
296317
try
297318
{
298319
_result = await RDAPClient.GetInstance().QueryAsync(query, GlobalStaticConfiguration.RDAP_CachePath,
299320
TimeSpan.FromMilliseconds(SettingsManager.Current.RDAP_Timeout),
300-
SettingsManager.Current.RDAP_FollowReferral);
321+
SettingsManager.Current.RDAP_FollowReferral, _cancellationTokenSource.Token);
301322

302323
List<RDAPObjectViewModel> results =
303324
[
@@ -319,6 +340,10 @@ private async Task RunQuery()
319340

320341
AddQueryToHistory(Query);
321342
}
343+
catch (OperationCanceledException)
344+
{
345+
ShowStatusMessage(Strings.CanceledByUserMessage);
346+
}
322347
catch (RDAPException ex)
323348
{
324349
ShowStatusMessage(GetErrorMessage(ex, query));
@@ -334,8 +359,17 @@ private async Task RunQuery()
334359
Log.Error("Error while querying RDAP.", ex);
335360
ShowStatusMessage(ex.Message);
336361
}
362+
finally
363+
{
364+
IsRunning = false;
365+
IsCanceling = false;
366+
}
367+
}
337368

338-
IsRunning = false;
369+
private void Stop()
370+
{
371+
IsCanceling = true;
372+
_cancellationTokenSource?.Cancel();
339373
}
340374

341375
private void ShowStatusMessage(string message)
@@ -379,6 +413,9 @@ private static string GetErrorMessage(RDAPException ex, RDAPQuery query)
379413
RDAPErrorKind.TooManyRedirects => Strings.RDAPTooManyRedirects,
380414
RDAPErrorKind.InvalidResponse => string.Format(Strings.RDAPInvalidResponseX, ex.Message),
381415
RDAPErrorKind.Network => string.Format(Strings.RDAPNetworkErrorX, ex.Message),
416+
// The timeout of the query (from the settings) is used for each request.
417+
RDAPErrorKind.Timeout => string.Format(Strings.RDAPTimeoutAfterXSeconds,
418+
SettingsManager.Current.RDAP_Timeout / 1000.0),
382419
_ => string.Format(Strings.RDAPHttpErrorX, serverMessage)
383420
};
384421
}
@@ -391,6 +428,10 @@ public void OnClose()
391428

392429
_closed = true;
393430

431+
// Stop the query
432+
if (IsRunning)
433+
Stop();
434+
394435
ConfigurationManager.Current.RDAPTabCount--;
395436
}
396437

0 commit comments

Comments
 (0)