Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/BannedSymbols.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
P:System.DateTime.Now;Use TimeProvider instead.
P:System.DateTime.UtcNow;Use TimeProvider instead.
P:System.DateTimeOffset.Now;Use TimeProvider instead.
P:System.DateTimeOffset.UtcNow;Use TimeProvider instead.
6 changes: 6 additions & 0 deletions src/Custom.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
<InstanceName Include="Particular.ServiceControl.Monitoring" />
</ItemGroup>

<!-- WPF-generated XAML compilation projects do not need analyzers. -->
<ItemGroup Condition="!$(MSBuildProjectFile.EndsWith('_wpftmp.csproj'))">
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" PrivateAssets="All" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)BannedSymbols.txt" Visible="false" />
</ItemGroup>

<PropertyGroup>
<RuntimeIdentifier Condition="'$(WindowsSelfContained)' == 'true'">win-x64</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(TargetArch)' == 'amd64'">linux-x64</RuntimeIdentifier>
Expand Down
1 change: 1 addition & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="$(RuntimeFrameworkVersion)" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="$(RuntimeFrameworkVersion)" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(RuntimeFrameworkVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="5.6.0" />
<PackageVersion Include="Microsoft.Data.SqlClient.Extensions.Azure" Version="7.0.2" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="$(RuntimeFrameworkVersion)" />
<PackageVersion Include="Microsoft.Extensions.DependencyModel" Version="$(RuntimeFrameworkVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ dotnet_diagnostic.CA2007.severity = none
# Justification: Rider displays an error to do with "Accessibility modifiers required (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0040)"
dotnet_diagnostic.IDE0040.severity = none

csharp_style_var_elsewhere = true:error
csharp_style_var_elsewhere = true:error
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,25 @@ public async Task UpdateUserIndicatorOnEndpoints(List<UpdateUserIndicator> userI
await Task.CompletedTask;
}

#pragma warning disable RS0030 // Do not use banned apis: Throughput is based on external clocks
public async Task<bool> IsThereThroughputForLastXDays(int days, CancellationToken cancellationToken = default) => await Task.FromResult(
allThroughput.Any(endpointThroughput => endpointThroughput.Value.Any(
t => t.Key >= DateOnly.FromDateTime(DateTime.UtcNow).AddDays(-days) &&
t.Key <= DateOnly.FromDateTime(DateTime.UtcNow).AddDays(-1))));
#pragma warning restore RS0030

public async Task<bool> IsThereThroughputForLastXDaysForSource(int days, ThroughputSource throughputSource, bool includeToday, CancellationToken cancellationToken = default)
{
#pragma warning disable RS0030 // Do not use banned apis: Throughput is based on external clocks
var endDate = includeToday ? DateOnly.FromDateTime(DateTime.UtcNow) : DateOnly.FromDateTime(DateTime.UtcNow).AddDays(-1);
#pragma warning restore RS0030

return await Task.FromResult(
allThroughput.Any(
endpointThroughput => endpointThroughput.Key.ThroughputSource == throughputSource &&
#pragma warning disable RS0030 // Do not use banned apis: Throughput is based on external clocks
endpointThroughput.Value.Any(t => t.Key >= DateOnly.FromDateTime(DateTime.UtcNow).AddDays(-days) && t.Key <= endDate)));
#pragma warning restore RS0030
}

List<Endpoint> GetAllConnectedEndpoints(string name) => endpoints.Where(w => w.SanitizedName == name || w.Id.Name == name).ToList();
Expand Down
1 change: 1 addition & 0 deletions src/Particular.LicensingComponent.UnitTests/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

# Justification: Test project
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.RS0030.severity = none
dotnet_diagnostic.PS0018.severity = none
2 changes: 1 addition & 1 deletion src/Particular.LicensingComponent/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ dotnet_diagnostic.IDE0040.severity = none
dotnet_diagnostic.IDE0010.severity = suggestion

csharp_style_var_elsewhere = true:error
csharp_style_var_for_built_in_types = true:error
csharp_style_var_for_built_in_types = true:error
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ async Task GatherThroughput(CancellationToken cancellationToken)

var missingAuditThroughput = auditCounts
.Where(auditCount => auditCount.UtcDate > endpoint.LastCollectedDate &&
#pragma warning disable RS0030 // Do not use banned apis: Throughput collection periods are based on current calendar dates
auditCount.UtcDate < DateOnly.FromDateTime(DateTime.UtcNow))
#pragma warning restore RS0030
.Select(auditCount => new EndpointDailyThroughput(auditCount.UtcDate, auditCount.Count))
.ToList();

Expand Down
2 changes: 2 additions & 0 deletions src/Particular.LicensingComponent/ThroughputCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ public async Task<SignedReport> GenerateThroughputReport(string spVersion, DateT

if (reportEndDate is null || reportEndDate == DateTime.MinValue)
{
#pragma warning disable RS0030 // Do not use banned apis: Throughput collection periods are based on current calendar dates
reportEndDate = DateTime.UtcNow.Date;
#pragma warning restore RS0030
}

var queueThroughputs = new List<QueueThroughput>();
Expand Down
3 changes: 3 additions & 0 deletions src/ServiceControl.AcceptanceTesting/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

# Justification: Usage is from test projects
dotnet_diagnostic.CA2007.severity = none

# Justification: Usage is from test projects
dotnet_diagnostic.RS0030.severity = none
4 changes: 4 additions & 0 deletions src/ServiceControl.AcceptanceTests.PostgreSql/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# Justification: Test project
dotnet_diagnostic.RS0030.severity = none
1 change: 1 addition & 0 deletions src/ServiceControl.AcceptanceTests.RavenDB/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

# Justification: Test project
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.RS0030.severity = none
4 changes: 4 additions & 0 deletions src/ServiceControl.AcceptanceTests.SqlServer/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# Justification: Test project
dotnet_diagnostic.RS0030.severity = none
1 change: 1 addition & 0 deletions src/ServiceControl.AcceptanceTests/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.PS0013.severity = none
dotnet_diagnostic.PS0018.severity = none
dotnet_diagnostic.RS0030.severity = none
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

# Justification: Test project
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.RS0030.severity = none
dotnet_diagnostic.PS0018.severity = none
1 change: 1 addition & 0 deletions src/ServiceControl.Audit.AcceptanceTests/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# Justification: Test project
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.PS0018.severity = none
dotnet_diagnostic.RS0030.severity = none
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[*.cs]

# Justification: ServiceControl app has no synchronization context
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.CA2007.severity = none
2 changes: 1 addition & 1 deletion src/ServiceControl.Audit.Persistence.RavenDB/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[*.cs]

# Justification: ServiceControl app has no synchronization context
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.CA2007.severity = none
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ int CheckAndReportIndexesWithTooMuchIndexLag(IndexInformation[] indexes)
{
if (indexStats.IsStale && indexStats.LastIndexingTime.HasValue)
{
#pragma warning disable RS0030 // Do not use banned apis: RavenDB retention, index lag, and date boundaries require current wall-clock time
var indexLag = DateTime.UtcNow - indexStats.LastIndexingTime.Value;
#pragma warning restore RS0030

if (indexLag > IndexLagThresholdError)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ public async Task<QueryResult<IList<AuditCount>>> QueryAuditCounts(string endpoi

if (oldestMsg != null)
{
#pragma warning disable RS0030 // Do not use banned apis: RavenDB retention, index lag, and date boundaries require current wall-clock time
var endDate = DateTime.UtcNow.Date.AddDays(1);
#pragma warning restore RS0030
var oldestMsgDate = oldestMsg.ProcessedAt.ToUniversalTime().Date;
var thirtyDays = endDate.AddDays(-30);

Expand Down Expand Up @@ -181,7 +183,9 @@ public async Task<QueryResult<IList<AuditCount>>> QueryAuditCounts(string endpoi
{
results.Add(new AuditCount
{
#pragma warning disable RS0030 // Do not use banned apis: RavenDB retention, index lag, and date boundaries require current wall-clock time
UtcDate = DateTime.UtcNow.Date,
#pragma warning restore RS0030
Count = 0
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public async Task RecordProcessedMessage(ProcessedMessage processedMessage, Read
MetadataAsDictionary GetExpirationMetadata() =>
new()
{
#pragma warning disable RS0030 // Do not use banned apis: RavenDB retention, index lag, and date boundaries require current wall-clock time
[Constants.Documents.Metadata.Expires] = DateTime.UtcNow.Add(auditRetentionPeriod)
#pragma warning restore RS0030
};

public Task RecordSagaSnapshot(SagaSnapshot sagaSnapshot, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

# Justification: Test project
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.RS0030.severity = none
dotnet_diagnostic.PS0018.severity = none
1 change: 1 addition & 0 deletions src/ServiceControl.Audit.Persistence.Tests/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Justification: Test project
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.RS0030.severity = none
dotnet_diagnostic.PS0018.severity = none

# Justification: Tests don't support cancellation and don't need to forward IMessageHandlerContext.CancellationToken
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceControl.Audit.Persistence/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[*.cs]

# Justification: ServiceControl app has no synchronization context
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.CA2007.severity = none
4 changes: 4 additions & 0 deletions src/ServiceControl.Audit.Persistence/ProcessedMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ public ProcessedMessage(Dictionary<string, string> headers, Dictionary<string, o
var processingStartedTicks =
headers.TryGetValue(NServiceBus.Headers.ProcessingStarted, out var processingStartedValue)
? DateTimeOffsetHelper.ToDateTimeOffset(processingStartedValue).UtcDateTime.Ticks.ToString()
#pragma warning disable RS0030 // Do not use banned apis: Missing message timestamps fall back to the current wall-clock time
: DateTime.UtcNow.Ticks.ToString();
#pragma warning restore RS0030

var documentId = $"{processingStartedTicks}-{headers.ProcessingId()}";

Id = $"ProcessedMessages-{documentId}";

ProcessedAt = Headers.TryGetValue(NServiceBus.Headers.ProcessingEnded, out var processedAt) ?
#pragma warning disable RS0030 // Do not use banned apis: Missing message timestamps fall back to the current wall-clock time
DateTimeOffsetHelper.ToDateTimeOffset(processedAt).UtcDateTime : DateTime.UtcNow; // best guess
#pragma warning restore RS0030
}

public string Id { get; set; }
Expand Down
1 change: 1 addition & 0 deletions src/ServiceControl.Audit.UnitTests/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

# Justification: Test project
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.RS0030.severity = none
dotnet_diagnostic.PS0018.severity = none
2 changes: 1 addition & 1 deletion src/ServiceControl.Audit/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[*.cs]

# Justification: ServiceControl app has no synchronization context
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.CA2007.severity = none
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ void TryAddEndpoint(EndpointDetails endpointDetails, AuditEnricherContext contex
{
context.AddForSend(new RegisterNewEndpoint
{
#pragma warning disable RS0030 // Do not use banned apis: Audit enrichment timestamps must reflect when events are processed
DetectedAt = DateTime.UtcNow,
#pragma warning restore RS0030
Endpoint = endpointDetails
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public void Enrich(AuditEnricherContext context)
//and did not send the acknowledgment. We send it here to the acknowledgment queue.
var ackMessage = new OutgoingMessage(Guid.NewGuid().ToString(), new Dictionary<string, string>
{
#pragma warning disable RS0030 // Do not use banned apis: Audit enrichment timestamps must reflect when events are processed
["ServiceControl.Retry.Successful"] = DateTimeOffsetHelper.ToWireFormattedString(DateTimeOffset.UtcNow),
#pragma warning restore RS0030
["ServiceControl.Retry.UniqueMessageId"] = newRetryMessageId
}, Array.Empty<byte>());
var ackOperation = new TransportOperation(ackMessage, new UnicastAddressTag(ackQueue));
Expand Down
1 change: 1 addition & 0 deletions src/ServiceControl.Config.Tests/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Justification: Test project
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.RS0030.severity = none

# Justification: Executable specifications intentionally assign properties after the
# object initializer to mirror user interaction order (e.g. typing a name after load)
Expand Down
2 changes: 2 additions & 0 deletions src/ServiceControl.Config/UI/Shell/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ IEventAggregator eventAggregator
DisplayName = "ServiceControl Config";
IsModal = false;
LoadAppVersion();
#pragma warning disable RS0030 // Do not use banned apis: UtcNow for copyright is acceptable
CopyrightInfo = $"{DateTime.UtcNow.Year} © Particular Software";
#pragma warning restore RS0030

RefreshInstancesCmd = Command.Create(async () =>
{
Expand Down
2 changes: 2 additions & 0 deletions src/ServiceControl.Infrastructure.Metrics/Counter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ internal Counter(string name, bool enabled)
eventsPerSecond = new int[2];
movingAverage = new int[300];
movingAverageEpochs = new long[300];
#pragma warning disable RS0030 // Do not use banned apis: metrics do not need to use external time provider
epoch = DateTime.UtcNow.Minute;
#pragma warning restore RS0030
}

public void Mark()
Expand Down
2 changes: 2 additions & 0 deletions src/ServiceControl.Infrastructure.Metrics/Meter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ internal Meter(string name, bool enabled, float scale = 1)
movingAverageSums = new long[300];
movingAverageCounts = new long[300];
movingAverageEpochs = new long[300];
#pragma warning disable RS0030 // Do not use banned apis: metrics do not need to use external time provider
epoch = DateTime.UtcNow.Minute;
#pragma warning restore RS0030
}

public Measurement Measure() => new Measurement(this, enabled);
Expand Down
1 change: 1 addition & 0 deletions src/ServiceControl.Infrastructure.Tests/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

# Justification: Test project
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.RS0030.severity = none

4 changes: 4 additions & 0 deletions src/ServiceControl.Infrastructure/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# Justification: Test project
dotnet_diagnostic.RS0030.severity = none
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ static string BuildEcsEvent(string subjectId, string subjectName, string permiss
{
var ecs = new Dictionary<string, object?>
{
#pragma warning disable RS0030 // Do not use banned apis: logging should use real time
["@timestamp"] = DateTimeOffset.UtcNow.ToString("O"),
#pragma warning restore RS0030
["ecs"] = new { version = EcsVersion },
["event"] = new
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ static string BuildEcsEvent(AuditUser user, MessageActionKind kind, string permi
{
var ecs = new Dictionary<string, object?>
{
#pragma warning disable RS0030 // Do not use banned apis: logging should use real time
["@timestamp"] = DateTimeOffset.UtcNow.ToString("O"),
#pragma warning restore RS0030
["ecs"] = new { version = AuthorizationAuditLog.EcsVersion },
["event"] = new
{
Expand Down
2 changes: 2 additions & 0 deletions src/ServiceControl.Infrastructure/LoggingConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public static string ConfigureNLog(string logFileName, string logPath, LogLevel

NLog.LogManager.Configuration = nlogConfig;

#pragma warning disable RS0030 // Do not use banned apis: logging should use real time
var logEventInfo = new LogEventInfo { TimeStamp = DateTime.UtcNow };
#pragma warning restore RS0030
var fileTarget = nlogConfig.FindTargetByName<FileTarget>("file");
return AppEnvironment.RunningInContainer ? "console" : fileTarget.FileName.Render(logEventInfo);
}
Expand Down
1 change: 1 addition & 0 deletions src/ServiceControl.LicenseManagement/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[*.cs]
6 changes: 6 additions & 0 deletions src/ServiceControl.LicenseManagement/LicenseDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public static LicenseDetails TrialExpired()
return FromLicense(new License
{
LicenseType = "Trial",
#pragma warning disable RS0030 // Do not use banned apis: License expiry must be evaluated against current wall-clock time
ExpirationDate = DateTime.UtcNow.Date.AddDays(-2), //HasLicenseDateExpired uses a grace period of 1 day
#pragma warning restore RS0030
IsExtendedTrial = false,
ValidApplications = ["All"]
});
Expand All @@ -74,7 +76,9 @@ internal static LicenseDetails FromLicense(License license)
UpgradeProtectionExpiration = license.UpgradeProtectionExpiration,
//If expiration date is greater that 50 years treat is as no expiration date
ExpirationDate = license.ExpirationDate.HasValue
#pragma warning disable RS0030 // Do not use banned apis: License expiry must be evaluated against current wall-clock time
? license.ExpirationDate.Value > DateTime.UtcNow.AddYears(50) ? null : license.ExpirationDate
#pragma warning restore RS0030
: license.ExpirationDate,
RegisteredTo = license.RegisteredTo,
IsCommercialLicense = license.IsCommercialLicense,
Expand Down Expand Up @@ -107,7 +111,9 @@ static bool HasLicenseDateExpired(DateTime licenseDate)
oneDayGrace = licenseDate.AddDays(1);
}

#pragma warning disable RS0030 // Do not use banned apis: License expiry must be evaluated against current wall-clock time
return oneDayGrace < DateTime.UtcNow.Date;
#pragma warning restore RS0030
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

# Justification: Test project
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.RS0030.severity = none
1 change: 1 addition & 0 deletions src/ServiceControl.Monitoring.UnitTests/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

# Justification: Test project
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.RS0030.severity = none
csharp_style_var_elsewhere = true:error
csharp_style_var_for_built_in_types = true:error
2 changes: 1 addition & 1 deletion src/ServiceControl.Monitoring/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[*.cs]

# Justification: Application synchronization contexts don't require ConfigureAwait(false)
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.CA2007.severity = none
Loading
Loading