本文整理汇总了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);
}
}
}
示例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();
}
示例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));
}
}
示例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;
}
}