From 12fa2e642f48c5b4acfda6a7d39db016bbc96131 Mon Sep 17 00:00:00 2001 From: Lars Weber Date: Mon, 28 Oct 2024 11:37:28 +0100 Subject: [PATCH] Address feedback --- .../Client/Managed/Version10/GdsBlob.cs | 20 ++++++++----------- .../Client/Native/FesBlob.cs | 4 ++-- .../Common/BlobBase.cs | 12 +++-------- .../Common/BlobStream.cs | 11 +++------- 4 files changed, 16 insertions(+), 31 deletions(-) diff --git a/src/FirebirdSql.Data.FirebirdClient/Client/Managed/Version10/GdsBlob.cs b/src/FirebirdSql.Data.FirebirdClient/Client/Managed/Version10/GdsBlob.cs index b98c4c850..8436eeced 100644 --- a/src/FirebirdSql.Data.FirebirdClient/Client/Managed/Version10/GdsBlob.cs +++ b/src/FirebirdSql.Data.FirebirdClient/Client/Managed/Version10/GdsBlob.cs @@ -21,10 +21,6 @@ using System.Threading.Tasks; using FirebirdSql.Data.Common; -#if !(NET48 || NETSTANDARD2_0) -using System.Buffers; -#endif - namespace FirebirdSql.Data.Client.Managed.Version10; internal sealed class GdsBlob : BlobBase @@ -134,7 +130,7 @@ public override int GetLength() _database.Xdr.Write(IscCodes.op_info_blob); _database.Xdr.Write(_blobHandle); _database.Xdr.Write(0); - _database.Xdr.WriteBuffer(new byte[]{ IscCodes.isc_info_blob_total_length }, 1); + _database.Xdr.WriteBuffer(new byte[] { IscCodes.isc_info_blob_total_length }, 1); _database.Xdr.Write(bufferLength); _database.Xdr.Flush(); @@ -174,7 +170,7 @@ public override async ValueTask GetLengthAsync(CancellationToken cancellati await _database.Xdr.WriteAsync(IscCodes.op_info_blob, cancellationToken).ConfigureAwait(false); await _database.Xdr.WriteAsync(_blobHandle, cancellationToken).ConfigureAwait(false); await _database.Xdr.WriteAsync(0, cancellationToken).ConfigureAwait(false); - await _database.Xdr.WriteBufferAsync(new byte[]{ IscCodes.isc_info_blob_total_length }, 1, cancellationToken).ConfigureAwait(false); + await _database.Xdr.WriteBufferAsync(new byte[] { IscCodes.isc_info_blob_total_length }, 1, cancellationToken).ConfigureAwait(false); await _database.Xdr.WriteAsync(bufferLength, cancellationToken).ConfigureAwait(false); await _database.Xdr.FlushAsync(cancellationToken).ConfigureAwait(false); @@ -278,7 +274,7 @@ public override async ValueTask GetSegmentAsync(Stream stream, CancellationToken if (buffer.Length == 0) { - // previous segment was last, this has no data + //previous segment was last, this has no data return; } @@ -328,7 +324,7 @@ public override byte[] GetSegment() if (buffer.Length == 0) { - // previous segment was last, this has no data + //previous segment was last, this has no data return Array.Empty(); } @@ -446,13 +442,13 @@ public override async ValueTask PutSegmentAsync(byte[] buffer, CancellationToken } } - public override void Seek(int offset, int fbSeekMode) + public override void Seek(int offset, int seekMode) { try { _database.Xdr.Write(IscCodes.op_seek_blob); _database.Xdr.Write(_blobHandle); - _database.Xdr.Write(fbSeekMode); + _database.Xdr.Write(seekMode); _database.Xdr.Write(offset); _database.Xdr.Flush(); @@ -465,13 +461,13 @@ public override void Seek(int offset, int fbSeekMode) throw IscException.ForIOException(ex); } } - public override async ValueTask SeekAsync(int offset, int fbSeekMode, CancellationToken cancellationToken = default) + public override async ValueTask SeekAsync(int offset, int seekMode, CancellationToken cancellationToken = default) { try { await _database.Xdr.WriteAsync(IscCodes.op_seek_blob, cancellationToken).ConfigureAwait(false); await _database.Xdr.WriteAsync(_blobHandle, cancellationToken).ConfigureAwait(false); - await _database.Xdr.WriteAsync(fbSeekMode, cancellationToken).ConfigureAwait(false); + await _database.Xdr.WriteAsync(seekMode, cancellationToken).ConfigureAwait(false); await _database.Xdr.WriteAsync(offset, cancellationToken).ConfigureAwait(false); await _database.Xdr.FlushAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/FirebirdSql.Data.FirebirdClient/Client/Native/FesBlob.cs b/src/FirebirdSql.Data.FirebirdClient/Client/Native/FesBlob.cs index b77c91e6a..6394963f5 100644 --- a/src/FirebirdSql.Data.FirebirdClient/Client/Native/FesBlob.cs +++ b/src/FirebirdSql.Data.FirebirdClient/Client/Native/FesBlob.cs @@ -170,7 +170,7 @@ public override int GetLength() _statusVector, ref _blobHandle, 1, - new byte[]{IscCodes.isc_info_blob_total_length}, + new byte[] { IscCodes.isc_info_blob_total_length }, (short)buffer.Length, buffer); @@ -192,7 +192,7 @@ public override ValueTask GetLengthAsync(CancellationToken cancellationToke _statusVector, ref _blobHandle, 1, - new byte[]{IscCodes.isc_info_blob_total_length}, + new byte[] { IscCodes.isc_info_blob_total_length }, (short)buffer.Length, buffer); diff --git a/src/FirebirdSql.Data.FirebirdClient/Common/BlobBase.cs b/src/FirebirdSql.Data.FirebirdClient/Common/BlobBase.cs index 375930fa8..7214d5e8c 100644 --- a/src/FirebirdSql.Data.FirebirdClient/Common/BlobBase.cs +++ b/src/FirebirdSql.Data.FirebirdClient/Common/BlobBase.cs @@ -54,7 +54,6 @@ public string ReadString() var buffer = Read(); return _charset.GetString(buffer, 0, buffer.Length); } - public async ValueTask ReadStringAsync(CancellationToken cancellationToken = default) { var buffer = await ReadAsync(cancellationToken).ConfigureAwait(false); @@ -87,7 +86,6 @@ public byte[] Read() return ms.ToArray(); } } - public async ValueTask ReadAsync(CancellationToken cancellationToken = default) { using (var ms = new MemoryStream()) @@ -119,7 +117,6 @@ public void Write(string data) { Write(_charset.GetBytes(data)); } - public ValueTask WriteAsync(string data, CancellationToken cancellationToken = default) { return WriteAsync(_charset.GetBytes(data), cancellationToken); @@ -129,7 +126,6 @@ public void Write(byte[] buffer) { Write(buffer, 0, buffer.Length); } - public ValueTask WriteAsync(byte[] buffer, CancellationToken cancellationToken = default) { return WriteAsync(buffer, 0, buffer.Length, cancellationToken); @@ -172,9 +168,7 @@ public void Write(byte[] buffer, int index, int count) throw; } } - - public async ValueTask WriteAsync(byte[] buffer, int index, int count, - CancellationToken cancellationToken = default) + public async ValueTask WriteAsync(byte[] buffer, int index, int count, CancellationToken cancellationToken = default) { try { @@ -230,8 +224,8 @@ public async ValueTask WriteAsync(byte[] buffer, int index, int count, public abstract void PutSegment(byte[] buffer); public abstract ValueTask PutSegmentAsync(byte[] buffer, CancellationToken cancellationToken = default); - public abstract void Seek(int offset, int fbSeekMode); - public abstract ValueTask SeekAsync(int offset, int fbSeekMode, CancellationToken cancellationToken = default); + public abstract void Seek(int offset, int seekMode); + public abstract ValueTask SeekAsync(int offset, int seekMode, CancellationToken cancellationToken = default); public abstract void Close(); public abstract ValueTask CloseAsync(CancellationToken cancellationToken = default); diff --git a/src/FirebirdSql.Data.FirebirdClient/Common/BlobStream.cs b/src/FirebirdSql.Data.FirebirdClient/Common/BlobStream.cs index 5796faa3f..04f9a7e87 100644 --- a/src/FirebirdSql.Data.FirebirdClient/Common/BlobStream.cs +++ b/src/FirebirdSql.Data.FirebirdClient/Common/BlobStream.cs @@ -69,7 +69,6 @@ public override int Read(byte[] buffer, int offset, int count) return copied; } - public override async Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { @@ -113,7 +112,7 @@ public override long Seek(long offset, SeekOrigin origin) if (!_blobHandle.IsOpen) _blobHandle.Open(); - var fbSeekMode = origin switch + var seekMode = origin switch { SeekOrigin.Begin => IscCodes.isc_blb_seek_from_head, SeekOrigin.Current => IscCodes.isc_blb_seek_relative, @@ -121,7 +120,7 @@ public override long Seek(long offset, SeekOrigin origin) _ => throw new ArgumentOutOfRangeException(nameof(origin)) }; - _blobHandle.Seek((int)offset, fbSeekMode); + _blobHandle.Seek((int)offset, seekMode); return _position = _blobHandle.Position; } @@ -158,15 +157,12 @@ public override void Write(byte[] buffer, int offset, int count) } catch { - // Cancel the blob and rethrow the exception _blobHandle.Cancel(); throw; } } - - public override async Task WriteAsync(byte[] buffer, int offset, int count, - CancellationToken cancellationToken) + public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { try { @@ -194,7 +190,6 @@ public override async Task WriteAsync(byte[] buffer, int offset, int count, } catch { - // Cancel the blob and rethrow the exception await _blobHandle.CancelAsync(cancellationToken).ConfigureAwait(false); throw;