|
@@ -2,7 +2,7 @@
|
2
|
2
|
using System.Collections.Generic;
|
3
|
3
|
using System.Linq;
|
4
|
4
|
using System.Net;
|
5
|
|
-using System.Runtime.CompilerServices;
|
|
5
|
+using System.Threading;
|
6
|
6
|
using System.Threading.Tasks;
|
7
|
7
|
using ARSoft.Tools.Net.Dns;
|
8
|
8
|
using Microsoft.Extensions.Options;
|
|
@@ -27,6 +27,7 @@ namespace SiteStatus.Business
|
27
|
27
|
ServerStatus = new List<DnsZoneServerStatusDbo>()
|
28
|
28
|
};
|
29
|
29
|
|
|
30
|
+ var cancellationTokenSource = new CancellationTokenSource();
|
30
|
31
|
var list = new List<KeyValuePair<string, Task<List<SoaRecord>>>>();
|
31
|
32
|
var tasks = new List<Task<List<SoaRecord>>>();
|
32
|
33
|
foreach (var server in servers)
|
|
@@ -34,17 +35,29 @@ namespace SiteStatus.Business
|
34
|
35
|
try
|
35
|
36
|
{
|
36
|
37
|
var resolver = new DnsStubResolver(new []{IPAddress.Parse(server)});
|
37
|
|
- var recordsTask = resolver.ResolveAsync<SoaRecord>(zone, RecordType.Soa);
|
|
38
|
+ var recordsTask = resolver.ResolveAsync<SoaRecord>(zone, RecordType.Soa, RecordClass.INet, cancellationTokenSource.Token);
|
38
|
39
|
list.Add(new KeyValuePair<string, Task<List<SoaRecord>>>(server, recordsTask));
|
39
|
40
|
tasks.Add(recordsTask);
|
40
|
41
|
}
|
41
|
|
- catch (Exception e)
|
|
42
|
+ catch (Exception)
|
42
|
43
|
{
|
43
|
44
|
tasks.Add(Task.FromResult<List<SoaRecord>>(null));
|
44
|
45
|
}
|
45
|
46
|
}
|
46
|
47
|
|
47
|
|
- await Task.WhenAll(tasks.ToArray());
|
|
48
|
+ try
|
|
49
|
+ {
|
|
50
|
+ var allTasks = Task.WhenAll(tasks.ToArray());
|
|
51
|
+ if (await Task.WhenAny(allTasks, Task.Delay(Options.Dns.Resolve.Timeout)) == allTasks) {
|
|
52
|
+ await allTasks;
|
|
53
|
+ } else {
|
|
54
|
+ cancellationTokenSource.Cancel();
|
|
55
|
+ }
|
|
56
|
+ }
|
|
57
|
+ catch (Exception)
|
|
58
|
+ {
|
|
59
|
+ // Ignore, errors will be handled later
|
|
60
|
+ }
|
48
|
61
|
|
49
|
62
|
foreach (var recordResult in list)
|
50
|
63
|
{
|
|
@@ -57,7 +70,7 @@ namespace SiteStatus.Business
|
57
|
70
|
Soa = record?.ToString()
|
58
|
71
|
});
|
59
|
72
|
}
|
60
|
|
- catch (Exception e)
|
|
73
|
+ catch (Exception)
|
61
|
74
|
{
|
62
|
75
|
dnsStatus.ServerStatus.Add(new DnsZoneServerStatusDbo
|
63
|
76
|
{
|
|
@@ -72,20 +85,26 @@ namespace SiteStatus.Business
|
72
|
85
|
|
73
|
86
|
public DnsStatusDbo GetDnsStatus()
|
74
|
87
|
{
|
75
|
|
- var status = new DnsStatusDbo
|
|
88
|
+ var allTasks = new Dictionary<SettingsDnsViewDbo, IList<Task<DnsZoneStatusDbo>>>();
|
|
89
|
+ foreach (var view in Options.Dns.Views)
|
76
|
90
|
{
|
77
|
|
- Views = Options.Dns.Views.Select(view =>
|
78
|
|
- {
|
79
|
|
- var servers = view.Servers.Select(server => server.Ip).ToList();
|
80
|
|
- var tasks = view.Zones.Select(zone => GetZoneStatusAsync(zone.Name, servers)).ToArray();
|
|
91
|
+ var servers = view.Servers.Select(server => server.Ip).ToList();
|
|
92
|
+ var tasks = view.Zones.Select(zone => GetZoneStatusAsync(zone.Name, servers)).ToArray();
|
|
93
|
+
|
|
94
|
+ allTasks.Add(view, tasks);
|
|
95
|
+ }
|
81
|
96
|
|
82
|
|
- Task.WaitAll(tasks);
|
|
97
|
+ Task.WaitAll(allTasks.SelectMany(x => x.Value).ToArray());
|
83
|
98
|
|
84
|
|
- var results = tasks.Select(task => task.Result).ToList();
|
|
99
|
+ var status = new DnsStatusDbo
|
|
100
|
+ {
|
|
101
|
+ Views = allTasks.Select(pair =>
|
|
102
|
+ {
|
|
103
|
+ var results = pair.Value.Select(task => task.Result).ToList();
|
85
|
104
|
|
86
|
105
|
return new DnsStatusViewDbo
|
87
|
106
|
{
|
88
|
|
- Name = view.Name,
|
|
107
|
+ Name = pair.Key.Name,
|
89
|
108
|
Zones = results
|
90
|
109
|
};
|
91
|
110
|
}).ToList()
|