diff --git a/src/Foundatio.AppMetrics/AppMetricsClient.cs b/src/Foundatio.AppMetrics/AppMetricsClient.cs index 6f007200..9feffee5 100644 --- a/src/Foundatio.AppMetrics/AppMetricsClient.cs +++ b/src/Foundatio.AppMetrics/AppMetricsClient.cs @@ -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; diff --git a/src/Foundatio.Extensions.Hosting/Jobs/HostedJobService.cs b/src/Foundatio.Extensions.Hosting/Jobs/HostedJobService.cs index 546894ea..ab571d6f 100644 --- a/src/Foundatio.Extensions.Hosting/Jobs/HostedJobService.cs +++ b/src/Foundatio.Extensions.Hosting/Jobs/HostedJobService.cs @@ -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 { @@ -74,7 +78,11 @@ public async Task StopAsync(CancellationToken cancellationToken) try { +#if NET8_0_OR_GREATER + await _stoppingCts.CancelAsync(); +#else _stoppingCts.Cancel(); +#endif } finally { diff --git a/src/Foundatio.MetricsNET/MetricsNETClient.cs b/src/Foundatio.MetricsNET/MetricsNETClient.cs index 122993a2..0dc737a2 100644 --- a/src/Foundatio.MetricsNET/MetricsNETClient.cs +++ b/src/Foundatio.MetricsNET/MetricsNETClient.cs @@ -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) { diff --git a/src/Foundatio.TestHarness/Jobs/JobQueueTestsBase.cs b/src/Foundatio.TestHarness/Jobs/JobQueueTestsBase.cs index 8af588f6..e7974982 100644 --- a/src/Foundatio.TestHarness/Jobs/JobQueueTestsBase.cs +++ b/src/Foundatio.TestHarness/Jobs/JobQueueTestsBase.cs @@ -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(metrics, "test", loggerFactory: Log)); +#pragma warning restore CS0618 // Type or member is obsolete queues.Add(q); } _logger.LogInformation("Done setting up queues"); diff --git a/src/Foundatio.TestHarness/Jobs/SampleQueueJob.cs b/src/Foundatio.TestHarness/Jobs/SampleQueueJob.cs index b7b2356a..35ea7e27 100644 --- a/src/Foundatio.TestHarness/Jobs/SampleQueueJob.cs +++ b/src/Foundatio.TestHarness/Jobs/SampleQueueJob.cs @@ -1,4 +1,6 @@ -using System; +#pragma warning disable 612, 618 + +using System; using System.Threading; using System.Threading.Tasks; using Exceptionless; @@ -118,3 +120,5 @@ protected override Task RunInternalAsync(JobContext context) return Task.FromResult(JobResult.Success); } } + +#pragma warning restore 612, 618 diff --git a/src/Foundatio.TestHarness/Metrics/MetricsClientTestBase.cs b/src/Foundatio.TestHarness/Metrics/MetricsClientTestBase.cs index dd8cde1e..5608847c 100644 --- a/src/Foundatio.TestHarness/Metrics/MetricsClientTestBase.cs +++ b/src/Foundatio.TestHarness/Metrics/MetricsClientTestBase.cs @@ -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; @@ -215,3 +216,5 @@ public virtual async Task CanSendBufferedMetricsAsync() Assert.Equal(100, counter.Count); } } + +#pragma warning restore 612, 618 diff --git a/src/Foundatio.TestHarness/Queue/QueueTestBase.cs b/src/Foundatio.TestHarness/Queue/QueueTestBase.cs index be043688..f0899eee 100644 --- a/src/Foundatio.TestHarness/Queue/QueueTestBase.cs +++ b/src/Foundatio.TestHarness/Queue/QueueTestBase.cs @@ -29,7 +29,9 @@ protected QueueTestBase(ITestOutputHelper output) : base(output) { Log.SetLogLevel(LogLevel.Debug); Log.SetLogLevel(LogLevel.Debug); +#pragma warning disable CS0618 // Type or member is obsolete Log.SetLogLevel>(LogLevel.Debug); +#pragma warning restore CS0618 // Type or member is obsolete Log.SetLogLevel(LogLevel.Debug); } @@ -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(metrics, reportCountsInterval: TimeSpan.FromMilliseconds(100), loggerFactory: Log)); +#pragma warning restore CS0618 // Type or member is obsolete _ = Task.Run(async () => { @@ -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(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++) @@ -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(metrics, reportCountsInterval: TimeSpan.FromMilliseconds(100), loggerFactory: Log)); +#pragma warning restore CS0618 // Type or member is obsolete await queue.StartWorkingAsync(w => { _logger.LogDebug("WorkAction"); @@ -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(metrics, "metric", TimeSpan.FromMilliseconds(100), loggerFactory: Log); +#pragma warning restore CS0618 // Type or member is obsolete var options = new InMemoryQueueOptions { Behaviors = new[] { behavior }, LoggerFactory = Log }; using var queue = new InMemoryQueue(options); @@ -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(metrics, loggerFactory: Log)); +#pragma warning restore CS0618 // Type or member is obsolete var resetEvent = new AsyncAutoResetEvent(); await queue.StartWorkingAsync(async w => diff --git a/src/Foundatio.TestHarness/Storage/FileStorageTestsBase.cs b/src/Foundatio.TestHarness/Storage/FileStorageTestsBase.cs index ea3294a0..ccc66893 100644 --- a/src/Foundatio.TestHarness/Storage/FileStorageTestsBase.cs +++ b/src/Foundatio.TestHarness/Storage/FileStorageTestsBase.cs @@ -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)); } diff --git a/src/Foundatio/Metrics/DiagnosticsMetricsClient.cs b/src/Foundatio/Metrics/DiagnosticsMetricsClient.cs index eca7c425..2ec18f7f 100644 --- a/src/Foundatio/Metrics/DiagnosticsMetricsClient.cs +++ b/src/Foundatio/Metrics/DiagnosticsMetricsClient.cs @@ -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; diff --git a/src/Foundatio/Storage/IFileStorage.cs b/src/Foundatio/Storage/IFileStorage.cs index 84ab5ab9..94698609 100644 --- a/src/Foundatio/Storage/IFileStorage.cs +++ b/src/Foundatio/Storage/IFileStorage.cs @@ -128,7 +128,9 @@ public static async Task GetObjectAsync(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(stream); @@ -149,7 +151,9 @@ public static async Task 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(); @@ -161,7 +165,9 @@ public static async Task 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; diff --git a/tests/Foundatio.Tests/Jobs/WorkItemJobTests.cs b/tests/Foundatio.Tests/Jobs/WorkItemJobTests.cs index 575f76f6..3ee0a37c 100644 --- a/tests/Foundatio.Tests/Jobs/WorkItemJobTests.cs +++ b/tests/Foundatio.Tests/Jobs/WorkItemJobTests.cs @@ -69,7 +69,9 @@ public async Task CanHandleMultipleWorkItemInstances() using var metrics = new InMemoryMetricsClient(o => o.LoggerFactory(Log)); using var queue = new InMemoryQueue(o => o.RetryDelay(TimeSpan.Zero).Retries(0).LoggerFactory(Log)); +#pragma warning disable CS0618 // Type or member is obsolete queue.AttachBehavior(new MetricsQueueBehavior(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); diff --git a/tests/Foundatio.Tests/Metrics/InMemoryMetricsTests.cs b/tests/Foundatio.Tests/Metrics/InMemoryMetricsTests.cs index 46ac1650..619ecc30 100644 --- a/tests/Foundatio.Tests/Metrics/InMemoryMetricsTests.cs +++ b/tests/Foundatio.Tests/Metrics/InMemoryMetricsTests.cs @@ -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)); }