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


C# ICloudBlob.RenewLeaseAsync方法代码示例

本文整理汇总了C#中ICloudBlob.RenewLeaseAsync方法的典型用法代码示例。如果您正苦于以下问题:C# ICloudBlob.RenewLeaseAsync方法的具体用法?C# ICloudBlob.RenewLeaseAsync怎么用?C# ICloudBlob.RenewLeaseAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICloudBlob的用法示例。


在下文中一共展示了ICloudBlob.RenewLeaseAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetRenewedStateAsync

 /// <summary>
 /// Puts the lease on the given blob in a renewed state.
 /// </summary>
 /// <param name="blob">The blob with the lease.</param>
 /// <param name="leaseTime">The amount of time on the renewed lease.</param>
 /// <returns>The lease ID of the current lease.</returns>
 internal static async Task<string> SetRenewedStateAsync(ICloudBlob blob, TimeSpan? leaseTime)
 {
     string leaseId = await SetLeasedStateAsync(blob, leaseTime);
     await blob.RenewLeaseAsync(AccessCondition.GenerateLeaseCondition(leaseId));
     return leaseId;
 }
开发者ID:Juliako,项目名称:azure-sdk-for-net,代码行数:12,代码来源:LeaseTests.cs

示例2: LockInternal

        private async Task<Tuple<IDisposable, string>> LockInternal(ICloudBlob blob)
        {
            string leaseId;

            try
            {
                leaseId = await blob.AcquireLeaseAsync(TimeSpan.FromMinutes(1), null).ConfigureAwait(false);
                LeoTrace.WriteLine("Leased Blob: " + blob.Name);
            }
            catch (StorageException e)
            {
                // If we have a conflict this blob is already locked...
                if (e.RequestInformation.HttpStatusCode == 409)
                {
                    return null;
                }

                if (e.RequestInformation.HttpStatusCode == 404)
                {
                    leaseId = null;
                }
                else
                {
                    throw e.Wrap(blob.Name);
                }
            }

            // May not have had a blob pushed...
            if (leaseId == null)
            {
                try
                {
                    using (var stream = new MemoryStream(new byte[1]))
                    {
                        try
                        {
                            await blob.UploadFromStreamAsync(stream).ConfigureAwait(false);
                        }
                        catch (StorageException) { }  // Just eat storage exceptions at this point... something was created obviously
                    }
                    leaseId = await blob.AcquireLeaseAsync(TimeSpan.FromMinutes(1), null).ConfigureAwait(false);
                    LeoTrace.WriteLine("Created new blob and lease (2 calls): " + blob.Name);
                }
                catch (StorageException e)
                {
                    // If we have a conflict this blob is already locked...
                    if (e.RequestInformation.HttpStatusCode == 409)
                    {
                        return null;
                    }

                    if (e.RequestInformation.HttpStatusCode == 404)
                    {
                        leaseId = null;
                    }
                    else
                    {
                        throw e.Wrap(blob.Name);
                    }
                }
            }

            var condition = AccessCondition.GenerateLeaseCondition(leaseId);

            // Every 30 secs keep the lock renewed
            var keepAlive = AsyncEnumerableEx.CreateTimer(TimeSpan.FromSeconds(30))
                .Select(t =>
                {
                    LeoTrace.WriteLine("Renewed Lease: " + blob.Name);
                    return blob.RenewLeaseAsync(condition);
                })
                .Unwrap()
                .TakeUntilDisposed(null, t =>
                {
                    try
                    {
                        blob.ReleaseLease(condition);
                    }
                    catch (Exception e)
                    {
                        LeoTrace.WriteLine("Release failed: " + e.Message);
                    }
                });


            return Tuple.Create((IDisposable)keepAlive, leaseId);
        }
开发者ID:KalixHealth,项目名称:Kalix.Leo,代码行数:87,代码来源:AzureStore.cs

示例3: 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

示例4: RenewLease

 private static async Task RenewLease(ICloudBlob blob, string leaseId)
 {
     var blobKey = GetKey(blob);
     try
     {
         await blob.RenewLeaseAsync(
             new AccessCondition
             {
                 LeaseId = leaseId
             });
         Trace.TraceInformation("Renewed lease for blob {0}", blobKey);
     }
     catch (Exception ex)
     {
         Trace.TraceError("Failed to renew lease for blob {0}. Exception was: {1}", blobKey, ex);
     }
 }
开发者ID:ReubenBond,项目名称:Yams,代码行数:17,代码来源:SelfRenewableBlobLease.cs


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