-
Notifications
You must be signed in to change notification settings - Fork 0
Upgrade newest standards #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
88e0d98
2aae2d0
be95cfb
7ff17cf
e0a1802
24e6b59
f1e2e8b
574f696
f2bbb0d
a7f4589
22e436e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -433,3 +433,4 @@ docfx_project/obj/ | |
| docs/* | ||
| !docs/.gitkeep | ||
| !docs/RELEASE-WORKFLOW-SETUP.md | ||
| .nuget/nuget.exe | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| namespace Example6_ReducingDuplicateCode | ||
| { | ||
| internal class ConsoleColors | ||
| { | ||
| public const string Green = "\u001b[32m"; | ||
| public const string Yellow = "\u001b[33m"; | ||
| public const string Reset = "\u001b[0m"; | ||
| public const string Red = "\u001b[31m"; | ||
| public const string Cyan = "\u001b[36m"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,21 +28,21 @@ public int ProgressInterval | |
|
|
||
| public IAsyncEnumerable<int> ExtractAsync() | ||
| { | ||
| return WorkerAsync(null, CancellationToken.None); | ||
| return WorkerAsync(progress: null, CancellationToken.None); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| public IAsyncEnumerable<int> ExtractAsync(CancellationToken token) | ||
| { | ||
| return WorkerAsync(null, token); | ||
| return WorkerAsync(progress: null, token); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| public IAsyncEnumerable<int> ExtractAsync(IProgress<EtlProgress> progress) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(progress, nameof(progress)); | ||
| ArgumentNullException.ThrowIfNull(progress); | ||
|
|
||
| return WorkerAsync(progress, CancellationToken.None); | ||
| } | ||
|
|
@@ -55,7 +55,7 @@ public IAsyncEnumerable<int> ExtractAsync | |
| CancellationToken token | ||
| ) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(progress, nameof(progress)); | ||
| ArgumentNullException.ThrowIfNull(progress); | ||
|
|
||
| return WorkerAsync(progress, token); | ||
| } | ||
|
|
@@ -74,10 +74,10 @@ [EnumeratorCancellation] CancellationToken token | |
| await using var timer = new Timer | ||
| ( | ||
| _ => progress?.Report(new EtlProgress(Volatile.Read(ref count))), | ||
| null, | ||
| state: null, | ||
| TimeSpan.Zero, | ||
| TimeSpan.FromMilliseconds(_progressInterval) // Use the configured progress interval | ||
| ); | ||
| ).ConfigureAwait(false); | ||
|
Comment on lines
76
to
+80
|
||
|
|
||
| var current = 1; | ||
| var previous = 0; | ||
|
|
@@ -100,7 +100,7 @@ [EnumeratorCancellation] CancellationToken token | |
| var temp = current; | ||
| current += previous; | ||
| previous = temp; | ||
| await Task.Delay(100); // Simulate asynchronous operation | ||
| await Task.Delay(100, CancellationToken.None).ConfigureAwait(false); // Simulate asynchronous operation | ||
| } | ||
|
Comment on lines
100
to
104
|
||
|
|
||
| progress?.Report(new EtlProgress(Volatile.Read(ref count))); // Report final count | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,9 +31,9 @@ public IAsyncEnumerable<string> TransformAsync | |
| IAsyncEnumerable<int> items | ||
| ) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(items, nameof(items)); | ||
| ArgumentNullException.ThrowIfNull(items); | ||
|
|
||
| return WorkerAsync(items, null, CancellationToken.None); | ||
| return WorkerAsync(items, progress: null, CancellationToken.None); | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -44,9 +44,9 @@ public IAsyncEnumerable<string> TransformAsync | |
| CancellationToken token | ||
| ) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(items, nameof(items)); | ||
| ArgumentNullException.ThrowIfNull(items); | ||
|
|
||
| return WorkerAsync(items, null, token); | ||
| return WorkerAsync(items, progress: null, token); | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -57,8 +57,8 @@ public IAsyncEnumerable<string> TransformAsync | |
| IProgress<EtlProgress> progress | ||
| ) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(items, nameof(items)); | ||
| ArgumentNullException.ThrowIfNull(progress, nameof(progress)); | ||
| ArgumentNullException.ThrowIfNull(items); | ||
| ArgumentNullException.ThrowIfNull(progress); | ||
|
|
||
| return WorkerAsync(items, progress, CancellationToken.None); | ||
| } | ||
|
|
@@ -72,8 +72,8 @@ public IAsyncEnumerable<string> TransformAsync | |
| CancellationToken token | ||
| ) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(items, nameof(items)); | ||
| ArgumentNullException.ThrowIfNull(progress, nameof(progress)); | ||
| ArgumentNullException.ThrowIfNull(items); | ||
| ArgumentNullException.ThrowIfNull(progress); | ||
|
|
||
| return WorkerAsync(items, progress, token); | ||
|
|
||
|
|
@@ -88,18 +88,18 @@ private async IAsyncEnumerable<string> WorkerAsync | |
| [EnumeratorCancellation] CancellationToken token | ||
| ) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(items, nameof(items)); | ||
| ArgumentNullException.ThrowIfNull(items); | ||
|
|
||
| Console.WriteLine($"{ConsoleColors.Green}Transforming{ConsoleColors.Reset} integers to strings asynchronously...\n"); | ||
|
|
||
| var count = 0; | ||
| await using var timer = new Timer | ||
| ( | ||
| _ => progress?.Report(new EtlProgress(Volatile.Read(ref count))), | ||
| null, | ||
| state: null, | ||
| TimeSpan.Zero, | ||
| TimeSpan.FromMilliseconds(_progressInterval) // Use the configured progress interval | ||
| ); | ||
| ).ConfigureAwait(false); | ||
|
Comment on lines
98
to
+102
|
||
|
|
||
|
|
||
| await foreach (var item in items.WithCancellation(token)) | ||
|
|
@@ -115,7 +115,7 @@ [EnumeratorCancellation] CancellationToken token | |
| } | ||
|
|
||
| Console.WriteLine($"Transforming integer {item} to string."); | ||
| await Task.Delay(50); // Simulate some delay for transformation | ||
| await Task.Delay(50, CancellationToken.None).ConfigureAwait(false); // Simulate some delay for transformation | ||
| yield return item.ToString(); | ||
|
Comment on lines
117
to
119
|
||
| count = Interlocked.Increment(ref count); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| namespace Example6_ReducingDuplicateCode | ||
| { | ||
| internal record EtlProgress(int CurrentCount); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ public abstract class ExtractorBase<TSource, TProgress> | |
| /// <summary> | ||
| /// The number of milliseconds between progress updates. | ||
| /// </summary> | ||
| /// <exception cref="ArgumentException">Value cannot be less than 1</exception> | ||
| /// <exception cref="ArgumentOutOfRangeException">Value cannot be less than 1</exception> | ||
| public int ReportingInterval | ||
| { | ||
| get => _reportingInterval; | ||
|
|
@@ -50,7 +50,7 @@ public int ReportingInterval | |
| /// It is the responsibility of the derived class to keep this value up to date as the | ||
| /// base class will have no way of knowing the correct value | ||
| /// </remarks> | ||
|
|
||
| /// <exception cref="ArgumentOutOfRangeException">Value cannot be less than 0</exception> | ||
| [Range(0, int.MaxValue, ErrorMessage = "Current item count cannot be less than 0.")] | ||
| public int CurrentItemCount | ||
| { | ||
|
|
@@ -70,6 +70,7 @@ protected set | |
| /// <summary> | ||
| /// Gets the current number of records skipped | ||
| /// </summary> | ||
| /// <exception cref="ArgumentOutOfRangeException">Value cannot be less than 0</exception> | ||
| public int CurrentSkippedItemCount | ||
| { | ||
| get => _currentSkippedItemCount; | ||
|
|
@@ -92,7 +93,7 @@ protected set | |
| /// This is useful for partially extracting data from a source, especially when the source is large | ||
| /// or infinite or during development. | ||
| /// </remarks> | ||
| /// <exception cref="ArgumentException">The specified value is less than 0</exception> | ||
| /// <exception cref="ArgumentOutOfRangeException">The specified value is less than 0</exception> | ||
| /// <example> | ||
| /// <code> | ||
| /// var count = 0; | ||
|
|
@@ -136,7 +137,7 @@ public int MaximumItemCount | |
| /// This is useful for partially extracting data from a source during development, or to skip | ||
| /// items that were already processed or are not relevant for the current extraction. | ||
| /// </remarks> | ||
| /// <exception cref="ArgumentException">The specified value is less than 0</exception> | ||
| /// <exception cref="ArgumentOutOfRangeException">The specified value is less than 0</exception> | ||
| /// <example> | ||
| /// <code> | ||
| /// using (var reader = new StreamReader(filePath)) | ||
|
|
@@ -231,7 +232,7 @@ public virtual IAsyncEnumerable<TSource> ExtractAsync(IProgress<TProgress> progr | |
| using var timer = new Timer | ||
| ( | ||
| _ => progress.Report(CreateProgressReport()), | ||
| null, | ||
| state: null, | ||
| TimeSpan.Zero, | ||
| TimeSpan.FromMilliseconds(ReportingInterval) | ||
| ); | ||
|
Comment on lines
232
to
238
|
||
|
|
@@ -265,7 +266,7 @@ public virtual IAsyncEnumerable<TSource> ExtractAsync(IProgress<TProgress> progr | |
| using var timer = new Timer | ||
| ( | ||
| _ => progress.Report(CreateProgressReport()), | ||
| null, | ||
| state: null, | ||
| TimeSpan.Zero, | ||
|
|
||
| TimeSpan.FromMilliseconds(ReportingInterval) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
System.Threading.TimerisIDisposableand the constructor doesn’t return a task, soawait usingand.ConfigureAwait(false)on the timer creation won’t compile. Use a normalusing var(orPeriodicTimer) and keep it within the async method scope so it’s disposed after the load completes.