Exemple #1
0
 public Lease GetLease(string pathToFile, string blobSasUri)
 {
     if (!string.IsNullOrWhiteSpace(blobSasUri))
     {
         return(BlobLease.GetLease(pathToFile, blobSasUri));
     }
     else
     {
         return(FileLease.GetLease(pathToFile));
     }
 }
Exemple #2
0
        public static BlobLease TryGetLease(string pathToFile, string blobSasUri, string leaseId = null)
        {
            BlobLease lease = null;

            try
            {
                Logger.LogInfo($"Inside TryGetLease method with {pathToFile} and lease {leaseId == null}");
                var blob = BlobController.GetBlobForFile(pathToFile, blobSasUri);
                if (!blob.Exists())
                {
                    // This was a path blob. We want to create a new blob to hold the lease
                    // Luckily for us, just uploading some text to it does the trick
                    blob.UploadText("LeaseHolder");
                }

                leaseId = string.IsNullOrEmpty(leaseId) ? Guid.NewGuid().ToString() : leaseId;
                var leaseDuration = Infrastructure.Settings.LeaseDuration;
                lease = new BlobLease()
                {
                    PathBeingLeased = pathToFile,
                    ExpirationDate  = DateTime.UtcNow + leaseDuration,
                    _fileBlob       = blob
                };
                try
                {
                    Logger.LogInfo($"Acquiring Lease");
                    lease.Id = blob.AcquireLease(leaseDuration, leaseId);
                }
                catch (StorageException ex)
                {
                    Logger.LogErrorEvent("Got StorageException while acquiring lease", ex);
                    // Someone else is holding the lease
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Logger.LogErrorEvent("Failed in TryGetLease method", ex);
            }
            return(lease);
        }
Exemple #3
0
 public Lease TryGetLease(string pathToFile, string blobSasUri)
 {
     try
     {
         if (!string.IsNullOrWhiteSpace(blobSasUri))
         {
             return(BlobLease.TryGetLease(pathToFile, blobSasUri));
         }
         else
         {
             return(FileLease.TryGetLease(pathToFile));
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Could not get the lease to " + pathToFile);
         Console.WriteLine(e.Message);
         Console.WriteLine(e.StackTrace);
         return(null);
     }
 }