Skip to content

Commit a2ec820

Browse files
authored
.Net Core 3.0 support (#19)
.Net Core 3.0 support +semver: feature
2 parents c5904b6 + dbd2046 commit a2ec820

File tree

7 files changed

+137
-33
lines changed

7 files changed

+137
-33
lines changed

FollowingFileStream.APIdoc/docfx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"disableGitFeatures": false,
1818
"disableDefaultFilter": false,
1919
"properties": {
20-
"TargetFramework": "netstandard2.0"
20+
"TargetFramework": "netstandard2.1"
2121
}
2222
}
2323
],

FollowingFileStream.ConsoleTestTool/FollowingFileStream.ConsoleTestTool.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<PropertyGroup>
88
<OutputType>Exe</OutputType>
9-
<TargetFramework>netcoreapp2.2</TargetFramework>
9+
<TargetFrameworks>netcoreapp3.0;netcoreapp2.2</TargetFrameworks>
1010
<LangVersion>7.1</LangVersion>
1111
<IsPackable>false</IsPackable>
1212
</PropertyGroup>

FollowingFileStream.Tests/FollowingFileStream.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp2.2</TargetFramework>
3+
<TargetFrameworks>netcoreapp3.0;netcoreapp2.2</TargetFrameworks>
44
<IsPackable>false</IsPackable>
55
</PropertyGroup>
66
<ItemGroup>

FollowingFileStream/AsyncStream.cs

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Manandre.IO
99
/// <summary>
1010
///
1111
/// </summary>
12+
#pragma warning disable S3881
1213
public abstract class AsyncStream : Stream
1314
{
1415
#if !NETSTANDARD1_3
@@ -286,8 +287,28 @@ public sealed override void Write(byte[] buffer, int offset, int count)
286287
/// </exception>
287288
public abstract override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken);
288289

289-
private bool disposed = false;
290+
#if NETSTANDARD2_1
291+
/// <summary>
292+
/// Asynchronously releases the unmanaged resources used by the FollowingFileStream and optionally
293+
/// releases the managed resources.
294+
/// </summary>
295+
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.
296+
///</param>
297+
protected virtual ValueTask DisposeAsync(bool disposing) => default;
298+
299+
/// <summary>
300+
/// Asynchronously releases all resources used by the AsyncStream.
301+
/// </summary>
302+
public sealed override ValueTask DisposeAsync() => DisposeAsync(true);
290303

304+
/// <summary>
305+
/// Releases the unmanaged resources used by the FollowingFileStream and optionally
306+
/// releases the managed resources.
307+
/// </summary>
308+
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.
309+
///</param>
310+
protected sealed override void Dispose(bool disposing) => DisposeAsync(disposing).GetAwaiter().GetResult();
311+
#else
291312
/// <summary>
292313
/// Releases the unmanaged resources used by the FollowingFileStream and optionally
293314
/// releases the managed resources.
@@ -296,14 +317,10 @@ public sealed override void Write(byte[] buffer, int offset, int count)
296317
///</param>
297318
protected override void Dispose(bool disposing)
298319
{
299-
if (disposed)
300-
return;
301-
302-
disposed = true;
303320
// Call stream class implementation.
304321
base.Dispose(disposing);
305322
}
306-
323+
#endif
307324
/// <summary>
308325
/// Synchronized version of an async stream
309326
/// </summary>
@@ -400,26 +417,6 @@ public override int WriteTimeout
400417
}
401418
}
402419

403-
protected override void Dispose(bool disposing)
404-
{
405-
try
406-
{
407-
// Explicitly pick up a potentially methodimpl'ed Dispose
408-
if (disposing)
409-
{
410-
cts.Cancel();
411-
using (locker.Lock())
412-
{
413-
((IDisposable)_stream).Dispose();
414-
}
415-
}
416-
}
417-
finally
418-
{
419-
base.Dispose(disposing);
420-
}
421-
}
422-
423420
public override long Seek(long offset, SeekOrigin origin)
424421
{
425422
using (locker.Lock(cts.Token))
@@ -481,9 +478,64 @@ public override async Task FlushAsync(CancellationToken cancellationToken)
481478
cancellationToken.ThrowIfCancellationRequested();
482479
}
483480
}
481+
482+
private bool disposed = false;
483+
484+
#if NETSTANDARD2_1
485+
protected override async ValueTask DisposeAsync(bool disposing)
486+
{
487+
if (disposed)
488+
return;
489+
490+
try
491+
{
492+
// Explicitly pick up a potentially methodimpl'ed DisposeAsync
493+
if (disposing)
494+
{
495+
cts.Cancel();
496+
using (await locker.LockAsync())
497+
{
498+
await ((IAsyncDisposable)_stream).DisposeAsync();
499+
}
500+
}
501+
}
502+
finally
503+
{
504+
disposed = true;
505+
await base.DisposeAsync(disposing);
506+
}
507+
}
508+
#else
509+
protected override void Dispose(bool disposing)
510+
{
511+
if (disposed)
512+
return;
513+
514+
try
515+
{
516+
// Explicitly pick up a potentially methodimpl'ed Dispose
517+
if (disposing)
518+
{
519+
cts.Cancel();
520+
using (locker.Lock())
521+
{
522+
((IDisposable)_stream).Dispose();
523+
}
524+
525+
}
526+
}
527+
finally
528+
{
529+
disposed = true;
530+
base.Dispose(disposing);
531+
}
532+
}
533+
#endif
484534
}
485535
}
486536

