Added async read/write/flush methods to IStream

This commit is contained in:
Chris Bush 2017-02-16 05:54:44 -05:00
Родитель 353c5cd4f9
Коммит 47f6b07c23
5 изменённых файлов: 296 добавлений и 3 удалений

Просмотреть файл

@ -22,9 +22,31 @@
</ToolsOptionsCategory>
<ToolsOptionsCategory name="TextEditor">
<ToolsOptionsSubCategory name="CSharp">
<PropertyValue name="AutoListMembers">true</PropertyValue>
<PropertyValue name="AutoListParams">true</PropertyValue>
<PropertyValue name="BraceCompletion">true</PropertyValue>
<PropertyValue name="CutCopyBlankLines">true</PropertyValue>
<PropertyValue name="EnableLeftClickForURLs">true</PropertyValue>
<PropertyValue name="HideAdvancedMembers">true</PropertyValue>
<PropertyValue name="IndentSize">4</PropertyValue>
<PropertyValue name="IndentStyle">2</PropertyValue>
<PropertyValue name="InsertTabs">false</PropertyValue>
<PropertyValue name="OverviewWidth">58</PropertyValue>
<PropertyValue name="ShowAnnotations">true</PropertyValue>
<PropertyValue name="ShowCaretPosition">true</PropertyValue>
<PropertyValue name="ShowChanges">true</PropertyValue>
<PropertyValue name="ShowErrors">true</PropertyValue>
<PropertyValue name="ShowHorizontalScrollBar">true</PropertyValue>
<PropertyValue name="ShowLineNumbers">true</PropertyValue>
<PropertyValue name="ShowMarks">true</PropertyValue>
<PropertyValue name="ShowNavigationBar">true</PropertyValue>
<PropertyValue name="ShowPreview">true</PropertyValue>
<PropertyValue name="ShowVerticalScrollBar">true</PropertyValue>
<PropertyValue name="TabSize">4</PropertyValue>
<PropertyValue name="UseMapMode">false</PropertyValue>
<PropertyValue name="VirtualSpace">false</PropertyValue>
<PropertyValue name="WordWrap">false</PropertyValue>
<PropertyValue name="WordWrapGlyphs">true</PropertyValue>
</ToolsOptionsSubCategory>
<ToolsOptionsSubCategory name="CSharp-Specific">
<PropertyValue name="AddImport_SuggestForTypesInNuGetPackages">0</PropertyValue>

Просмотреть файл

@ -1,6 +1,8 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
namespace SystemInterface.IO
{
@ -101,6 +103,20 @@ namespace SystemInterface.IO
/// </summary>
void Flush();
//
// Summary:
// Asynchronously clears all buffers for this stream and causes any buffered data
// to be written to the underlying device.
//
// Returns:
// A task that represents the asynchronous flush operation.
//
// Exceptions:
// T:System.ObjectDisposedException:
// The stream has been disposed.
[ComVisible(false)]
Task FlushAsync();
/// <summary>
/// When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
/// </summary>
@ -110,6 +126,96 @@ namespace SystemInterface.IO
/// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached. </returns>
int Read([In, Out] byte[] buffer, int offset, int count);
//
// Summary:
// Asynchronously reads a sequence of bytes from the current stream and advances
// the position within the stream by the number of bytes read.
//
// Parameters:
// buffer:
// The buffer to write the data into.
//
// offset:
// The byte offset in buffer at which to begin writing data from the stream.
//
// count:
// The maximum number of bytes to read.
//
// Returns:
// A task that represents the asynchronous read operation. The value of the TResult
// parameter contains the total number of bytes read into the buffer. The result
// value can be less than the number of bytes requested if the number of bytes currently
// available is less than the requested number, or it can be 0 (zero) if the end
// of the stream has been reached.
//
// Exceptions:
// T:System.ArgumentNullException:
// buffer is null.
//
// T:System.ArgumentOutOfRangeException:
// offset or count is negative.
//
// T:System.ArgumentException:
// The sum of offset and count is larger than the buffer length.
//
// T:System.NotSupportedException:
// The stream does not support reading.
//
// T:System.ObjectDisposedException:
// The stream has been disposed.
//
// T:System.InvalidOperationException:
// The stream is currently in use by a previous read operation.
[ComVisible(false)]
Task<int> ReadAsync(byte[] buffer, int offset, int count);
//
// Summary:
// Asynchronously reads a sequence of bytes from the current stream, advances the
// position within the stream by the number of bytes read, and monitors cancellation
// requests.
//
// Parameters:
// buffer:
// The buffer to write the data into.
//
// offset:
// The byte offset in buffer at which to begin writing data from the stream.
//
// count:
// The maximum number of bytes to read.
//
// cancellationToken:
// The token to monitor for cancellation requests. The default value is System.Threading.CancellationToken.None.
//
// Returns:
// A task that represents the asynchronous read operation. The value of the TResult
// parameter contains the total number of bytes read into the buffer. The result
// value can be less than the number of bytes requested if the number of bytes currently
// available is less than the requested number, or it can be 0 (zero) if the end
// of the stream has been reached.
//
// Exceptions:
// T:System.ArgumentNullException:
// buffer is null.
//
// T:System.ArgumentOutOfRangeException:
// offset or count is negative.
//
// T:System.ArgumentException:
// The sum of offset and count is larger than the buffer length.
//
// T:System.NotSupportedException:
// The stream does not support reading.
//
// T:System.ObjectDisposedException:
// The stream has been disposed.
//
// T:System.InvalidOperationException:
// The stream is currently in use by a previous read operation.
[ComVisible(false)]
Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken);
/// <summary>
/// Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.
/// </summary>
@ -145,6 +251,91 @@ namespace SystemInterface.IO
/// <param name="count">The number of bytes to be written to the current stream. </param>
void Write(byte[] buffer, int offset, int count);
//
// Summary:
// Asynchronously writes a sequence of bytes to the current stream and advances
// the current position within this stream by the number of bytes written.
//
// Parameters:
// buffer:
// The buffer to write data from.
//
// offset:
// The zero-based byte offset in buffer from which to begin copying bytes to the
// stream.
//
// count:
// The maximum number of bytes to write.
//
// Returns:
// A task that represents the asynchronous write operation.
//
// Exceptions:
// T:System.ArgumentNullException:
// buffer is null.
//
// T:System.ArgumentOutOfRangeException:
// offset or count is negative.
//
// T:System.ArgumentException:
// The sum of offset and count is larger than the buffer length.
//
// T:System.NotSupportedException:
// The stream does not support writing.
//
// T:System.ObjectDisposedException:
// The stream has been disposed.
//
// T:System.InvalidOperationException:
// The stream is currently in use by a previous write operation.
[ComVisible(false)]
Task WriteAsync(byte[] buffer, int offset, int count);
//
// Summary:
// Asynchronously writes a sequence of bytes to the current stream, advances the
// current position within this stream by the number of bytes written, and monitors
// cancellation requests.
//
// Parameters:
// buffer:
// The buffer to write data from.
//
// offset:
// The zero-based byte offset in buffer from which to begin copying bytes to the
// stream.
//
// count:
// The maximum number of bytes to write.
//
// cancellationToken:
// The token to monitor for cancellation requests. The default value is System.Threading.CancellationToken.None.
//
// Returns:
// A task that represents the asynchronous write operation.
//
// Exceptions:
// T:System.ArgumentNullException:
// buffer is null.
//
// T:System.ArgumentOutOfRangeException:
// offset or count is negative.
//
// T:System.ArgumentException:
// The sum of offset and count is larger than the buffer length.
//
// T:System.NotSupportedException:
// The stream does not support writing.
//
// T:System.ObjectDisposedException:
// The stream has been disposed.
//
// T:System.InvalidOperationException:
// The stream is currently in use by a previous write operation.
[ComVisible(false)]
Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken);
/// <summary>
/// Writes a byte to the current position in the stream and advances the position within the stream by one byte.
/// </summary>

