Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit 9214122

Browse files
committed
Minor code clean-up based on info messages in VS
1 parent 891e58f commit 9214122

10 files changed

Lines changed: 31 additions & 33 deletions

File tree

Directory.Build.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
<OutputPath>$(BaseOutputPath)$(Configuration)\</OutputPath>
1414
</PropertyGroup>
1515
<PropertyGroup>
16-
<LangVersion>9.0</LangVersion>
16+
<LangVersion>10.0</LangVersion>
17+
<StartDevelopmentStorage>False</StartDevelopmentStorage>
1718
</PropertyGroup>
1819
<PropertyGroup>
1920
<EnableNPE Condition="'$(EnableNPE)' == '' and $([MSBuild]::IsOSPlatform('Windows'))">true</EnableNPE>

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<PackageVersion Include="McMaster.Extensions.CommandLineUtils" Version="4.0.2" />
2020
<PackageVersion Include="MessagePack" Version="2.5.108" />
2121
<PackageVersion Include="MessagePackAnalyzer" Version="2.5.108" />
22-
<PackageVersion Include="Microsoft.ApplicationInsights" Version="2.21.0" />
2322
<PackageVersion Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
23+
<PackageVersion Include="Microsoft.ApplicationInsights" Version="2.21.0" />
2424
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.15" />
2525
<PackageVersion Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
2626
<PackageVersion Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />

NuGet.Insights.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2020
Directory.Build.props = Directory.Build.props
2121
Directory.Build.targets = Directory.Build.targets
2222
Directory.Packages.props = Directory.Packages.props
23+
global.json = global.json
2324
LICENSE = LICENSE
2425
NuGet.config = NuGet.config
2526
README.md = README.md

src/Forks/Forks.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<AssemblyName>NuGet.Insights.Forks</AssemblyName>
55
<RootNamespace>NuGet.Insights</RootNamespace>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7-
<LangVersion>10.0</LangVersion>
87
</PropertyGroup>
98
<ItemGroup>
109
<PackageReference Include="NuGet.Commands" />

src/Logic/Network/HttpSourceExtensions.cs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static class HttpSourceExtensions
2020
{
2121
private const int DefaultMaxTries = 3;
2222

23-
internal static readonly JsonSerializerOptions JsonSerializerOptions = new JsonSerializerOptions
23+
internal static readonly JsonSerializerOptions JsonSerializerOptions = new()
2424
{
2525
Converters =
2626
{
@@ -193,7 +193,7 @@ public static async Task<T> ProcessStreamWithRetryAsync<T>(
193193
nuGetLogger,
194194
token);
195195
}
196-
catch (Exception ex) when (ShouldRetryStreamException(attempt, fetchedHeaders, token, ex))
196+
catch (Exception ex) when (ShouldRetryStreamException(attempt, fetchedHeaders, ex, token))
197197
{
198198
logger.LogTransientWarning(ex, "On attempt {Attempt}, processing the stream response body failed. Trying again.", attempt);
199199
}
@@ -227,14 +227,14 @@ public static async Task<T> ProcessResponseWithRetryAsync<T>(
227227
nuGetLogger,
228228
token);
229229
}
230-
catch (Exception ex) when (ShouldRetryStreamException(attempt, fetchedHeaders, token, ex))
230+
catch (Exception ex) when (ShouldRetryStreamException(attempt, fetchedHeaders, ex, token))
231231
{
232232
logger.LogTransientWarning(ex, "On attempt {Attempt}, processing the response body for {Url} failed. Trying again.", attempt, url);
233233
}
234234
}
235235
}
236236

237-
private static bool ShouldRetryStreamException(int attempt, bool fetchedHeaders, CancellationToken token, Exception ex)
237+
private static bool ShouldRetryStreamException(int attempt, bool fetchedHeaders, Exception ex, CancellationToken token)
238238
{
239239
return attempt < 3
240240
&& fetchedHeaders
@@ -294,24 +294,22 @@ public static async Task<BlobMetadata> GetBlobMetadataAsync(
294294
async stream =>
295295
{
296296
var buffer = new byte[16 * 1024];
297-
using (var md5 = MD5.Create())
297+
using var md5 = MD5.Create();
298+
int read;
299+
do
298300
{
299-
int read;
300-
do
301-
{
302-
read = await stream.ReadAsync(buffer, 0, buffer.Length);
303-
md5.TransformBlock(buffer, 0, read, buffer, 0);
304-
}
305-
while (read > 0);
301+
read = await stream.ReadAsync(buffer);
302+
md5.TransformBlock(buffer, 0, read, buffer, 0);
303+
}
304+
while (read > 0);
306305

307-
md5.TransformFinalBlock(Array.Empty<byte>(), 0, 0);
308-
var contentMD5 = md5.Hash!.ToLowerHex();
306+
md5.TransformFinalBlock(Array.Empty<byte>(), 0, 0);
307+
var contentMD5 = md5.Hash!.ToLowerHex();
309308

310-
return new BlobMetadata(
311-
exists: true,
312-
hasContentMD5Header: false,
313-
contentMD5: contentMD5);
314-
}
309+
return new BlobMetadata(
310+
exists: true,
311+
hasContentMD5Header: false,
312+
contentMD5: contentMD5);
315313
},
316314
logger,
317315
token);

