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


C# ICloudBlob.ReleaseLease方法代码示例

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


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

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

示例2: SetReleasedState

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


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