コード例 #1
0
 public void SetUp()
 {
     blobSettings = new LeaseBlockBlobSettings
     {
         ConnectionString = "UseDevelopmentStorage=true",
         ContainerName = "test" + Guid.NewGuid().ToString("N"),
         BlobPath = "lease.blob",
         ReAquirePreviousTestLease = false,
         RetryCount = 2,
         RetryInterval = TimeSpan.FromMilliseconds(250)
     };
     maximumStopDurationEstimateSeconds = 10;
     var storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
     var client = storageAccount.CreateCloudBlobClient();
     container = client.GetContainerReference(blobSettings.ContainerName);
     container.CreateIfNotExist();
     leaseBlob = container.GetBlobReference(blobSettings.BlobPath);
     leaseBlob.UploadByteArray(new byte[0]);
 }
コード例 #2
0
ファイル: BlobStorage.cs プロジェクト: amido/Amido.Testing
 public static void ReleaseLease(LeaseBlockBlobSettings blobSettings, string leaseId)
 {
     cancellationTokenSource.Cancel();
     leasingTask.Wait();
     var blob = GetBlobReference(blobSettings);
     try
     {
         blob.ReleaseLease(AccessCondition.GenerateLeaseCondition(leaseId), leaseRequestTimeout);
     }
     catch
     {
     }
     finally
     {
         BreakLease(blob);
     }
 }
コード例 #3
0
ファイル: BlobStorage.cs プロジェクト: amido/Amido.Testing
 private static CloudBlob GetBlobReference(LeaseBlockBlobSettings blobSettings)
 {
     var storageAccount = blobSettings.ConnectionString == null 
         ? new CloudStorageAccount(new StorageCredentialsAccountAndKey(blobSettings.BlobStorage, blobSettings.BlobStorageKey), blobSettings.UseHttps) 
         : CloudStorageAccount.Parse(blobSettings.ConnectionString);
     var client = storageAccount.CreateCloudBlobClient();
     var container = client.GetContainerReference(blobSettings.ContainerName);
     return container.GetBlobReference(blobSettings.BlobPath);
 }
コード例 #4
0
ファイル: BlobStorage.cs プロジェクト: amido/Amido.Testing
        public static string AquireLease(LeaseBlockBlobSettings blobSettings, int maximumStopDurationEstimateSeconds)
        {
            var blob = GetBlobReference(blobSettings);

            if (blobSettings.ReAquirePreviousTestLease)
                BreakTestLeaseIfExists(blob);

            var retryCount = blobSettings.RetryCount;
            var leaseId = blob.TryAcquireLease(maximumStopDurationEstimateSeconds);
            while (leaseId == null && retryCount > 0)
            {
                Thread.Sleep(blobSettings.RetryInterval);
                leaseId = blob.TryAcquireLease(maximumStopDurationEstimateSeconds);
                retryCount--;
            }
            return leaseId;
        }