/// <summary> /// Constructor. /// </summary> /// <param name="allowModifications"> /// If false, a <see cref="RequestFailedException"/> will be thrown if the blob is modified while /// it is being read from. /// </param> public BlobOpenReadOptions(bool allowModifications) { // Setting the Conditions to empty means we won't automatically // use the ETag as a condition and it will be possible for the blob // to change while it's being read from. if (allowModifications) { Conditions = new BlobRequestConditions(); } }
/// <summary> /// Deep copy constructor. /// </summary> /// <param name="deepCopySource"></param> private BlobDownloadOptions(BlobDownloadOptions deepCopySource) { Argument.AssertNotNull(deepCopySource, nameof(deepCopySource)); Range = new HttpRange(offset: deepCopySource.Range.Offset, length: deepCopySource.Range.Length); Conditions = BlobRequestConditions.CloneOrDefault(deepCopySource.Conditions); // can't access an internal deep copy in Storage.Common TransactionalHashingOptions = deepCopySource.TransactionalHashingOptions == default ? default : new DownloadTransactionalHashingOptions() { Algorithm = deepCopySource.TransactionalHashingOptions.Algorithm, Validate = deepCopySource.TransactionalHashingOptions.Validate }; }
/// <summary> /// Deep copy constructor. /// </summary> /// <param name="deepCopySource"></param> private BlobDownloadOptions(BlobDownloadOptions deepCopySource) { Argument.AssertNotNull(deepCopySource, nameof(deepCopySource)); Range = new HttpRange(offset: deepCopySource.Range.Offset, length: deepCopySource.Range.Length); Conditions = BlobRequestConditions.CloneOrDefault(deepCopySource.Conditions); ProgressHandler = deepCopySource.ProgressHandler; // can't access an internal deep copy in Storage.Common // TODO #27253 //TransactionalHashingOptions = deepCopySource.TransactionalHashingOptions == default // ? default // : new DownloadTransactionalHashingOptions() // { // Algorithm = deepCopySource.TransactionalHashingOptions.Algorithm, // Validate = deepCopySource.TransactionalHashingOptions.Validate // }; }
public async Task <bool> TryCreateAsync(BlockBlobClient blob, CancellationToken cancellationToken) { Dictionary <string, string> metadata = new Dictionary <string, string>(); BlobReceipt.Incomplete.ToMetadata(metadata); BlobRequestConditions accessCondition = new BlobRequestConditions { IfNoneMatch = new ETag("*") }; bool isContainerNotFoundException = false; try { await blob.UploadAsync( new MemoryStream(), new BlobUploadOptions() { Conditions = accessCondition, Metadata = metadata, }, cancellationToken : cancellationToken ).ConfigureAwait(false); return(true); } catch (RequestFailedException exception) { if (exception.IsNotFoundContainerNotFound()) { isContainerNotFoundException = true; } else if (exception.IsConflictBlobAlreadyExists()) { return(false); } else if (exception.IsPreconditionFailedLeaseIdMissing()) { return(false); } else { throw; } } Debug.Assert(isContainerNotFoundException); await _blobContainerClient.CreateIfNotExistsAsync(cancellationToken : cancellationToken).ConfigureAwait(false); try { await blob.UploadAsync( new MemoryStream(), new BlobUploadOptions() { Conditions = accessCondition, Metadata = metadata, }, cancellationToken : cancellationToken ).ConfigureAwait(false); return(true); } catch (RequestFailedException exception) { if (exception.IsConflictBlobAlreadyExists()) { return(false); } else if (exception.IsPreconditionFailedLeaseIdMissing()) { return(false); } else { throw; } } }
/// <summary> /// Creates a deep copy of the given instance, if any. /// </summary> /// <param name="deepCopySource">Instance to deep copy.</param> /// <returns>The deep copy, or null.</returns> internal static BlobRequestConditions CloneOrDefault(BlobRequestConditions deepCopySource) { if (deepCopySource == default) { return(default);
private BlobRequestConditions(BlobRequestConditions deepCopySource) : base(deepCopySource) { Argument.AssertNotNull(deepCopySource, nameof(deepCopySource)); LeaseId = deepCopySource.LeaseId; }