Example #1
0
        private async Task <AcquireLeaseResult> Renew(string category, AcquiredLease acquiredLease)
        {
            var leaseClient = GetBlobClient(category, acquiredLease.ResourceKey).GetBlobLeaseClient(acquiredLease.Token);

            try
            {
                await leaseClient.RenewAsync();

                return(new AcquireLeaseResult(new AcquiredLease(acquiredLease.ResourceKey, acquiredLease.Duration, acquiredLease.Token, DateTime.UtcNow),
                                              ResponseCode.OK, null));
            }
            catch (RequestFailedException e)
            {
                ResponseCode statusCode;
                //This mapping is based on references : https://docs.microsoft.com/en-us/rest/api/storageservices/blob-service-error-codes
                // https://docs.microsoft.com/en-us/rest/api/storageservices/Lease-Blob?redirectedfrom=MSDN
                switch (e.Status)
                {
                case 404:
                case 409:
                case 412: statusCode = ResponseCode.InvalidToken; break;

                default: statusCode = ResponseCode.TransientFailure; break;
                }
                return(new AcquireLeaseResult(new AcquiredLease(acquiredLease.ResourceKey), statusCode, e));
            }
        }
Example #2
0
        private async Task <AcquireLeaseResult> Renew(string category, AcquiredLease acquiredLease)
        {
            var blob = this.container.GetBlobReference(GetBlobName(category, acquiredLease.ResourceKey));

            try
            {
                await blob.RenewLeaseAsync(AccessCondition.GenerateLeaseCondition(acquiredLease.Token));

                return(new AcquireLeaseResult(new AcquiredLease(acquiredLease.ResourceKey, acquiredLease.Duration, acquiredLease.Token, DateTime.UtcNow),
                                              ResponseCode.OK, null));
            }
            catch (StorageException e)
            {
                ResponseCode statusCode;
                //This mapping is based on references : https://docs.microsoft.com/en-us/rest/api/storageservices/blob-service-error-codes
                // https://docs.microsoft.com/en-us/rest/api/storageservices/Lease-Blob?redirectedfrom=MSDN
                switch (e.RequestInformation.HttpStatusCode)
                {
                case 404:
                case 409:
                case 412: statusCode = ResponseCode.InvalidToken; break;

                default: statusCode = ResponseCode.TransientFailure; break;
                }
                return(new AcquireLeaseResult(new AcquiredLease(acquiredLease.ResourceKey), statusCode, e));
            }
        }
Example #3
0
        private Task Release(string category, AcquiredLease acquiredLease)
        {
            var leaseClient = GetBlobClient(category, acquiredLease.ResourceKey).GetBlobLeaseClient(acquiredLease.Token);

            return(leaseClient.ReleaseAsync());
        }
Example #4
0
 public AcquireLeaseResult(AcquiredLease acquiredLease, ResponseCode statusCode, Exception failureException)
 {
     this.AcquiredLease    = acquiredLease;
     this.StatusCode       = statusCode;
     this.FailureException = failureException;
 }
Example #5
0
        private Task Release(string category, AcquiredLease acquiredLease)
        {
            var blob = this.container.GetBlobReference(GetBlobName(category, acquiredLease.ResourceKey));

            return(blob.ReleaseLeaseAsync(AccessCondition.GenerateLeaseCondition(acquiredLease.Token)));
        }