1- using System ;
1+ using DnsClient ;
2+ using Kerberos . NET . Dns ;
3+ using System ;
24using System . Collections . Generic ;
35using System . Linq ;
46using System . Threading . Tasks ;
5- using DnsClient ;
6- using Kerberos . NET . Dns ;
77
8- namespace Kerberos . NET . CommandLine . Dns
8+ namespace Kerberos . NET . PortableDns
99{
10- internal class PlatformIndependentDnsClient : IKerberosDnsQuery
10+ internal class PortableDnsImplementation : IKerberosDnsQuery
1111 {
12- private static readonly WindowsDnsQuery WindowsDns = new WindowsDnsQuery ( ) ;
13-
14- public async Task < IReadOnlyCollection < DnsRecord > > Query ( string query , DnsRecordType type )
12+ static PortableDnsImplementation ( )
1513 {
16- if ( WindowsDns . IsSupported )
17- {
18- return await WindowsDns . Query ( query , type ) ;
19- }
14+ DnsQuery . RegisterImplementation ( new PortableDnsImplementation ( ) ) ;
15+ }
2016
21- var client = new LookupClient ( ) ;
17+ public static LookupClientOptions Options { get ; set ; } = new LookupClientOptions ( ) ;
2218
23- var response = await client . QueryAsync ( query , ( QueryType ) type ) ;
19+ private static LookupClient Create ( )
20+ {
21+ return new LookupClient ( Options ) ;
22+ }
2423
24+ public async Task < IReadOnlyCollection < DnsRecord > > Query ( string query , DnsRecordType type )
25+ {
26+ var client = Create ( ) ;
27+ var response = await client . QueryAsync ( query , ( QueryType ) type ) ;
2528 var srvRecords = response . Answers . SrvRecords ( ) . Select ( a => new DnsRecord
2629 {
2730 Name = a . DomainName ,
@@ -38,9 +41,7 @@ public async Task<IReadOnlyCollection<DnsRecord>> Query(string query, DnsRecordT
3841 foreach ( var srv in srvRecords )
3942 {
4043 var c1 = merged . Where ( m => m . Key . Equals ( srv . Target , StringComparison . InvariantCultureIgnoreCase ) ) ;
41-
4244 var canon = c1 . SelectMany ( r => r ) ;
43-
4445 srv . Canonical = canon . ToList ( ) ;
4546 }
4647
0 commit comments