當前位置: 首頁>>代碼示例>>C#>>正文


C# CloudBlockBlob.AcquireLease方法代碼示例

本文整理匯總了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.AcquireLease方法的典型用法代碼示例。如果您正苦於以下問題:C# CloudBlockBlob.AcquireLease方法的具體用法?C# CloudBlockBlob.AcquireLease怎麽用?C# CloudBlockBlob.AcquireLease使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob的用法示例。


在下文中一共展示了CloudBlockBlob.AcquireLease方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: uploadfromFilesystem

 public void uploadfromFilesystem(CloudBlockBlob blob, string localFilePath, string eventType)
 {
     if (eventType.Equals("create") || eventType.Equals("signUpStart"))
     {
         Program.ClientForm.addtoConsole("Upload started[create || signUpStart]:" + localFilePath);
         blob.UploadFromFile(localFilePath, FileMode.Open);
         Program.ClientForm.addtoConsole("Uploaded");
         Program.ClientForm.ballon("Uploaded:"+ localFilePath);
     }
     else
     {
         try
         {
             Program.ClientForm.addtoConsole("Upload started[change,etc]:" + localFilePath);
             string leaseId = Guid.NewGuid().ToString();
             blob.AcquireLease(TimeSpan.FromMilliseconds(16000), leaseId);
             blob.UploadFromFile(localFilePath, FileMode.Open, AccessCondition.GenerateLeaseCondition(leaseId));
             blob.ReleaseLease(AccessCondition.GenerateLeaseCondition(leaseId));
             Program.ClientForm.addtoConsole("Uploaded");
             Program.ClientForm.ballon("Uploaded:" + localFilePath);
         }
         catch (Exception ex)
         {
             Program.ClientForm.addtoConsole("Upload: second attempt");
             Thread.Sleep(5000);
             string leaseId = Guid.NewGuid().ToString();
             blob.AcquireLease(TimeSpan.FromMilliseconds(16000), leaseId);
             blob.UploadFromFile(localFilePath, FileMode.Open, AccessCondition.GenerateLeaseCondition(leaseId));
             blob.ReleaseLease(AccessCondition.GenerateLeaseCondition(leaseId));
             Program.ClientForm.addtoConsole("Uploaded");
             Program.ClientForm.ballon("Uploaded:" + localFilePath);
         }
     }
 }
開發者ID:hangmiao,項目名稱:DBLike,代碼行數:34,代碼來源:LocalFileSys.cs

示例2: RenewingBlobLease

		public RenewingBlobLease(CloudBlockBlob blob)
		{
			_log = this.GetLogger();
			_blob = blob;
			Id = _blob.AcquireLease(TimeSpan.FromSeconds(40), null);
			_log.DebugEvent("AcquiredLease", new Facet("blobUri", _blob.Uri), new Facet("leaseId", Id));

			_timer = new Timer(TimeSpan.FromSeconds(30).TotalMilliseconds);
			_timer.Elapsed += RenewLease;
			_timer.Start();
		}
開發者ID:smartpcr,項目名稱:bigdata2,代碼行數:11,代碼來源:RenewingBlobLease.cs

示例3: Leased

 public static void Leased(CloudBlockBlob blob, Action<CloudBlockBlob> a)
 {
     var lease = blob.AcquireLease(TimeSpan.FromSeconds(60), null);
     try
     {
         a(blob);
     }
     finally
     {
         blob.ReleaseLease(AccessCondition.GenerateLeaseCondition(lease));
     }
 }
開發者ID:philipnilsson,項目名稱:N2AzureFileSystem,代碼行數:12,代碼來源:Program.cs

示例4: TryAcquireLease

    public bool TryAcquireLease(CloudBlockBlob blob, double leaseTimeInSeconds)
    {
        if(leaseTimeInSeconds < 15 || leaseTimeInSeconds > 60)
            throw new ArgumentException(@"value must be greater than 15 and smaller than 60", 
                                        "leaseTimeInSeconds");
        try
        {
            string proposedLeaseId = Guid.NewGuid().ToString();

            var leaseTime = TimeSpan.FromSeconds(leaseTimeInSeconds);
            string leaseId = blob.AcquireLease(leaseTime,
                                                        proposedLeaseId);

            UpdateAcquiredLease(blob, leaseId, leaseTimeInSeconds);
                
            return true;
        }
        catch (StorageException)
        {
            Trace.WriteLine(string.Format(FAILED_TO_ACQUIRE_LEASE, blob.Name));
            return false;
        }
    }
開發者ID:hossamdarwish,項目名稱:Brisebois.WindowsAzure,代碼行數:23,代碼來源:BlobLeaseManager.cs


注:本文中的Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.AcquireLease方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。