/// <summary> /// Releases the file resources used by the stream. /// </summary> public void Dispose() { if (this.originalStream != null) { this.originalStream.Dispose(); this.originalStream = null; } }
public IAsyncOperation<ICloudFileStream> OpenWriteAsync(long? size, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext) #endif { FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(options, this.ServiceClient, false); operationContext = operationContext ?? new OperationContext(); bool createNew = size.HasValue; if (!createNew && modifiedOptions.StoreFileContentMD5.Value) { throw new ArgumentException(SR.MD5NotPossible); } #if ASPNET_K return Task.Run(async () => { if (createNew) { await this.CreateAsync(size.Value, accessCondition, options, operationContext, cancellationToken); } else { await this.FetchAttributesAsync(accessCondition, options, operationContext, cancellationToken); #else return AsyncInfo.Run(async (token) => { if (createNew) { await this.CreateAsync(size.Value, accessCondition, options, operationContext); } else { await this.FetchAttributesAsync(accessCondition, options, operationContext); #endif size = this.Properties.Length; } if (accessCondition != null) { accessCondition = AccessCondition.GenerateLeaseCondition(accessCondition.LeaseId); } #if ASPNET_K CloudFileStream stream = new FileWriteStream(this, size.Value, createNew, accessCondition, modifiedOptions, operationContext); return stream; }, cancellationToken); #else ICloudFileStream stream = new FileWriteStreamHelper(this, size.Value, createNew, accessCondition, modifiedOptions, operationContext); return stream; }); #endif }
/// <summary> /// Initializes a new instance of the FileWriteStreamHelper 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 object that represents the access conditions for the file. If null, no condition is used.</param> /// <param name="options">An object that specifies additional options for the request.</param> internal FileWriteStreamHelper(CloudFile file, long fileSize, bool createNew, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext) { this.originalStream = new FileWriteStream(file, fileSize, createNew, accessCondition, options, operationContext); this.originalStreamAsOutputStream = this.originalStream.AsOutputStream(); }