Skip to content

Commit

Permalink
Enable analyzers and delete dead code.
Browse files Browse the repository at this point in the history
  • Loading branch information
peters committed Jan 27, 2024
1 parent dd12609 commit c4bf4a8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 45 deletions.
23 changes: 10 additions & 13 deletions Digipost.Api.Client.ConcurrencyTest/DigipostAsync.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
using System.Net;
using System.Threading.Tasks;
using Digipost.Api.Client.Common;
using Digipost.Api.Client.ConcurrencyTest.Enums;

namespace Digipost.Api.Client.ConcurrencyTest
{
internal class DigipostAsync : DigipostRunner
internal class DigipostAsync(
int numberOfRequests,
int defaultConnectionLimit,
ClientConfig clientconfig,
string thumbprint)
: DigipostRunner(clientconfig, thumbprint, numberOfRequests)
{
private readonly int _defaultConnectionLimit;

public DigipostAsync(int numberOfRequests, int defaultConnectionLimit, ClientConfig clientconfig,
string thumbprint)
: base(clientconfig, thumbprint, numberOfRequests)
{
_defaultConnectionLimit = defaultConnectionLimit;
}

public override void Run(RequestType requestType)
public override async Task RunAsync(RequestType requestType)
{
Stopwatch.Start();
ServicePointManager.DefaultConnectionLimit = _defaultConnectionLimit;
ServicePointManager.DefaultConnectionLimit = defaultConnectionLimit;

while (RunsLeft() > 0)
{
Send(Client, requestType);
await SendAsync(Client, requestType);
}

Stopwatch.Stop();
Expand Down
31 changes: 15 additions & 16 deletions Digipost.Api.Client.ConcurrencyTest/DigipostParalell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,31 @@

namespace Digipost.Api.Client.ConcurrencyTest
{
internal class DigipostParalell : DigipostRunner
internal class DigipostParalell(
int numberOfRequests,
int defaultConnectionLimit,
int degreeOfParallelism,
ClientConfig clientConfig,
string thumbprint)
: DigipostRunner(clientConfig, thumbprint, numberOfRequests)
{
private readonly int _defaultConnectionLimit;
private readonly int _degreeOfParallelism;

public DigipostParalell(int numberOfRequests, int defaultConnectionLimit, int degreeOfParallelism,
ClientConfig clientConfig, string thumbprint)
: base(clientConfig, thumbprint, numberOfRequests)
{
_defaultConnectionLimit = defaultConnectionLimit;
_degreeOfParallelism = degreeOfParallelism;
}

public override void Run(RequestType requestType)
public override async Task RunAsync(RequestType requestType)
{
Stopwatch.Start();
ServicePointManager.DefaultConnectionLimit = _defaultConnectionLimit;
ServicePointManager.DefaultConnectionLimit = defaultConnectionLimit;

var messages = new List<IMessage>();
while (RunsLeft() > 0)
{
messages.Add(GetMessage());
}

var options = new ParallelOptions {MaxDegreeOfParallelism = _degreeOfParallelism};
Parallel.ForEach(messages, options, message => Send(Client, requestType));
var options = new ParallelOptions {MaxDegreeOfParallelism = degreeOfParallelism};

await Parallel.ForEachAsync(messages, options, async (_, _) =>
{
await SendAsync(Client, requestType);
});

Stopwatch.Stop();
DisplayTestResults();
Expand Down
4 changes: 2 additions & 2 deletions Digipost.Api.Client.ConcurrencyTest/DigipostRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public int RunsLeft()
return Interlocked.Decrement(ref _itemsLeft);
}

public abstract void Run(RequestType requestType);
public abstract Task RunAsync(RequestType requestType);

public IMessage GetMessage()
{
Expand Down Expand Up @@ -71,7 +71,7 @@ private byte[] GetDocumentBytes()
return _documentBytes ?? (_documentBytes = ContentResource.Hoveddokument.PlainText());
}

public async Task Send(DigipostClient digipostClient, RequestType requestType)
public async Task SendAsync(DigipostClient digipostClient, RequestType requestType)
{
try
{
Expand Down
11 changes: 6 additions & 5 deletions Digipost.Api.Client.ConcurrencyTest/Initializer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using Digipost.Api.Client.Common;
using Digipost.Api.Client.ConcurrencyTest.Enums;
using Environment = Digipost.Api.Client.Common.Environment;
Expand All @@ -18,10 +19,10 @@ public class Initializer
public static void Run()
{
Console.WriteLine("Starting program ...");
Digipost(NumberOfRequests, ThreadsActive, ProcessingType);
await Digipost(NumberOfRequests, ThreadsActive, ProcessingType);
}

private static void Digipost(int numberOfRequests, int connectionLimit, ProcessingType processingType)
private static async Task Digipost(int numberOfRequests, int connectionLimit, ProcessingType processingType)
{
Console.WriteLine("Starting to send digipost: {0}, with requests: {1}, poolcount: {2}", processingType,
numberOfRequests, connectionLimit);
Expand All @@ -31,11 +32,11 @@ private static void Digipost(int numberOfRequests, int connectionLimit, Processi
switch (processingType)
{
case ProcessingType.Parallel:
new DigipostParalell(numberOfRequests, connectionLimit, DegreeOfParallelism, clientConfig,
Thumbprint).Run(RequestType);
await new DigipostParalell(numberOfRequests, connectionLimit, DegreeOfParallelism, clientConfig,
Thumbprint).RunAsync(RequestType);
break;
case ProcessingType.Async:
new DigipostAsync(numberOfRequests, connectionLimit, clientConfig, Thumbprint).Run(RequestType);
await new DigipostAsync(numberOfRequests, connectionLimit, clientConfig, Thumbprint).RunAsync(RequestType);
break;
}
}
Expand Down
7 changes: 4 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<Project>
<PropertyGroup>

<LangVersion>12.0</LangVersion>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
</PropertyGroup>

<PropertyGroup>
<Authors>Digipost AS</Authors>
<Company>Posten Norge AS</Company>
<Copyright>Copyright © 2022 Posten Norge AS</Copyright>
Expand All @@ -13,8 +16,6 @@
<Description>Klientbibliotek for integrasjon mot Digipost REST-API.</Description>

<PackageOutputPath Condition="$(PackageOutputPath) == ''">$(MSBuildThisFileDirectory)\nupkgs</PackageOutputPath>

<UserSecretsId>enterprise-certificate</UserSecretsId>
</PropertyGroup>

</Project>
6 changes: 0 additions & 6 deletions digipost-api-client.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Digipost.Api.Client.Common"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Digipost.Api.Client.Common.Tests", "Digipost.Api.Client.Common.Tests\Digipost.Api.Client.Common.Tests.csproj", "{BC85F48B-9584-41F7-BBE8-EBBEC1EEC7E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Digipost.Api.Client.ConcurrencyTest", "Digipost.Api.Client.ConcurrencyTest\Digipost.Api.Client.ConcurrencyTest.csproj", "{7B5E5062-98E5-4312-9A82-28DF530BF5FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Digipost.Api.Client.Docs", "Digipost.Api.Client.Docs\Digipost.Api.Client.Docs.csproj", "{1B5DB6E1-7363-4B6D-8565-CBF7E5C958DE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Digipost.Api.Client.Archive", "Digipost.Api.Client.Archive\Digipost.Api.Client.Archive.csproj", "{1BEC9279-D6C5-4C26-B926-13081F1C3DBC}"
Expand Down Expand Up @@ -46,10 +44,6 @@ Global
{BC85F48B-9584-41F7-BBE8-EBBEC1EEC7E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC85F48B-9584-41F7-BBE8-EBBEC1EEC7E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC85F48B-9584-41F7-BBE8-EBBEC1EEC7E8}.Release|Any CPU.Build.0 = Release|Any CPU
{7B5E5062-98E5-4312-9A82-28DF530BF5FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B5E5062-98E5-4312-9A82-28DF530BF5FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B5E5062-98E5-4312-9A82-28DF530BF5FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B5E5062-98E5-4312-9A82-28DF530BF5FB}.Release|Any CPU.Build.0 = Release|Any CPU
{1B5DB6E1-7363-4B6D-8565-CBF7E5C958DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1B5DB6E1-7363-4B6D-8565-CBF7E5C958DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B5DB6E1-7363-4B6D-8565-CBF7E5C958DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down

0 comments on commit c4bf4a8

Please sign in to comment.