private async Task <string> TryAcquireLeaseAsync(IStorageBlockBlob blob, TimeSpan leasePeriod, CancellationToken cancellationToken) { bool blobDoesNotExist = false; try { // Optimistically try to acquire the lease. The blob may not yet // exist. If it doesn't we handle the 404, create it, and retry below return(await blob.AcquireLeaseAsync(leasePeriod, null, cancellationToken)); } catch (StorageException exception) { if (exception.RequestInformation != null) { if (exception.RequestInformation.HttpStatusCode == 409) { return(null); } else if (exception.RequestInformation.HttpStatusCode == 404) { blobDoesNotExist = true; } else { throw; } } else { throw; } } if (blobDoesNotExist) { await TryCreateAsync(blob, cancellationToken); try { return(await blob.AcquireLeaseAsync(leasePeriod, null, cancellationToken)); } catch (StorageException exception) { if (exception.RequestInformation != null && exception.RequestInformation.HttpStatusCode == 409) { return(null); } else { throw; } } } return(null); }
public async Task <string> TryAcquireLeaseAsync(IStorageBlockBlob blob, CancellationToken cancellationToken) { try { return(await blob.AcquireLeaseAsync(LeasePeriod, null, cancellationToken)); } catch (StorageException exception) { if (exception.IsConflictLeaseAlreadyPresent()) { return(null); } else if (exception.IsNotFoundBlobOrContainerNotFound()) { // If someone deleted the receipt, there's no lease to acquire. return(null); } else { throw; } } }
private async Task<string> TryAcquireLeaseAsync(IStorageBlockBlob blob, TimeSpan leasePeriod, CancellationToken cancellationToken) { try { return await blob.AcquireLeaseAsync(leasePeriod, null, cancellationToken); } catch (StorageException exception) { if (exception.IsConflictLeaseAlreadyPresent()) { return null; } else if (exception.IsNotFoundBlobOrContainerNotFound()) { // If someone deleted the receipt, there's no lease to acquire. return null; } else { throw; } } }
private async Task<string> TryAcquireLeaseAsync(IStorageBlockBlob blob, TimeSpan leasePeriod, CancellationToken cancellationToken) { bool blobDoesNotExist = false; try { // Optimistically try to acquire the lease. The blob may not yet // exist. If it doesn't we handle the 404, create it, and retry below return await blob.AcquireLeaseAsync(leasePeriod, null, cancellationToken); } catch (StorageException exception) { if (exception.RequestInformation != null) { if (exception.RequestInformation.HttpStatusCode == 409) { return null; } else if (exception.RequestInformation.HttpStatusCode == 404) { blobDoesNotExist = true; } else { throw; } } else { throw; } } if (blobDoesNotExist) { await TryCreateAsync(blob, cancellationToken); try { return await blob.AcquireLeaseAsync(leasePeriod, null, cancellationToken); } catch (StorageException exception) { if (exception.RequestInformation != null && exception.RequestInformation.HttpStatusCode == 409) { return null; } else { throw; } } } return null; }