Просмотреть файл

@ -3,6 +3,8 @@ using System.IO;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Security.Permissions;
using System.Threading;
using System.Threading.Tasks;
using SystemInterface.IO;
using SystemInterface.Microsoft.Win32.SafeHandles;
using SystemInterface.Security.AccessControl;
@ -604,5 +606,30 @@ namespace SystemWrapper.IO
fileStreamWraps[i] = new FileStreamWrap(fileStreams[i]);
return fileStreamWraps;
}
public async Task FlushAsync()
{
await FileStreamInstance.FlushAsync();
}
public async Task<int> ReadAsync(byte[] buffer, int offset, int count)
{
return await FileStreamInstance.ReadAsync(buffer, offset, count);
}
public async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
return await FileStreamInstance.ReadAsync(buffer, offset, count, cancellationToken);
}
public async Task WriteAsync(byte[] buffer, int offset, int count)
{
await FileStreamInstance.WriteAsync(buffer, offset, count);
}
public async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
await FileStreamInstance.WriteAsync(buffer, offset, count, cancellationToken);
}
}
}
}

Просмотреть файл

@ -2,6 +2,8 @@ using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Threading;
using System.Threading.Tasks;
using SystemInterface.IO;
namespace SystemWrapper.IO
@ -407,5 +409,30 @@ namespace SystemWrapper.IO
{
MemoryStreamInstance.Dispose();
}
public async Task FlushAsync()
{
await MemoryStreamInstance.FlushAsync();
}
public async Task<int> ReadAsync(byte[] buffer, int offset, int count)
{
return await MemoryStreamInstance.ReadAsync(buffer, offset, count);
}
public async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
return await MemoryStreamInstance.ReadAsync(buffer, offset, count, cancellationToken);
}
public async Task WriteAsync(byte[] buffer, int offset, int count)
{
await MemoryStreamInstance.WriteAsync(buffer, offset, count);
}
public async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
await MemoryStreamInstance.WriteAsync(buffer, offset, count, cancellationToken);
}
}
}

Просмотреть файл

@ -2,7 +2,8 @@
{
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using SystemInterface.IO;
/// <summary>
@ -249,6 +250,11 @@
this.StreamInstance.Flush();
}
public async Task FlushAsync()
{
await StreamInstance.FlushAsync();
}
/// <summary>
/// When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the
/// number of bytes read.
@ -274,6 +280,16 @@
return this.StreamInstance.Read(buffer, offset, count);
}
public async Task<int> ReadAsync(byte[] buffer, int offset, int count)
{
return await StreamInstance.ReadAsync(buffer, offset, count);
}
public async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
return await StreamInstance.ReadAsync(buffer, offset, count, cancellationToken);
}
/// <summary>
/// Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.
/// </summary>
@ -348,6 +364,16 @@
this.StreamInstance.Write(buffer, offset, count);
}
public async Task WriteAsync(byte[] buffer, int offset, int count)
{
await StreamInstance.WriteAsync(buffer, offset, count);
}
public async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
await StreamInstance.WriteAsync(buffer, offset, count, cancellationToken);
}
/// <summary>
/// Writes a byte to the current position in the stream and advances the position within the stream by one byte.
/// </summary>
@ -361,4 +387,4 @@
#endregion
}
}
}