本文整理汇总了C#中ICloudBlob.ExistsAsync方法的典型用法代码示例。如果您正苦于以下问题:C# ICloudBlob.ExistsAsync方法的具体用法?C# ICloudBlob.ExistsAsync怎么用?C# ICloudBlob.ExistsAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICloudBlob
的用法示例。
在下文中一共展示了ICloudBlob.ExistsAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateBlobIfNoneExists
private static async Task CreateBlobIfNoneExists(ICloudBlob updateBlob)
{
if (!await updateBlob.ExistsAsync())
{
await BlobUtils.CreateEmptyBlob(updateBlob);
}
}
示例2: TryAcquireLeaseAsync
private async Task<string> TryAcquireLeaseAsync(ICloudBlob blob)
{
string leaseId;
var blobUriString = blob.Uri.ToString();
try
{
var sourceBlobExists = await blob.ExistsAsync();
if (!sourceBlobExists)
{
return null;
}
_jobEventSource.BeginningAcquireLease(blobUriString);
leaseId = await blob.AcquireLeaseAsync(_defaultLeaseTime, null);
_jobEventSource.FinishedAcquireLease(blobUriString);
}
catch (StorageException storageException)
{
// check if this is a 409 Conflict with a StatusDescription stating that "There is already a lease present."
// or 404 NotFound (might have been removed by another other instance of this job)
var webException = storageException.InnerException as WebException;
if (webException != null)
{
var httpWebResponse = webException.Response as HttpWebResponse;
if (httpWebResponse != null)
{
if ((httpWebResponse.StatusCode == HttpStatusCode.Conflict
&& httpWebResponse.StatusDescription == "There is already a lease present.") || httpWebResponse.StatusCode == HttpStatusCode.NotFound)
{
_jobEventSource.FailedAcquireLease(blobUriString); // no need to report these in Application Insights
return null;
}
}
}
_jobEventSource.FailedAcquireLease(blobUriString);
ApplicationInsights.TrackException(storageException);
throw;
}
return leaseId;
}
示例3: DoesBlobExistAsync
/// <summary>
/// Return a task that asynchronously check whether the specified blob exists.
/// </summary>
/// <param name="blob">ICloudBlob object</param>
/// <param name="options">Blob request options</param>
/// <param name="operationContext">Operation context</param>
/// <param name="cmdletCancellationToken">Cancellation token</param>
/// <returns>A task object that asynchronously check whether the specified blob exists.</returns>
public Task<bool> DoesBlobExistAsync(ICloudBlob blob, BlobRequestOptions options, OperationContext operationContext, CancellationToken cmdletCancellationToken)
{
return blob.ExistsAsync(options, operationContext, cmdletCancellationToken);
}
示例4: StartNewAutoRenewLeaseThread
private Thread StartNewAutoRenewLeaseThread(ICloudBlob blob, string leaseId, CancellationToken cancellationToken)
{
var autoRenewLeaseThread = new Thread(
async () =>
{
System.Diagnostics.Trace.TraceInformation("Thread [{0}] started.", Thread.CurrentThread.ManagedThreadId);
var blobUriString = blob.Uri.ToString();
try
{
while (!cancellationToken.IsCancellationRequested &&
await blob.ExistsAsync(cancellationToken))
{
// auto-renew lease when about to expire
Thread.Sleep(_leaseExpirationThreshold);
System.Diagnostics.Trace.TraceInformation("Thread [{0}] working.",
Thread.CurrentThread.ManagedThreadId);
_jobEventSource.BeginningRenewLease(blobUriString);
await blob.RenewLeaseAsync(AccessCondition.GenerateLeaseCondition(leaseId), cancellationToken);
_jobEventSource.FinishedRenewLease(blobUriString);
}
}
catch (TaskCanceledException)
{
System.Diagnostics.Trace.TraceWarning("Thread [{0}] cancelled.", Thread.CurrentThread.ManagedThreadId);
// No need to track
}
catch
{
System.Diagnostics.Trace.TraceError("Thread [{0}] error.", Thread.CurrentThread.ManagedThreadId);
// The blob could have been deleted in the meantime and this thread will be killed either way.
// No need to track in Application Insights.
}
});
autoRenewLeaseThread.Start();
return autoRenewLeaseThread;
}