当前位置: 首页>>代码示例>>C#>>正文


C# ICloudBlob.ExistsAsync方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:Microsoft,项目名称:Yams,代码行数:7,代码来源:UpdateBlobFactory.cs

示例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;
        }
开发者ID:joyhui,项目名称:NuGet.Jobs,代码行数:41,代码来源:LogFileProvider.cs

示例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);
 }
开发者ID:NordPool,项目名称:azure-sdk-tools,代码行数:12,代码来源:StorageBlobManagement.cs

示例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;
 }
开发者ID:joyhui,项目名称:NuGet.Jobs,代码行数:36,代码来源:LogFileProvider.cs


注:本文中的ICloudBlob.ExistsAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。