/// <summary> /// Puts the lease on the given blob in an available state. /// </summary> /// <param name="blob">The blob with the lease.</param> internal static async Task SetAvailableStateAsync(CloudBlob blob) { bool shouldBreakFirst = false; OperationContext operationContext = new OperationContext(); try { await blob.DeleteIfExistsAsync(DeleteSnapshotsOption.None, null, null, operationContext); } catch (Exception) { if (operationContext.LastResult.ExtendedErrorInformation.ErrorCode == BlobErrorCodeStrings.LeaseIdMissing) { shouldBreakFirst = true; } else { throw; } } if (shouldBreakFirst) { await blob.BreakLeaseAsync(TimeSpan.Zero); await blob.DeleteAsync(); } await CreateBlobAsync(blob); }
/// <summary> /// Puts the lease on the given blob in an available state. /// </summary> /// <param name="blob">The blob with the lease.</param> internal static void SetAvailableStateTask(CloudBlob blob) { bool shouldBreakFirst = false; try { blob.DeleteIfExistsAsync().Wait(); } catch (AggregateException ex) { StorageException exception = ex.InnerException as StorageException; if (exception == null) { throw; } if (exception.RequestInformation.ExtendedErrorInformation.ErrorCode == BlobErrorCodeStrings.LeaseIdMissing) { shouldBreakFirst = true; } else { throw; } } if (shouldBreakFirst) { blob.BreakLeaseAsync(TimeSpan.Zero).Wait(); blob.DeleteAsync().Wait(); } CreateBlobTask(blob); }