Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit dee5626

Browse files
author
Christy Henriksson
authored
Latest fxcop fixes (#578)
1 parent dfdf05f commit dee5626

10 files changed

Lines changed: 53 additions & 50 deletions

File tree

build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ param (
99
[string]$SemanticVersion = '1.0.0-zlocal',
1010
[string]$Branch = 'zlocal',
1111
[string]$CommitSHA,
12-
[string]$BuildBranch = 'c35bbc228717720bdbc610f3285259391635e90e'
12+
[string]$BuildBranch = '28bbd8623e116d388cd6ece107b913296b6c1b20'
1313
)
1414

1515
$msBuildVersion = 15;

src/Gallery.Maintenance/DeleteExpiredVerificationKeysTask.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,21 @@ public override async Task RunAsync(Job job)
6161
if (expectedRowCount > 0)
6262
{
6363
using (var connection = await job.OpenSqlConnectionAsync<GalleryDbConfiguration>())
64+
using (var transaction = connection.BeginTransaction())
65+
using (var command = connection.CreateCommand())
6466
{
65-
using (var transaction = connection.BeginTransaction())
66-
{
67-
var numKeys = 0;
68-
var parameters = credentialKeys.Select(c => new SqlParameter("@Key" + numKeys++, SqlDbType.Int) { Value = c }).ToArray();
69-
70-
rowCount = await connection.ExecuteAsync(
71-
string.Format(DeleteQuery, string.Join(",", parameters.Select(p => p.ParameterName))),
72-
parameters,
73-
transaction, _commandTimeout);
74-
75-
transaction.Commit();
76-
}
67+
var numKeys = 0;
68+
var parameters = credentialKeys.Select(c => new SqlParameter("@Key" + numKeys++, SqlDbType.Int) { Value = c }).ToArray();
69+
command.Parameters.AddRange(parameters);
70+
71+
command.CommandText = string.Format(DeleteQuery, string.Join(",", parameters.Select(p => p.ParameterName)));
72+
command.CommandType = CommandType.Text;
73+
command.CommandTimeout = (int)_commandTimeout.TotalSeconds;
74+
command.Transaction = transaction;
75+
76+
rowCount = await command.ExecuteNonQueryAsync();
77+
78+
transaction.Commit();
7779
}
7880
}
7981

src/NuGet.Jobs.Common/Extensions/DapperExtensions.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,6 @@ namespace System.Data.SqlClient
1010
{
1111
public static class DapperExtensions
1212
{
13-
public static Task<int> ExecuteAsync(this SqlConnection connection, string sql, SqlParameter[] parameters = null, SqlTransaction transaction = null, TimeSpan? commandTimeout = null)
14-
{
15-
SqlCommand cmd = connection.CreateCommand();
16-
cmd.CommandText = sql;
17-
cmd.CommandType = CommandType.Text;
18-
19-
if (parameters != null)
20-
{
21-
cmd.Parameters.AddRange(parameters);
22-
}
23-
24-
if (commandTimeout.HasValue)
25-
{
26-
cmd.CommandTimeout = (int)commandTimeout.Value.TotalSeconds;
27-
}
28-
29-
if (transaction != null)
30-
{
31-
cmd.Transaction = transaction;
32-
}
33-
34-
return cmd.ExecuteNonQueryAsync();
35-
}
36-
3713
public static async Task<IEnumerable<T>> QueryWithRetryAsync<T>(
3814
this SqlConnection connection,
3915
string sql,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
6+
[module: SuppressMessage("Microsoft.Security.Web.Configuration", "CA3103:EnableFormsRequireSSL", Justification = "Forms authentication is not used, and this project is obsolete (Engineering#1737).")]

src/NuGetCDNRedirect/NuGetCDNRedirect.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
<Compile Include="Global.asax.cs">
184184
<DependentUpon>Global.asax</DependentUpon>
185185
</Compile>
186+
<Compile Include="GlobalSuppressions.cs" />
186187
<Compile Include="Properties\AssemblyInfo.cs" />
187188
<Compile Include="Properties\AssemblyInfo.*.cs" />
188189
</ItemGroup>

src/Search.GenerateAuxiliaryData/NestedJArrayExporter.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Data;
76
using System.Data.SqlClient;
87
using System.Linq;
98
using System.Threading.Tasks;
@@ -34,8 +33,7 @@ public NestedJArrayExporter(
3433

3534
protected override JContainer GetResultOfQuery(SqlConnection connection)
3635
{
37-
var command = new SqlCommand(GetEmbeddedSqlScript(SqlScript), connection);
38-
command.CommandType = CommandType.Text;
36+
var command = GetEmbeddedSqlCommand(connection, SqlScript);
3937

4038
return SqlDataReaderToNestedJArrays(command.ExecuteReader(), Col0, Col1);
4139
}

src/Search.GenerateAuxiliaryData/RankingsExporter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public RankingsExporter(
3232

3333
protected override JContainer GetResultOfQuery(SqlConnection connection)
3434
{
35-
var rankingsTotalCommand = new SqlCommand(GetEmbeddedSqlScript(_rankingsTotalScript), connection);
36-
rankingsTotalCommand.CommandType = CommandType.Text;
35+
var rankingsTotalCommand = GetEmbeddedSqlCommand(connection, _rankingsTotalScript);
3736
rankingsTotalCommand.Parameters.AddWithValue(_rankingCountParameterName, _rankingCount);
3837
rankingsTotalCommand.CommandTimeout = 60;
3938

src/Search.GenerateAuxiliaryData/SqlExporter.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Data;
77
using System.Data.SqlClient;
8+
using System.Diagnostics.CodeAnalysis;
89
using System.IO;
910
using System.Reflection;
1011
using System.Threading.Tasks;
@@ -34,10 +35,18 @@ public SqlExporter(
3435
OpenSqlConnectionAsync = openSqlConnectionAsync;
3536
}
3637

37-
protected static string GetEmbeddedSqlScript(string resourceName)
38+
[SuppressMessage("Microsoft.Security", "CA2100", Justification = "Query string comes from embedded resource, not user input.")]
39+
protected static SqlCommand GetEmbeddedSqlCommand(SqlConnection connection, string resourceName)
3840
{
39-
var stream = _executingAssembly.GetManifestResourceStream(_assemblyName + "." + resourceName);
40-
return new StreamReader(stream).ReadToEnd();
41+
using (var reader = new StreamReader(_executingAssembly.GetManifestResourceStream(_assemblyName + "." + resourceName)))
42+
{
43+
var commandText = reader.ReadToEnd();
44+
45+
return new SqlCommand(commandText, connection)
46+
{
47+
CommandType = CommandType.Text
48+
};
49+
}
4150
}
4251

4352
public override async Task ExportAsync()

src/Search.GenerateAuxiliaryData/VerifiedPackagesExporter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public VerifiedPackagesExporter(
2929

3030
protected override JContainer GetResultOfQuery(SqlConnection connection)
3131
{
32-
var verifiedPackagesCommand = new SqlCommand(GetEmbeddedSqlScript(_verifiedPackagesScript), connection);
33-
verifiedPackagesCommand.CommandType = CommandType.Text;
32+
var verifiedPackagesCommand = GetEmbeddedSqlCommand(connection, _verifiedPackagesScript);
3433
verifiedPackagesCommand.CommandTimeout = 60;
3534

3635
SqlDataReader reader = null;

src/Stats.AggregateCdnDownloadsInGallery/AggregateCdnDownloadsJob.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,14 @@ private async Task ProcessBatch(List<IPackageIdGroup> batch, SqlConnection desti
148148
{
149149
// Create a temporary table
150150
Logger.LogDebug("Creating temporary table...");
151-
await destinationDatabase.ExecuteAsync(_createTempTable);
151+
152+
using (var cmd = destinationDatabase.CreateCommand())
153+
{
154+
cmd.CommandText = _createTempTable;
155+
cmd.CommandType = CommandType.Text;
156+
157+
await cmd.ExecuteNonQueryAsync();
158+
}
152159

153160
// Load temporary table
154161
var aggregateCdnDownloadsInGalleryTable = new DataTable();
@@ -206,8 +213,14 @@ private async Task ProcessBatch(List<IPackageIdGroup> batch, SqlConnection desti
206213
Logger.LogInformation("Updating destination database Download Counts... ({RecordCount} package registrations to process).", batch.Count());
207214
stopwatch.Restart();
208215

209-
await destinationDatabase.ExecuteAsync(_updateFromTempTable,
210-
commandTimeout: TimeSpan.FromMinutes(30));
216+
using (var cmd = destinationDatabase.CreateCommand())
217+
{
218+
cmd.CommandText = _updateFromTempTable;
219+
cmd.CommandType = CommandType.Text;
220+
cmd.CommandTimeout = (int)TimeSpan.FromMinutes(30).TotalSeconds;
221+
222+
await cmd.ExecuteNonQueryAsync();
223+
}
211224

212225
Logger.LogInformation(
213226
"Updated destination database Download Counts (took {DurationSeconds} seconds).",

0 commit comments

Comments
 (0)