private BlobLeaseMaintainer(IBlobServiceClientEx blobServiceClientEx, string containerName, string blobName, string leaseId, DateTime leaseAcquiredOn, int leaseDuration, Action <BlobLeaseMaintainer, AggregateException> exceptionHandler) { _blobServiceClientEx = blobServiceClientEx; ContainerName = containerName; BlobName = blobName; LeaseId = leaseId; LeaseAcquiredOn = leaseAcquiredOn; LeaseDuration = leaseDuration; TaskExceptionHandler = exceptionHandler; CancellationTokenSource = new CancellationTokenSource(); StartMaintainingLease(); }
public static async Task <BlobLeaseMaintainer> LeaseNewOrExistingBlockBlobAndMaintainLease(IBlobServiceClientEx blobServiceClientEx, string containerName, string blobName, int leaseDuration, string proposedLeaseId = null, Action <BlobLeaseMaintainer, AggregateException> exceptionHandler = null) { var leaseResponse = await LeaseNewOrExistingBlockBlob(blobServiceClientEx, containerName, blobName, leaseDuration, proposedLeaseId); return(new BlobLeaseMaintainer(blobServiceClientEx, containerName, blobName, leaseResponse.LeaseId, leaseResponse.Date, leaseDuration, exceptionHandler)); }
public static async Task <LeaseBlobAcquireResponse> LeaseNewOrExistingBlockBlob(IBlobServiceClientEx blobServiceClientEx, string containerName, string blobName, int leaseDuration, string proposedLeaseId = null) { try { return(await LeaseExistingBlockBlob(blobServiceClientEx, containerName, blobName, leaseDuration, proposedLeaseId)); } catch (BlobNotFoundAzureException) { // ignore so that the blob can be created and leased below // if we could await in here, we'd just do it in here } await blobServiceClientEx.PutBlockBlobAsync(containerName, blobName, new byte[] { }); return(await LeaseExistingBlockBlob(blobServiceClientEx, containerName, blobName, leaseDuration, proposedLeaseId)); }