Skip to content

Commit

Permalink
NuGet updates and cleanup (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaCo authored Jul 1, 2024
1 parent 443d1bd commit f1e7ca3
Show file tree
Hide file tree
Showing 73 changed files with 555 additions and 343 deletions.
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ dotnet_diagnostic.CA1825.severity = silent
# CA1835: Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync' - (TODO: more improvements needed)
dotnet_diagnostic.CA1835.severity = silent

# CA1819: Do not return arrays.
dotnet_diagnostic.CA1819.severity = suggestion

# All the style rules we want to enforce during build...
dotnet_diagnostic.CA2211.severity = warning
dotnet_diagnostic.CA2007.severity = warning
Expand Down Expand Up @@ -209,6 +212,26 @@ dotnet_diagnostic.IDE0305.severity = none
# use primary ctor
dotnet_diagnostic.IDE0290.severity = none

dotnet_diagnostic.CA1303.severity = silent

# don't use short for enum
dotnet_diagnostic.CA1028.severity = silent

# Friendly overload for + operator
dotnet_diagnostic.CA2225.severity = silent

# interop
dotnet_diagnostic.CA5392.severity = silent

# Enum value Reserved
dotnet_diagnostic.CA1700.severity = silent
dotnet_diagnostic.CA1720.severity = silent

## Features not avail in all framework targets
dotnet_diagnostic.CA1510.severity = silent
dotnet_diagnostic.CA1512.severity = silent
dotnet_diagnostic.CA1513.severity = silent

# Xml project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}]
indent_size = 2
Expand Down
14 changes: 14 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project>
<PropertyGroup>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<AnalysisMode>all</AnalysisMode>
<AnalysisLevel>8.0</AnalysisLevel>
</PropertyGroup>

<PropertyGroup>
<LangVersion>12.0</LangVersion>
</PropertyGroup>
</Project>
12 changes: 3 additions & 9 deletions DnsClientDotNet.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29806.167
# Visual Studio Version 17
VisualStudioVersion = 17.10.35013.160
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3D3BE1AD-F551-420A-A81D-4CB88286C8CD}"
EndProject
Expand All @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitignore = .gitignore
.runsettings = .runsettings
azure-pipelines-ci.yml = azure-pipelines-ci.yml
directory.build.props = directory.build.props
LICENSE = LICENSE
README.md = README.md
EndProjectSection
Expand All @@ -23,8 +24,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniDig", "samples\MiniDig\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DnsClient.Tests", "test\DnsClient.Tests\DnsClient.Tests.csproj", "{01902674-53A3-4E81-B08F-CFAA7CA62F56}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiDesign", "test-other\ApiDesign\ApiDesign.csproj", "{2F789CAA-31E5-4394-96B9-1B06A1AA5EA0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DnsClient", "src\DnsClient\DnsClient.csproj", "{493E6161-7F71-4A59-AB28-B4A5E45A5E27}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "test-other\Benchmarks\Benchmarks.csproj", "{7461E2C7-008E-4E61-ABC3-AF85DE37084B}"
Expand Down Expand Up @@ -62,10 +61,6 @@ Global
{01902674-53A3-4E81-B08F-CFAA7CA62F56}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01902674-53A3-4E81-B08F-CFAA7CA62F56}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01902674-53A3-4E81-B08F-CFAA7CA62F56}.Release|Any CPU.Build.0 = Release|Any CPU
{2F789CAA-31E5-4394-96B9-1B06A1AA5EA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F789CAA-31E5-4394-96B9-1B06A1AA5EA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F789CAA-31E5-4394-96B9-1B06A1AA5EA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F789CAA-31E5-4394-96B9-1B06A1AA5EA0}.Release|Any CPU.Build.0 = Release|Any CPU
{493E6161-7F71-4A59-AB28-B4A5E45A5E27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{493E6161-7F71-4A59-AB28-B4A5E45A5E27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{493E6161-7F71-4A59-AB28-B4A5E45A5E27}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -97,7 +92,6 @@ Global
GlobalSection(NestedProjects) = preSolution
{CEC9D7AD-8000-4FC6-8EB3-AC1417B9808A} = {A1BE93CF-0106-495B-9720-008046657391}
{01902674-53A3-4E81-B08F-CFAA7CA62F56} = {34E43CED-3DF4-49CE-8556-69225ABD84E6}
{2F789CAA-31E5-4394-96B9-1B06A1AA5EA0} = {28CFF2BF-88D0-481F-829E-43B51DE7FB1F}
{493E6161-7F71-4A59-AB28-B4A5E45A5E27} = {3D3BE1AD-F551-420A-A81D-4CB88286C8CD}
{7461E2C7-008E-4E61-ABC3-AF85DE37084B} = {28CFF2BF-88D0-481F-829E-43B51DE7FB1F}
{8422A76D-CC40-4B4B-AA03-C17C3D86A073} = {28CFF2BF-88D0-481F-829E-43B51DE7FB1F}
Expand Down
8 changes: 3 additions & 5 deletions azure-pipelines-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ jobs:
inputs:
command: 'build'
projects: |
src/**/*.csproj
test/**/*.csproj
DnsClientDotNet.sln
arguments: '-c Release'
name: 'Build'
displayName: 'dotnet build'
Expand All @@ -42,7 +41,7 @@ jobs:
command: 'test'
projects: 'test/**/*.csproj'
publishTestResults: true
arguments: '-c Release --no-build --no-restore -f net6.0'
arguments: '-c Release --no-build --no-restore -f net8.0'

- job: Windows
displayName: 'Build & Test on Windows'
Expand All @@ -55,8 +54,7 @@ jobs:
inputs:
command: 'build'
projects: |
src/**/*.csproj
test/**/*.csproj
DnsClientDotNet.sln
arguments: '-c Release'
name: 'Build'
- task: DotNetCoreCLI@2
Expand Down
2 changes: 1 addition & 1 deletion samples/MiniDig/DigCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected override async Task<int> Execute()
Console.WriteLine($"; Servers: {string.Join(", ", lookup.NameServers)}");

var parsedDnsString = DnsString.Parse(useDomain);
if (parsedDnsString.NumberOfLabels == 1 && !parsedDnsString.Original.EndsWith("."))
if (parsedDnsString.NumberOfLabels == 1 && !parsedDnsString.Original.EndsWith(".", StringComparison.Ordinal))
{
foreach (var server in lookup.NameServers)
{
Expand Down
15 changes: 8 additions & 7 deletions samples/MiniDig/DnsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
Expand Down Expand Up @@ -41,7 +42,7 @@ public abstract class DnsCommand

public CommandOption NoTcpArg { get; set; }

public DnsCommand(CommandLineApplication app, string[] originalArgs)
protected DnsCommand(CommandLineApplication app, string[] originalArgs)
{
App = app ?? throw new ArgumentNullException(nameof(app));
OriginalArgs = originalArgs;
Expand All @@ -64,7 +65,7 @@ public NameServer[] GetEndpointsValue()
foreach (var serverPair in values)
{
var server = serverPair[0];
var port = serverPair.Length > 1 ? int.Parse(serverPair[1]) : 53;
var port = serverPair.Length > 1 ? int.Parse(serverPair[1], CultureInfo.InvariantCulture) : 53;

if (!IPAddress.TryParse(server, out IPAddress ip))
{
Expand Down Expand Up @@ -110,7 +111,7 @@ public LookupClientOptions GetLookupSettings()
{
if (MinimumTTLArg.HasValue())
{
return TimeSpan.FromMilliseconds(int.Parse(MinimumTTLArg.Value()));
return TimeSpan.FromMilliseconds(int.Parse(MinimumTTLArg.Value(), CultureInfo.InvariantCulture));
}

return null;
Expand All @@ -120,20 +121,20 @@ public LookupClientOptions GetLookupSettings()
{
if (MaximumTTLArg.HasValue())
{
return TimeSpan.FromMilliseconds(int.Parse(MaximumTTLArg.Value()));
return TimeSpan.FromMilliseconds(int.Parse(MaximumTTLArg.Value(), CultureInfo.InvariantCulture));
}

return null;
}

public int GetMaximumBufferSize()
=> MaximumBufferSizeArg.HasValue() ? int.Parse(MaximumBufferSizeArg.Value()) : DnsQueryOptions.MaximumBufferSize;
=> MaximumBufferSizeArg.HasValue() ? int.Parse(MaximumBufferSizeArg.Value(), CultureInfo.InvariantCulture) : DnsQueryOptions.MaximumBufferSize;

public bool GetRequestDnsSec() => RequestDnsSecRecordsArg.HasValue();

public int GetTimeoutValue() => ConnectTimeoutArg.HasValue() ? int.Parse(ConnectTimeoutArg.Value()) : 1000;
public int GetTimeoutValue() => ConnectTimeoutArg.HasValue() ? int.Parse(ConnectTimeoutArg.Value(), CultureInfo.InvariantCulture) : 1000;

public int GetTriesValue() => TriesArg.HasValue() ? int.Parse(TriesArg.Value()) : 5;
public int GetTriesValue() => TriesArg.HasValue() ? int.Parse(TriesArg.Value(), CultureInfo.InvariantCulture) : 5;

public bool GetUseCache()
{
Expand Down
11 changes: 4 additions & 7 deletions samples/MiniDig/MiniDig.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
<AssemblyName>MiniDig</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>MiniDig</PackageId>
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);CA2214;CA2008;CA5394;CA1865;CA1849;CA1307;</NoWarn>
</PropertyGroup>
<PropertyGroup>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>

<ItemGroup>
<None Update="names.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand All @@ -24,6 +21,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.1.0" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.1.1" />
</ItemGroup>
</Project>
20 changes: 14 additions & 6 deletions samples/MiniDig/PerfCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -19,8 +20,8 @@ public class PerfCommand : DnsCommand
private int _tasks;
private string _query;
private int _runtime;
private long _reportExcecutions = 0;
private long _allExcecutions = 0;
private long _reportExcecutions;
private long _allExcecutions;
private bool _running;
private LookupClientOptions _settings;
private int _errors;
Expand Down Expand Up @@ -54,19 +55,23 @@ protected override void Configure()

protected override async Task<int> Execute()
{
_clients = ClientsArg.HasValue() ? int.Parse(ClientsArg.Value()) : 10;
_clients = ClientsArg.HasValue() ? int.Parse(ClientsArg.Value(), CultureInfo.InvariantCulture) : 10;
if (_clients <= 0)
{
throw new ArgumentOutOfRangeException(nameof(ClientsArg));
}

_tasks = TasksArg.HasValue() ? int.Parse(TasksArg.Value()) : 8;
_tasks = TasksArg.HasValue() ? int.Parse(TasksArg.Value(), CultureInfo.InvariantCulture) : 8;
if (_clients <= 0)
{
throw new ArgumentOutOfRangeException(nameof(TasksArg));
}

_runtime = RuntimeArg.HasValue() ? int.Parse(RuntimeArg.Value()) <= 1 ? 5 : int.Parse(RuntimeArg.Value()) : 5;
_runtime = RuntimeArg.HasValue()
? int.Parse(RuntimeArg.Value(), CultureInfo.InvariantCulture) <= 1
? 5 : int.Parse(RuntimeArg.Value(), CultureInfo.InvariantCulture)
: 5;

_query = string.IsNullOrWhiteSpace(QueryArg.Value) ? string.Empty : QueryArg.Value;
_runSync = SyncArg.HasValue();

Expand All @@ -75,7 +80,10 @@ protected override async Task<int> Execute()
_running = true;

Console.WriteLine($"; <<>> Starting perf run with {_clients} (x{_tasks}) clients running for {_runtime} seconds <<>>");
Console.WriteLine($"; ({_settings.NameServers.Count} Servers, caching:{_settings.UseCache}, minttl:{_settings.MinimumCacheTimeout?.TotalMilliseconds}, maxttl:{_settings.MaximumCacheTimeout?.TotalMilliseconds})");
Console.WriteLine($"; ({_settings.NameServers.Count} Servers, caching:{_settings.UseCache}, " +
$"minttl:{_settings.MinimumCacheTimeout?.TotalMilliseconds}, " +
$"maxttl:{_settings.MaximumCacheTimeout?.TotalMilliseconds})");

_spinner = new Spiner();
_spinner.Start();

Expand Down
4 changes: 2 additions & 2 deletions samples/MiniDig/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

namespace DigApp
{
public class Program
public static class Program
{
public static async Task<int> Main(string[] args)
{
DnsClient.Tracing.Source.Switch.Level = SourceLevels.Warning;
DnsClient.Tracing.Source.Listeners.Add(new ConsoleTraceListener());

var app = new CommandLineApplication();
using var app = new CommandLineApplication();
app.UnrecognizedArgumentHandling = UnrecognizedArgumentHandling.Throw;

try
Expand Down
34 changes: 20 additions & 14 deletions samples/MiniDig/RandomCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
Expand All @@ -26,8 +27,8 @@ public class RandomCommand : DnsCommand
private ConcurrentQueue<string> _domainNames;
private int _clients;
private int _runtime;
private long _reportExcecutions = 0;
private long _allExcecutions = 0;
private long _reportExcecutions;
private long _allExcecutions;
private bool _running;
private LookupClientOptions _settings;
private int _errors;
Expand Down Expand Up @@ -71,8 +72,12 @@ protected override async Task<int> Execute()
var lines = File.ReadAllLines("names.txt");
_domainNames = new ConcurrentQueue<string>(lines.Select(p => p.Substring(p.IndexOf(';') + 1)).OrderBy(x => s_randmom.Next(0, lines.Length * 2)));

_clients = ClientsArg.HasValue() ? int.Parse(ClientsArg.Value()) : 10;
_runtime = RuntimeArg.HasValue() ? int.Parse(RuntimeArg.Value()) <= 1 ? 5 : int.Parse(RuntimeArg.Value()) : 5;
_clients = ClientsArg.HasValue() ? int.Parse(ClientsArg.Value(), CultureInfo.InvariantCulture) : 10;
_runtime = RuntimeArg.HasValue()
? int.Parse(RuntimeArg.Value(), CultureInfo.InvariantCulture) <= 1
? 5 : int.Parse(RuntimeArg.Value(), CultureInfo.InvariantCulture)
: 5;

_runSync = SyncArg.HasValue();

_settings = GetLookupSettings();
Expand Down Expand Up @@ -145,15 +150,16 @@ private async Task CollectPrint()
waitCount++;
await Task.Delay(1000).ConfigureAwait(false);

var serverUpdate = from good in _successByServer
join fail in _failByServer on good.Key equals fail.Key into all
from row in all.DefaultIfEmpty()
select new
{
good.Key,
Fails = row.Value,
Success = good.Value
};
var serverUpdate =
from good in _successByServer
join fail in _failByServer on good.Key equals fail.Key into all
from row in all.DefaultIfEmpty()
select new
{
good.Key,
Fails = row.Value,
Success = good.Value
};

var updateString = string.Join(" | ", serverUpdate.Select((p, i) => $"Server{i}: +{p.Success} -{p.Fails}"));

Expand All @@ -163,7 +169,7 @@ from row in all.DefaultIfEmpty()
_running = false;
}

private int _runNumber = 0;
private int _runNumber;

private async Task ExcecuteRun()
{
Expand Down
Loading

0 comments on commit f1e7ca3

Please sign in to comment.