Ejemplo n.º 1
0
 /// <summary>
 /// Puts the lease on the given container in a broken state due to a break period of zero.
 /// </summary>
 /// <param name="container">The container with the lease.</param>
 /// <returns>The lease ID of the broken lease.</returns>
 internal static string SetInstantBrokenStateAPM(CloudBlobContainer container)
 {
     string leaseId = SetLeasedStateAPM(container, null /* infinite lease */);
     using (AutoResetEvent waitHandle = new AutoResetEvent(false))
     {
         IAsyncResult result = container.BeginBreakLease(TimeSpan.Zero, ar => waitHandle.Set(), null);
         waitHandle.WaitOne();
         container.EndBreakLease(result);
         return leaseId;
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Puts the lease on the given container in an unleased state (either available or broken).
 /// </summary>
 /// <param name="container">The container with the lease.</param>
 internal static void SetUnleasedStateAPM(CloudBlobContainer container)
 {
     if (!container.CreateIfNotExists())
     {
         try
         {
             using (AutoResetEvent waitHandle = new AutoResetEvent(false))
             {
                 IAsyncResult result = container.BeginBreakLease(TimeSpan.Zero, ar => waitHandle.Set(), null);
                 waitHandle.WaitOne();
                 container.EndBreakLease(result);
             }
         }
         catch (StorageException e)
         {
             if (e.RequestInformation.ExtendedErrorInformation.ErrorCode == BlobErrorCodeStrings.LeaseAlreadyBroken ||
                 e.RequestInformation.ExtendedErrorInformation.ErrorCode == BlobErrorCodeStrings.LeaseNotPresentWithLeaseOperation)
             {
             }
             else
             {
                 throw;
             }
         }
     }
 }