Skip to content

Commit

Permalink
Fix more build warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ejsmith committed Feb 14, 2024
1 parent eb5b42d commit f23bdcc
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/Foundatio.AppMetrics/AppMetricsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

namespace Foundatio.Metrics;

#pragma warning disable CS0618 // Type or member is obsolete
public class AppMetricsClient : IMetricsClient
#pragma warning restore CS0618 // Type or member is obsolete
{
private readonly IMetrics _metrics;

Expand Down
8 changes: 8 additions & 0 deletions src/Foundatio.Extensions.Hosting/Jobs/HostedJobService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ private async Task ExecuteAsync(CancellationToken stoppingToken)
try
{
await runner.RunAsync(stoppingToken).AnyContext();
#if NET8_0_OR_GREATER
await _stoppingCts.CancelAsync();
#else
_stoppingCts.Cancel();
#endif
}
finally
{
Expand All @@ -74,7 +78,11 @@ public async Task StopAsync(CancellationToken cancellationToken)

try
{
#if NET8_0_OR_GREATER
await _stoppingCts.CancelAsync();
#else
_stoppingCts.Cancel();
#endif
}
finally
{
Expand Down
2 changes: 2 additions & 0 deletions src/Foundatio.MetricsNET/MetricsNETClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

namespace Foundatio.Metrics;

#pragma warning disable CS0618 // Type or member is obsolete
public class MetricsNETClient : IMetricsClient
#pragma warning restore CS0618 // Type or member is obsolete
{
public void Counter(string name, int value = 1)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Foundatio.TestHarness/Jobs/JobQueueTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ public virtual async Task CanRunMultipleQueueJobsAsync()
{
var q = GetSampleWorkItemQueue(retries: 1, retryDelay: TimeSpan.Zero);
await q.DeleteQueueAsync();
#pragma warning disable CS0618 // Type or member is obsolete
q.AttachBehavior(new MetricsQueueBehavior<SampleQueueWorkItem>(metrics, "test", loggerFactory: Log));
#pragma warning restore CS0618 // Type or member is obsolete
queues.Add(q);
}
_logger.LogInformation("Done setting up queues");
Expand Down
6 changes: 5 additions & 1 deletion src/Foundatio.TestHarness/Jobs/SampleQueueJob.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
#pragma warning disable 612, 618

using System;
using System.Threading;
using System.Threading.Tasks;
using Exceptionless;
Expand Down Expand Up @@ -118,3 +120,5 @@ protected override Task<JobResult> RunInternalAsync(JobContext context)
return Task.FromResult(JobResult.Success);
}
}

#pragma warning restore 612, 618
3 changes: 3 additions & 0 deletions src/Foundatio.TestHarness/Metrics/MetricsClientTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Xunit;
using Xunit.Abstractions;
#pragma warning disable AsyncFixer04 // A disposable object used in a fire & forget async call
#pragma warning disable 612, 618

namespace Foundatio.Tests.Metrics;

Expand Down Expand Up @@ -215,3 +216,5 @@ public virtual async Task CanSendBufferedMetricsAsync()
Assert.Equal(100, counter.Count);
}
}

#pragma warning restore 612, 618
12 changes: 12 additions & 0 deletions src/Foundatio.TestHarness/Queue/QueueTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ protected QueueTestBase(ITestOutputHelper output) : base(output)
{
Log.SetLogLevel<InMemoryCacheClient>(LogLevel.Debug);
Log.SetLogLevel<InMemoryMetricsClient>(LogLevel.Debug);
#pragma warning disable CS0618 // Type or member is obsolete
Log.SetLogLevel<MetricsQueueBehavior<SimpleWorkItem>>(LogLevel.Debug);
#pragma warning restore CS0618 // Type or member is obsolete
Log.SetLogLevel<ScheduledTimer>(LogLevel.Debug);
}

Expand Down Expand Up @@ -479,7 +481,9 @@ public virtual async Task CanDequeueEfficientlyAsync()
using var metricsCollector = new DiagnosticsMetricsCollector(FoundatioDiagnostics.Meter.Name, _logger);

using var metrics = new InMemoryMetricsClient(new InMemoryMetricsClientOptions());
#pragma warning disable CS0618 // Type or member is obsolete
queue.AttachBehavior(new MetricsQueueBehavior<SimpleWorkItem>(metrics, reportCountsInterval: TimeSpan.FromMilliseconds(100), loggerFactory: Log));
#pragma warning restore CS0618 // Type or member is obsolete

