Exemplo n.º 1
0
        /// <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 CounterEventAsync();
            this.fileChecksum         = new ChecksumWrapper(this.options.ChecksumOptions.StoreContentMD5.Value, this.options.ChecksumOptions.StoreContentCRC64.Value);
            this.rangeChecksum        = new ChecksumWrapper(this.options.ChecksumOptions.UseTransactionalMD5.Value, this.options.ChecksumOptions.UseTransactionalCRC64.Value);
#if !(NETCORE || WINDOWS_RT)
            this.parallelOperationSemaphoreAsync = new AsyncSemaphoreAsync(options.ParallelOperationThreadCount.Value);
#else
            this.parallelOperationSemaphore = new AsyncSemaphore(options.ParallelOperationThreadCount.Value);
#endif
            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 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;
#if WINDOWS_DESKTOP
            this.parallelOperationSemaphoreAsync = new AsyncSemaphoreAsync(1);
#else
            this.parallelOperationSemaphore = new AsyncSemaphore(1);
#endif
            this.streamWriteSizeInBytes = appendBlob.StreamWriteSizeInBytes;
        }
        /// <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;
#if WINDOWS_DESKTOP
            this.parallelOperationSemaphoreAsync = new AsyncSemaphoreAsync(options.ParallelOperationThreadCount.Value);
#else
            this.parallelOperationSemaphore = new AsyncSemaphore(options.ParallelOperationThreadCount.Value);
#endif
            this.lastException = null;
            this.committed     = false;
            this.disposed      = false;
        }