Ejemplo n.º 1
0
 /// <summary>
 /// Wraps the Read operation to remap any exceptions into IOException.
 /// </summary>
 /// <param name="buffer">The buffer to read the data into.</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 from the current stream.</param>
 /// <param name="setResult">The action to be done upon completion to return the number of bytes read.</param>
 /// <returns>A task sequence representing the operation.</returns>
 /// <exception cref="System.ArgumentException">The sum of offset and count is larger than the buffer length.</exception>
 /// <exception cref="System.ArgumentNullException">The buffer parameter is null.</exception>
 /// <exception cref="System.ArgumentOutOfRangeException">The offset or count parameters are negative</exception>
 /// <exception cref="System.IO.IOException">An I/O error occurs.</exception>
 private TaskSequence ReadImplWrapper(byte[] buffer, int offset, int count, Action <int> setResult)
 {
     StreamUtilities.CheckBufferArguments(buffer, offset, count);
     try
     {
         return(this.ReadImpl(buffer, offset, count, setResult));
     }
     catch (System.Exception ex)
     {
         throw new IOException("Error while reading blob", ex);
     }
 }
        /// <summary>
        /// Begins an asynchronous write operation.
        /// </summary>
        /// <param name="buffer">The buffer to write data from.</param>
        /// <param name="offset">The byte offset in buffer from which to begin writing.</param>
        /// <param name="count">The  number of bytes to write.</param>
        /// <param name="callback">An optional asynchronous callback, to be called when the write is complete.</param>
        /// <param name="state">A user-provided object that distinguishes this particular asynchronous write request from other requests.</param>
        /// <returns>An IAsyncResult that represents the asynchronous write, which could still be pending.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="buffer"/> is null.</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">offset or count is negative.</exception>
        /// <exception cref="System.ObjectDisposedException">Thrown if blob is already committed/closed</exception>
        /// <remarks>The operation will be completed synchronously if the buffer is not filled</remarks>
        public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            this.CheckWriteState();
            StreamUtilities.CheckBufferArguments(buffer, offset, count);

            Task <NullTaskReturn> task = null;

            if (this.UseBlocks)
            {
                task = new InvokeTaskSequenceTask(() =>
                {
                    return(this.WriteBlockBlobImpl(buffer, offset, count));
                });
            }
            else
            {
                task = this.WriteNonBlockedBlobImpl(buffer, offset, count);
            }

            return(task.ToAsyncResult(callback, state));
        }