Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.46k stars 4.8k forks source link

Microsoft.Azure.Storage.Core.StorageCommandAsyncResult migration guidance [Core] #33466

Open OzBob opened 1 year ago

OzBob commented 1 year ago

API Change Needed

Yes

Background and motivation

Upgrading from Microsoft.Azure.Storage.Blob.UploadFromByteArrayAsync to Microsoft.Azure.WebJobs.Extensions.Storage.Blobs should be possible with a replacement for Microsoft.Azure.Storage.Core.SyncMemoryStream in the new hotness of 'Azure.Storage.Blobs'.

Forking the repo to get the source is not a simple solution, as there is a dependency on 'StorageAsyncResult'->StorageCommandAsyncResult->CancellableOperationBase. Is there a replacement?

Add migration docs mapping the complete deprecated API map to Azure.Storage.Common

Document a timeline for parity.

API / Feature Proposal

//https://github.com/Azure/azure-storage-net/blob/master/Lib/Common/Core/SyncMemoryStream.cs
namespace Azure.Core
{

    public class SyncMemoryStream : MemoryStream
    { 
        /// <summary>
        /// Initializes a new instance of the SyncMemoryStream class with an expandable capacity initialized to zero.
        /// </summary>
        public SyncMemoryStream()base(){}

        /// <summary>
        /// Begins an asynchronous read operation.
        /// </summary>
        /// <param name="buffer">When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.</param>
        /// <param name="offset">The zero-based byte offset in buffer at which to begin storing the data read from the current stream.</param>
        /// <param name="count">The maximum number of bytes to be read.</param>
        /// <param name="callback">An optional asynchronous callback, to be called when the read is complete.</param>
        /// <param name="state">A user-provided object that distinguishes this particular asynchronous read request from other requests.</param>
        /// <returns>An IAsyncResult that represents the asynchronous read, which could still be pending.</returns>
        [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Needed to ensure exceptions are not thrown on threadpool threads.")]
        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            CommonUtility.AssertNotNull("buffer", buffer);
            CommonUtility.AssertInBounds("offset", offset, 0, buffer.Length);
            CommonUtility.AssertInBounds("count", count, 0, buffer.Length - offset);

            StorageAsyncResult<int> result = new StorageAsyncResult<int>(callback, state);

            try
            {
                result.Result = this.Read(buffer, offset, count);
                result.OnComplete();
            }
            catch (Exception e)
            {
                result.OnComplete(e);
            }

            return result;
        }

        /// <summary>
        /// Waits for the pending asynchronous read to complete.
        /// </summary>
        /// <param name="asyncResult">The reference to the pending asynchronous request to finish.</param>
        /// <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 if the end of the stream has been reached.</returns>
        public override int EndRead(IAsyncResult asyncResult)
        {
            StorageAsyncResult<int> result = (StorageAsyncResult<int>)asyncResult;
            result.End();
            return result.Result;
        }
    }
}

Time Constraints and Dependencies

Microsoft.Azure.Storage.Core.Util.StorageCommandAsyncResult <- Microsoft.Azure.Storage.Core.Util.StorageAsyncResult <- Microsoft.Azure.Storage.Core.Executor.ExecutionState

Stakeholders

No response

ghost commented 1 year ago

Thank you for your feedback. This has been routed to the support team for assistance.

ghost commented 1 year ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.

Issue Details
### API Change Needed Yes ### Background and motivation Upgrading from Microsoft.Azure.Storage.Blob.UploadFromByteArrayAsync to Microsoft.Azure.WebJobs.Extensions.Storage.Blobs should be possible with a replacement for Microsoft.Azure.Storage.Core.SyncMemoryStream in the new hotness of '[Azure.Storage.Blobs](https://www.nuget.org/packages/Azure.Storage.Blobs/#readme-body-tab)'. Forking the repo to get the source is not a simple solution, as there is a dependency on 'StorageAsyncResult'->StorageCommandAsyncResult->CancellableOperationBase. Is there a replacement? Add migration docs mapping the complete [deprecated](https://www.nuget.org/packages/Microsoft.Azure.Storage.Blob) API map to [Azure.Storage.Common](https://github.com/Azure/azure-sdk-for-net) Document a timeline for parity. ### API / Feature Proposal ```C# //https://github.com/Azure/azure-storage-net/blob/master/Lib/Common/Core/SyncMemoryStream.cs namespace Azure.Core { public class SyncMemoryStream : MemoryStream { /// /// Initializes a new instance of the SyncMemoryStream class with an expandable capacity initialized to zero. /// public SyncMemoryStream()base(){} /// /// Begins an asynchronous read operation. /// /// When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source. /// The zero-based byte offset in buffer at which to begin storing the data read from the current stream. /// The maximum number of bytes to be read. /// An optional asynchronous callback, to be called when the read is complete. /// A user-provided object that distinguishes this particular asynchronous read request from other requests. /// An IAsyncResult that represents the asynchronous read, which could still be pending. [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Needed to ensure exceptions are not thrown on threadpool threads.")] public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { CommonUtility.AssertNotNull("buffer", buffer); CommonUtility.AssertInBounds("offset", offset, 0, buffer.Length); CommonUtility.AssertInBounds("count", count, 0, buffer.Length - offset); StorageAsyncResult result = new StorageAsyncResult(callback, state); try { result.Result = this.Read(buffer, offset, count); result.OnComplete(); } catch (Exception e) { result.OnComplete(e); } return result; } /// /// Waits for the pending asynchronous read to complete. /// /// The reference to the pending asynchronous request to finish. /// 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 if the end of the stream has been reached. public override int EndRead(IAsyncResult asyncResult) { StorageAsyncResult result = (StorageAsyncResult)asyncResult; result.End(); return result.Result; } } } ``` ### Time Constraints and Dependencies Microsoft.Azure.Storage.Core.Util.StorageCommandAsyncResult <- Microsoft.Azure.Storage.Core.Util.StorageAsyncResult <- Microsoft.Azure.Storage.Core.Executor.ExecutionState ### Stakeholders _No response_
Author: OzBob
Assignees: -
Labels: `Storage`, `Service Attention`, `Client`, `customer-reported`, `feature-request`, `Docs`, `needs-team-attention`
Milestone: -
navba-MSFT commented 1 year ago

@xgithubtriage Could you please look into this once you get a chance ?