コード例 #1
0
 public static void AcquireLeaseDuring(this CloudBlob blob, Action<string> action)
 {
     var leaseId = blob.AcquireLease();
     action(leaseId);
     blob.UploadText("text", "text");
     blob.ReleaseLease(leaseId);
 }
コード例 #2
0
ファイル: LeaseExtensions.cs プロジェクト: afyles/NServiceBus
 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;
     }
 }
コード例 #3
0
 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;
     }
 }
コード例 #4
0
 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;
     }
 }
コード例 #5
0
 private static string AcquireLease(this CloudBlockBlob blob, TimeSpan? leaseTime = null)
 {
     leaseTime = leaseTime ?? TimeSpan.FromSeconds(60);
     return blob.AcquireLease(leaseTime.Value, null);
 }
コード例 #6
0
ファイル: BlobStorage.cs プロジェクト: amido/Amido.Testing
        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;
            }
        }
コード例 #7
0
 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));
     }
 }