537+
#pragma warning restore S3881
538+
487539
/// <summary>
488540
/// AsyncStream class extensions
489541
/// </summary>

FollowingFileStream/FollowingFileStream.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ public class FollowingFileStream : AsyncStream
6363
/// </exception>
6464
public FollowingFileStream(string path)
6565
{
66+
#pragma warning disable S2930
6667
fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
68+
#pragma warning restore S2930
6769
}
6870

6971
/// <summary>
@@ -120,7 +122,9 @@ public FollowingFileStream(string path)
120122
/// </exception>
121123
public FollowingFileStream(string path, int bufferSize, bool useAsync)
122124
{
125+
#pragma warning disable S2930
123126
fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, bufferSize, useAsync);
127+
#pragma warning restore S2930
124128
}
125129
#endregion
126130

@@ -324,8 +328,36 @@ private bool IsFileLockedForWriting()
324328
return false;
325329
}
326330

327-
bool disposed = false;
331+
private bool disposed = false;
328332

333+
#if NETSTANDARD2_1
334+
/// <summary>
335+
/// Releases the unmanaged resources used by the FollowingFileStream and optionally
336+
/// releases the managed resources.
337+
/// </summary>
338+
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.
339+
///</param>
340+
protected override async ValueTask DisposeAsync(bool disposing)
341+
{
342+
if (disposed)
343+
return;
344+
345+
try
346+
{
347+
if (disposing)
348+
{
349+
cts.Cancel();
350+
await fileStream.DisposeAsync();
351+
}
352+
}
353+
finally
354+
{
355+
disposed = true;
356+
// Call stream class implementation.
357+
base.Dispose(disposing);
358+
}
359+
}
360+
#else
329361
/// <summary>
330362
/// Releases the unmanaged resources used by the FollowingFileStream and optionally
331363
/// releases the managed resources.
@@ -347,7 +379,7 @@ protected override void Dispose(bool disposing)
347379
// Call stream class implementation.
348380
base.Dispose(disposing);
349381
}
350-
382+
#endif
351383
/// <summary>
352384
/// Clears buffers for this stream and causes any buffered data to be written to the file.
353385
/// </summary>

FollowingFileStream/FollowingFileStream.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Library</OutputType>
4-
<TargetFrameworks>netstandard2.0;netstandard1.3</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.1;netstandard2.0;netstandard1.3</TargetFrameworks>
55
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
66
</PropertyGroup>
77
<PropertyGroup>

azure-pipelines.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ jobs:
3636
projectVersion: '$(Build.BuildId)'
3737
extraProperties: 'sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/coverage/coverage.opencover.xml'
3838

39+
- task: UseDotNet@2
40+
displayName: 'Use dotnet sdk 2.x'
41+
inputs:
42+
version: 2.x
43+
44+
- task: UseDotNet@2
45+
displayName: 'Use dotnet sdk 3.x'
46+
inputs:
47+
version: 3.x
48+
3949
- task: DotNetCoreCLI@2
4050
displayName: Restore
4151
inputs:
@@ -158,6 +168,16 @@ jobs:
158168
command: 'install'
159169
installPackageId: 'wkhtmltopdf'
160170

171+
- task: UseDotNet@2
172+
displayName: 'Use dotnet sdk 2.x'
173+
inputs:
174+
version: 2.x
175+
176+
- task: UseDotNet@2
177+
displayName: 'Use dotnet sdk 3.x'
178+
inputs:
179+
version: 3.x
180+
161181
# First restore to resolve external dependencies
162182
- task: DotNetCoreCLI@2
163183
displayName: Restore
@@ -191,4 +211,4 @@ jobs:
191211
inputs:
192212
PathtoPublish: '$(Build.SourcesDirectory)/FollowingFileStream.APIdoc/_site_pdf/FollowingFileStream.APIdoc_pdf.pdf'
193213
ArtifactName: 'apidoc_pdf'
194-
publishLocation: 'Container'
214+
publishLocation: 'Container'

0 commit comments

Comments
 (0)