/// <summary>
 /// Initializes a new instance of the BlobWriteStreamBase class.
 /// </summary>
 /// <param name="accessCondition">An object that represents the access conditions for the blob. If null, no condition is used.</param>
 /// <param name="options">An object that specifies any additional options for the request.</param>
 /// <param name="operationContext">An <see cref="OperationContext"/> object for tracking the current operation.</param>
 private BlobWriteStreamBase(CloudBlobClient serviceClient, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
     : base()
 {
     this.currentOffset = 0;
     this.accessCondition = accessCondition;
     this.options = options;
     this.operationContext = operationContext;
     this.pendingWrites = 0;
     this.noPendingWritesEvent = new ManualResetEvent(true);
     this.blobMD5 = options.StoreBlobContentMD5.Value ? new MD5Wrapper() : null;
     this.blockMD5 = options.UseTransactionalMD5.Value ? new MD5Wrapper() : null;
     this.parallelOperationSemaphore = new AsyncSemaphore(serviceClient.ParallelOperationThreadCount);
     this.lastException = null;
 }
 /// <summary>
 /// Initializes a new instance of the BlobWriteStreamBase class.
 /// </summary>
 /// <param name="serviceClient">The service client.</param>        
 /// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the condition that must be met in order for the request to proceed. If <c>null</c>, no condition is used.</param>
 /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies additional options for the request.</param>
 /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
 private BlobWriteStreamBase(CloudBlobClient serviceClient, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
     : base()
 {
     this.internalBuffer = new MultiBufferMemoryStream(serviceClient.BufferManager);
     this.accessCondition = accessCondition;
     this.currentOffset = 0;
     this.options = options;
     this.operationContext = operationContext;
     this.noPendingWritesEvent = new CounterEvent();
     this.blobMD5 = this.options.StoreBlobContentMD5.Value ? new MD5Wrapper() : null;
     this.blockMD5 = this.options.UseTransactionalMD5.Value ? new MD5Wrapper() : null;
     this.parallelOperationSemaphore = new AsyncSemaphore(options.ParallelOperationThreadCount.Value);
     this.lastException = null;
     this.committed = false;
     this.disposed = false;
 }
 /// <summary>
 /// Initializes a new instance of the FileWriteStreamBase class for a file.
 /// </summary>
 /// <param name="file">File reference to write to.</param>
 /// <param name="fileSize">Size of the file.</param>
 /// <param name="createNew">Use <c>true</c> if the file is newly created, <c>false</c> otherwise.</param>
 /// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the access conditions for the file. If <c>null</c>, no condition is used.</param>
 /// <param name="options">An <see cref="FileRequestOptions"/> object that specifies additional options for the request.</param>
 /// <param name="operationContext">An <see cref="OperationContext"/> object for tracking the current operation.</param>
 protected FileWriteStreamBase(CloudFile file, long fileSize, bool createNew, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext)
     : base()
 {
     this.internalBuffer = new MultiBufferMemoryStream(file.ServiceClient.BufferManager);
     this.currentOffset = 0;
     this.accessCondition = accessCondition;
     this.options = options;
     this.operationContext = operationContext;
     this.noPendingWritesEvent = new CounterEvent();
     this.fileMD5 = this.options.StoreFileContentMD5.Value ? new MD5Wrapper() : null;
     this.rangeMD5 = this.options.UseTransactionalMD5.Value ? new MD5Wrapper() : null;
     this.parallelOperationSemaphore = new AsyncSemaphore(options.ParallelOperationThreadCount.Value);
     this.lastException = null;
     this.committed = false;
     this.disposed = false;
     this.currentFileOffset = 0;
     this.file = file;
     this.fileSize = fileSize;
     this.streamWriteSizeInBytes = file.StreamWriteSizeInBytes;
     this.newFile = createNew;
 }
 /// <summary>
 /// Initializes a new instance of the BlobReadStrea class.
 /// </summary>
 /// <param name="blob">Blob reference to read from</param>
 /// <param name="accessCondition">An object that represents the access conditions for the blob. If null, no condition is used.</param>
 /// <param name="options">An object that specifies any additional options for the request.</param>
 /// <param name="operationContext">An <see cref="OperationContext"/> object for tracking the current operation.</param>
 internal BlobReadStream(ICloudBlob blob, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
     : base(blob, accessCondition, options, operationContext)
 {
     this.parallelOperationSemaphore = new AsyncSemaphore(1);
 }
        /// <summary>
        /// Initializes a new instance of the BlobWriteStreamBase class for an append blob.
        /// </summary>
        /// <param name="appendBlob">Blob reference to write to.</param>
        /// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the condition that must be met in order for the request to proceed. If <c>null</c>, no condition is used.</param>
        /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies additional options for the request.</param>
        /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
        protected BlobWriteStreamBase(CloudAppendBlob appendBlob, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
            : this(appendBlob.ServiceClient, accessCondition, options, operationContext)
        {
            this.accessCondition = this.accessCondition ?? new AccessCondition();

            // If we are creating a new blob, create call would have appropriately set the length to 0. For an existing blob, if user specified a condition with append offset,
            // we will use it. Otherwise, we will use the length returned by the FetchAttributes call.
            this.currentBlobOffset = this.accessCondition.IfAppendPositionEqual.HasValue ? this.accessCondition.IfAppendPositionEqual.Value : appendBlob.Properties.Length;
            this.operationContext = this.operationContext ?? new OperationContext();
            this.appendBlob = appendBlob;
            this.Blob = this.appendBlob;
            this.parallelOperationSemaphore = new AsyncSemaphore(1);
            this.streamWriteSizeInBytes = appendBlob.StreamWriteSizeInBytes;
        }