internal async Task RemoveAzureBlob(long taskId, IStorageBlobManagement localChannel, CloudBlob blob, bool isValidBlob)
{
if (!isValidBlob)
{
ValidatePipelineCloudBlob(blob);
}
ValidateBlobType(blob);
DeleteSnapshotsOption deleteSnapshotsOption = DeleteSnapshotsOption.None;
bool retryDeleteSnapshot = false;
if (IsSnapshot(blob))
{
if (deleteSnapshot)
{
throw new ArgumentException(String.Format(Resources.CannotDeleteSnapshotForSnapshot, blob.Name, blob.SnapshotTime));
}
}
else
{
if (deleteSnapshot)
{
deleteSnapshotsOption = DeleteSnapshotsOption.DeleteSnapshotsOnly;
}
else if (force)
{
deleteSnapshotsOption = DeleteSnapshotsOption.IncludeSnapshots;
}
else
{
retryDeleteSnapshot = true;
}
}
try
{
await DeleteCloudAsync(taskId, localChannel, blob, deleteSnapshotsOption);
retryDeleteSnapshot = false;
}
catch (StorageException e)
{
if (e.IsConflictException() && retryDeleteSnapshot)
{
//If x-ms-delete-snapshots is not specified on the request and the blob has associated snapshots, the Blob service returns status code 409 (Conflict).
retryDeleteSnapshot = true;
}
else
{
throw;
}
}
if (retryDeleteSnapshot)
{
string message = string.Format(Resources.ConfirmRemoveBlobWithSnapshot, blob.Name, blob.Container.Name);
if (await OutputStream.ConfirmAsync(message))
{
deleteSnapshotsOption = DeleteSnapshotsOption.IncludeSnapshots;
await DeleteCloudAsync(taskId, localChannel, blob, deleteSnapshotsOption);
}
else
{
string result = String.Format(Resources.RemoveBlobCancelled, blob.Name, blob.Container.Name);
OutputStream.WriteVerbose(taskId, result);
}
}
}