src/Logic/Support/ByteArrayExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public static class ByteArrayExtensions
1111
{
1212
public static string ToUpperHex(this byte[] bytes)
1313
{
14-
return BitConverter.ToString(bytes).Replace("-", string.Empty).ToUpperInvariant();
14+
return Convert.ToHexString(bytes);
1515
}
1616

1717
public static string ToLowerHex(this byte[] bytes)
1818
{
19-
return BitConverter.ToString(bytes).Replace("-", string.Empty).ToLowerInvariant();
19+
return Convert.ToHexString(bytes).ToLowerInvariant();
2020
}
2121

2222
public static string ToBase64(this byte[] bytes)

src/Worker.Logic/MessageProcessors/KustoIngestion/KustoDataValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private async Task<IReadOnlyList<Validation>> GetSetValidationsAsync(string colu
199199
return validations;
200200
}
201201

202-
private Validation GetLeftRightValidation(string leftTable, string rightTable, string column, string comparisonType, string joinQuery)
202+
private static Validation GetLeftRightValidation(string leftTable, string rightTable, string column, string comparisonType, string joinQuery)
203203
{
204204
var query = $@"{joinQuery} on {column}
205205
| where isempty({column}) or isempty({column}1)

test/Worker.Logic.Test/CatalogScan/Drivers/PackageCertificateToCsv/PackageCertificateToCsvDriverTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public async Task HandlesEVCodeSigning()
8989
var genericPolicies = JsonConvert.DeserializeObject<List<X509PolicyInfo>>(certificate.Policies);
9090
Assert.Equal(2, genericPolicies.Count);
9191
Assert.Equal("2.16.840.1.114412.3.2", genericPolicies[0].PolicyIdentifier);
92-
Assert.Equal(1, genericPolicies[0].PolicyQualifiers.Count);
92+
Assert.Single(genericPolicies[0].PolicyQualifiers);
9393
Assert.Equal(Oids.IdQtCps.Value, genericPolicies[0].PolicyQualifiers[0].PolicyQualifierId);
9494
Assert.Equal("2.23.140.1.3", genericPolicies[1].PolicyIdentifier);
9595
Assert.Empty(genericPolicies[1].PolicyQualifiers);

test/Worker.Logic.Test/CatalogScan/Drivers/PackageContentToCsv/PackageContentToCsvDriverTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ public async Task TreatsExtensionAsCaseInsensitive()
546546

547547
Assert.Equal(DriverResultType.Success, output.Type);
548548
var records = output.Value.Records;
549-
Assert.Equal(1, records.Count);
549+
Assert.Single(records);
550550
Assert.All(records, r => Assert.Equal(PackageContentResultType.AllLoaded, r.ResultType));
551551
Assert.All(records, r => Assert.Equal(".txt", r.FileExtension));
552552

@@ -578,7 +578,7 @@ public async Task HandlesSuffixWithoutDots()
578578

579579
Assert.Equal(DriverResultType.Success, output.Type);
580580
var records = output.Value.Records;
581-
Assert.Equal(1, records.Count);
581+
Assert.Single(records);
582582
Assert.All(records, r => Assert.Equal(PackageContentResultType.AllLoaded, r.ResultType));
583583
Assert.All(records, r => Assert.Equal("cense", r.FileExtension));
584584

@@ -608,7 +608,7 @@ public async Task HandlesHyphenInFrameworkProfile()
608608

609609
Assert.Equal(DriverResultType.Success, output.Type);
610610
var records = output.Value.Records;
611-
Assert.Equal(1, records.Count);
611+
Assert.Single(records);
612612
Assert.All(records, r => Assert.Equal(PackageContentResultType.AllLoaded, r.ResultType));
613613
Assert.All(records, r => Assert.Equal(".txt", r.FileExtension));
614614

test/Worker.Logic.Test/TestSupport/BaseWorkerLogicIntegrationTest.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,7 @@ await AssertWideEntityOutputAsync(
530530

531531
if (entity.V1.Available)
532532
{
533-
using var algorithm = SHA256.Create();
534-
mzipHash = algorithm.ComputeHash(entity.V1.MZipBytes.ToArray()).ToLowerHex();
533+
mzipHash = SHA256.HashData(entity.V1.MZipBytes.Span).ToLowerHex();
535534
httpHeaders = NormalizeHeaders(entity.V1.HttpHeaders, ignore: Enumerable.Empty<string>());
536535
}
537536

@@ -618,7 +617,7 @@ protected void MakeDeletedPackageAvailable(string id = "BehaviorSample", string
618617
}
619618
}
620619

621-
private void SetBlobResponseHeaders(HttpResponseMessage response, string sourcePath)
620+
private static void SetBlobResponseHeaders(HttpResponseMessage response, string sourcePath)
622621
{
623622
using (var fileStream = File.OpenRead(sourcePath))
624623
{
@@ -707,7 +706,7 @@ await AssertEntityOutputAsync<TableEntity>(
707706
fileName: fileName ?? "subject-to-owner.json");
708707
}
709708

710-
private ICslAdminProvider GetKustoAdminClient()
709+
private static ICslAdminProvider GetKustoAdminClient()
711710
{
712711
var connectionStringBuilder = ServiceCollectionExtensions.GetKustoConnectionStringBuilder(new NuGetInsightsWorkerSettings
713712
{

0 commit comments

Comments
 (0)