コード例 #1
0
        public AutoRenewLease(CloudBlockBlob blob)
        {
            _blob = blob;

            // acquire lease
            LeaseId = blob.TryAcquireLease(TimeSpan.FromSeconds(60));
            if (!HasLease) return;

            // keep renewing lease
            var fortySeconds = TimeSpan.FromSeconds(40);
            _renewalTimer = new Timer(x =>
            {
                if (_isRenewing)
                    blob.RenewLease(AccessCondition.GenerateLeaseCondition(LeaseId));
            }, null, fortySeconds, fortySeconds);
        }
コード例 #2
0
ファイル: AutoRenewLease.cs プロジェクト: afyles/NServiceBus
 public AutoRenewLease(CloudBlockBlob blob)
 {
     this.blob = blob;
     blob.Container.CreateIfNotExists();
        leaseId = blob.TryAcquireLease();
     if (HasLease)
     {
         renewalThread = new Thread(() =>
         {
             Thread.Sleep(TimeSpan.FromSeconds(40));
             blob.RenewLease(new AccessCondition()
                 {
                     LeaseId = leaseId
                 });
         });
         renewalThread.Start();
     }
 }
コード例 #3
0
    private bool RenewLease(CloudBlockBlob blob)
    {
        if (!HasLease(blob))
            return false;

        var name = blob.Name;

        try
        {
            blob.RenewLease(new AccessCondition
            {
                LeaseId = acquiredLeases[name].LeaseId
            });

            Trace.WriteLine(string.Format(RENEWED_LEASE, name));

            return true;
        }
        catch (StorageException)
        {
            acquiredLeases.Remove(name);

            Trace.WriteLine(string.Format(REMOVED_LEASE_FROM_ACQUIREDLEASES, name));

            return false;
        }
    }