public static void AcquireLeaseDuring(this CloudBlob blob, Action<string> action) { var leaseId = blob.AcquireLease(); action(leaseId); blob.UploadText("text", "text"); blob.ReleaseLease(leaseId); }
public static string TryAcquireLease(this CloudBlockBlob blob) { try { return blob.AcquireLease(TimeSpan.FromSeconds(90), null); } catch (WebException e) { if (((HttpWebResponse)e.Response).StatusCode != HttpStatusCode.Conflict) // 409, already leased { throw; } e.Response.Close(); return null; } }
internal static string TryAcquireLease(this CloudBlockBlob blob, TimeSpan? leaseTime = null) { try { return blob.AcquireLease(leaseTime); } catch (StorageException storageException) { if (storageException.HasResponse(HttpStatusCode.Conflict, "There is already a lease present.")) return null; throw; } }
public static string TryAcquireLease(this CloudBlob blob, int leaseLengthSeconds) { try { return blob.AcquireLease(leaseLengthSeconds); } catch (WebException ex) { if (ex.Response == null || ((HttpWebResponse) ex.Response).StatusCode != HttpStatusCode.Conflict) { throw; } ex.Response.Close(); return null; } }
private static string AcquireLease(this CloudBlockBlob blob, TimeSpan? leaseTime = null) { leaseTime = leaseTime ?? TimeSpan.FromSeconds(60); return blob.AcquireLease(leaseTime.Value, null); }
private static string TryAcquireLease(this CloudBlob blob, int maximumStopDurationEstimateSeconds) { try { var leaseId = blob.AcquireLease(TimeSpan.FromSeconds(35), null, AccessCondition.GenerateEmptyCondition(), leaseRequestTimeout); blob.Metadata[leasedForTestTag] = "True"; blob.SetMetadata(AccessCondition.GenerateLeaseCondition(leaseId), leaseRequestTimeout); cancellationTokenSource = new CancellationTokenSource(); var cancellationToken = cancellationTokenSource.Token; leasingTask = Task.Factory.StartNew(t => AutoRenewLease(blob, leaseId, maximumStopDurationEstimateSeconds, cancellationToken), cancellationToken, TaskCreationOptions.LongRunning); return leaseId; } catch (StorageClientException storageException) { var webException = storageException.InnerException as WebException; if (webException == null || webException.Response == null || ((HttpWebResponse)webException.Response).StatusCode != HttpStatusCode.Conflict) // 409, already leased { BreakLease(blob); throw; } webException.Response.Close(); return null; } }
public static void Leased(this CloudBlockBlob blob, Action<CloudBlockBlob> a) { var lease = blob.AcquireLease(null, null); try { a(blob); } finally { blob.ReleaseLease(AccessCondition.GenerateLeaseCondition(lease)); } }