_ = Task.Run(async () =>
{
Expand Down Expand Up @@ -532,7 +536,9 @@ public virtual async Task CanResumeDequeueEfficientlyAsync()
await queue.EnqueueAsync(new SimpleWorkItem { Data = "Hello" });

using var secondQueue = GetQueue(runQueueMaintenance: false);
#pragma warning disable CS0618 // Type or member is obsolete
secondQueue.AttachBehavior(new MetricsQueueBehavior<SimpleWorkItem>(metrics, reportCountsInterval: TimeSpan.FromMilliseconds(100), loggerFactory: Log));
#pragma warning restore CS0618 // Type or member is obsolete

_logger.LogTrace("Starting dequeue loop");
for (int index = 0; index < iterations; index++)
Expand Down Expand Up @@ -757,7 +763,9 @@ public virtual async Task CanHandleErrorInWorkerAsync()

using var metrics = new InMemoryMetricsClient(new InMemoryMetricsClientOptions { Buffered = false, LoggerFactory = Log });

#pragma warning disable CS0618 // Type or member is obsolete
queue.AttachBehavior(new MetricsQueueBehavior<SimpleWorkItem>(metrics, reportCountsInterval: TimeSpan.FromMilliseconds(100), loggerFactory: Log));
#pragma warning restore CS0618 // Type or member is obsolete
await queue.StartWorkingAsync(w =>
{
_logger.LogDebug("WorkAction");
Expand Down Expand Up @@ -1061,7 +1069,9 @@ public virtual async Task CanRunWorkItemWithMetricsAsync()

using var metrics = new InMemoryMetricsClient(new InMemoryMetricsClientOptions { Buffered = false, LoggerFactory = Log });

#pragma warning disable CS0618 // Type or member is obsolete
var behavior = new MetricsQueueBehavior<WorkItemData>(metrics, "metric", TimeSpan.FromMilliseconds(100), loggerFactory: Log);
#pragma warning restore CS0618 // Type or member is obsolete
var options = new InMemoryQueueOptions<WorkItemData> { Behaviors = new[] { behavior }, LoggerFactory = Log };
using var queue = new InMemoryQueue<WorkItemData>(options);

Expand Down Expand Up @@ -1316,7 +1326,9 @@ protected async Task CanDequeueWithLockingImpAsync(CacheLockProvider distributed
Log.DefaultMinimumLevel = LogLevel.Trace;
using var metrics = new InMemoryMetricsClient(new InMemoryMetricsClientOptions { Buffered = false, LoggerFactory = Log });

#pragma warning disable CS0618 // Type or member is obsolete
queue.AttachBehavior(new MetricsQueueBehavior<SimpleWorkItem>(metrics, loggerFactory: Log));
#pragma warning restore CS0618 // Type or member is obsolete

var resetEvent = new AsyncAutoResetEvent();
await queue.StartWorkingAsync(async w =>
Expand Down
2 changes: 2 additions & 0 deletions src/Foundatio.TestHarness/Storage/FileStorageTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,9 @@ public virtual async Task CanRoundTripSeekableStreamAsync()
_logger.LogTrace("Saved contents with position {Position}.", memoryStream.Position);
}

#pragma warning disable CS0618 // Type or member is obsolete
await using var stream = await storage.GetFileStreamAsync(path);
#pragma warning restore CS0618 // Type or member is obsolete
var actual = XElement.Load(stream);
Assert.Equal(element.ToString(SaveOptions.DisableFormatting), actual.ToString(SaveOptions.DisableFormatting));
}
Expand Down
5 changes: 3 additions & 2 deletions src/Foundatio/Metrics/DiagnosticsMetricsClient.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
#pragma warning disable 612, 618

using System;
using System.Collections.Concurrent;
using System.Diagnostics.Metrics;
#pragma warning disable 612, 618

namespace Foundatio.Metrics;

Expand Down
6 changes: 6 additions & 0 deletions src/Foundatio/Storage/IFileStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ public static async Task<T> GetObjectAsync<T>(this IFileStorage storage, string
if (String.IsNullOrEmpty(path))
throw new ArgumentNullException(nameof(path));

#pragma warning disable CS0618 // Type or member is obsolete
using var stream = await storage.GetFileStreamAsync(path, cancellationToken).AnyContext();
#pragma warning restore CS0618 // Type or member is obsolete
if (stream != null)
return storage.Serializer.Deserialize<T>(stream);

Expand All @@ -149,7 +151,9 @@ public static async Task<string> GetFileContentsAsync(this IFileStorage storage,
if (String.IsNullOrEmpty(path))
throw new ArgumentNullException(nameof(path));

#pragma warning disable CS0618 // Type or member is obsolete
using var stream = await storage.GetFileStreamAsync(path).AnyContext();
#pragma warning restore CS0618 // Type or member is obsolete
if (stream != null)
return await new StreamReader(stream).ReadToEndAsync().AnyContext();

Expand All @@ -161,7 +165,9 @@ public static async Task<byte[]> GetFileContentsRawAsync(this IFileStorage stora
if (String.IsNullOrEmpty(path))
throw new ArgumentNullException(nameof(path));

#pragma warning disable CS0618 // Type or member is obsolete
using var stream = await storage.GetFileStreamAsync(path).AnyContext();
#pragma warning restore CS0618 // Type or member is obsolete
if (stream == null)
return null;

Expand Down
2 changes: 2 additions & 0 deletions tests/Foundatio.Tests/Jobs/WorkItemJobTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ public async Task CanHandleMultipleWorkItemInstances()

using var metrics = new InMemoryMetricsClient(o => o.LoggerFactory(Log));
using var queue = new InMemoryQueue<WorkItemData>(o => o.RetryDelay(TimeSpan.Zero).Retries(0).LoggerFactory(Log));
#pragma warning disable CS0618 // Type or member is obsolete
queue.AttachBehavior(new MetricsQueueBehavior<WorkItemData>(metrics, loggerFactory: Log));
#pragma warning restore CS0618 // Type or member is obsolete
using var messageBus = new InMemoryMessageBus(o => o.LoggerFactory(Log));
var handlerRegistry = new WorkItemHandlers();
var j1 = new WorkItemJob(queue, messageBus, handlerRegistry, Log);
Expand Down
2 changes: 2 additions & 0 deletions tests/Foundatio.Tests/Metrics/InMemoryMetricsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public class InMemoryMetricsTests : MetricsClientTestBase
{
public InMemoryMetricsTests(ITestOutputHelper output) : base(output) { }

#pragma warning disable CS0618 // Type or member is obsolete
public override IMetricsClient GetMetricsClient(bool buffered = false)
#pragma warning restore CS0618 // Type or member is obsolete
{
return new InMemoryMetricsClient(o => o.LoggerFactory(Log).Buffered(buffered));
}
Expand Down

0 comments on commit f23bdcc

Please sign in to comment.