private static async Task CopyBlobAsync(BlobContainerClient container, BlobContainerClient destContainer, JPOFileInfo info, ILogger log) { try { // Get the name of the first blob in the container to use as the source. string blobName = info.fileName; // Create a BlobClient representing the source blob to copy. BlobClient sourceBlob = container.GetBlobClient(blobName); // Ensure that the source blob exists. if (await sourceBlob.ExistsAsync()) { // Lease the source blob for the copy operation to prevent another client from modifying it. BlobLeaseClient lease = sourceBlob.GetBlobLeaseClient(); // Specifying -1 for the lease interval creates an infinite lease. //await lease.AcquireAsync(TimeSpan.FromSeconds(100)); // Get the source blob's properties and display the lease state. BlobProperties sourceProperties = await sourceBlob.GetPropertiesAsync(); log.LoggerInfo($"Lease state: {sourceProperties.LeaseState}", info); Uri blob_sas_uri = BlobUtilities.GetServiceSASUriForBlob(sourceBlob, container.Name, null); // Get a BlobClient representing the destination blob BlobClient destBlob = destContainer.GetBlobClient(blobName);//destContainer.GetBlobClient(blob_sas_uri.ToString()); // Start the copy operation. await destBlob.StartCopyFromUriAsync(blob_sas_uri); // Get the destination blob's properties and display the copy status. BlobProperties destProperties = await destBlob.GetPropertiesAsync(); // Update the source blob's properties. sourceProperties = await sourceBlob.GetPropertiesAsync(); if (sourceProperties.LeaseState == LeaseState.Leased) { // Break the lease on the source blob. await lease.BreakAsync(); // Update the source blob's properties to check the lease state. sourceProperties = await sourceBlob.GetPropertiesAsync(); } } } catch (RequestFailedException ex) { log.LoggerError($"RequestFailedException: {ex.Message}", ex?.StackTrace, info); Console.WriteLine(ex.Message); Console.ReadLine(); throw; } }
private static async Task CopyBlobAsync(BlobContainerClient container, BlobContainerClient destContainer, JPOFileInfo fileInfo) { try { // Get the name of the first blob in the container to use as the source. string blobName = fileInfo.fileName; // Create a BlobClient representing the source blob to copy. BlobClient sourceBlob = container.GetBlobClient(blobName); // Ensure that the source blob exists. if (await sourceBlob.ExistsAsync()) { // Lease the source blob for the copy operation to prevent another client from modifying it. BlobLeaseClient lease = sourceBlob.GetBlobLeaseClient(); // Specifying -1 for the lease interval creates an infinite lease. //await lease.AcquireAsync(TimeSpan.FromSeconds(100)); // Get the source blob's properties and display the lease state. BlobProperties sourceProperties = await sourceBlob.GetPropertiesAsync(); Console.WriteLine($"Lease state: {sourceProperties.LeaseState}"); Uri blob_sas_uri = BlobUtilities.GetServiceSASUriForBlob(sourceBlob, container.Name, null); // Get a BlobClient representing the destination blob BlobClient destBlob = destContainer.GetBlobClient(fileInfo.fileName);//destContainer.GetBlobClient(blob_sas_uri.ToString()); var dict = new Dictionary <string, string>(); foreach (var(tag, index) in fileInfo.tags.Split(",").WithIndex()) { dict.Add($"tag{index}", tag.Trim()); } dict.Add("correlationID", fileInfo.correlationID); dict.Add("source", fileInfo.source); dict.Add("description", fileInfo.description); var options = new BlobCopyFromUriOptions { Metadata = dict }; // Start the copy operation. await destBlob.StartCopyFromUriAsync(blob_sas_uri, options); // Get the destination blob's properties and display the copy status. BlobProperties destProperties = await destBlob.GetPropertiesAsync(); // Update the source blob's properties. sourceProperties = await sourceBlob.GetPropertiesAsync(); if (sourceProperties.LeaseState == LeaseState.Leased) { // Break the lease on the source blob. await lease.BreakAsync(); // Update the source blob's properties to check the lease state. sourceProperties = await sourceBlob.GetPropertiesAsync(); } } } catch (RequestFailedException ex) { Console.WriteLine(ex.Message); Console.ReadLine(); throw; } }