/// <summary> /// Deletes the artifacts associated with an import task using the bucket name /// and key prefix to the artifacts in Amazon S3. No check is performed to /// determine whether the associated conversion task is in progress. /// </summary> /// <param name="s3Client"> /// An Amazon S3 client for the operation to use. This should have been constructed /// using credentials that have access to the bucket containing the image file /// artifacts and be scoped to the region containing the bucket. /// </param> /// <param name="bucketName">The name of the bucket containing the artifacts</param> /// <param name="keyPrefix">The common key prefix of the artifacts</param> /// <param name="progressCallback">Optional progress callback</param> public static void DeleteImageArtifacts(ICoreAmazonS3 s3Client, string bucketName, string keyPrefix, CleanupProgressCallback progressCallback) { // build the full collection of keys to be deleted so that any progress // indicator managed by the caller is accurate SendProgressNotification(progressCallback, "Collating keys to image file artifacts", null); var artifactKeys = s3Client.GetAllObjectKeys(bucketName, keyPrefix, null); if (artifactKeys.Count == 0) { var msg = string.Format(CultureInfo.InvariantCulture, "Found no image file artifacts with key prefix '{0}' to delete in bucket '{1}'.", keyPrefix, bucketName); SendProgressNotification(progressCallback, msg, null); return; } var deletionMsg = string.Format(CultureInfo.InvariantCulture, "Deleting {0} image file artifacts (key prefix '{1}', bucket '{2}').", artifactKeys.Count, keyPrefix, bucketName); SendProgressNotification(progressCallback, deletionMsg, 0); var index = 0; var processed = 0; do { var batchOfKeys = new List <string>(); while (batchOfKeys.Count < 1000 && index < artifactKeys.Count) { batchOfKeys.Add(artifactKeys[index++]); } s3Client.Deletes(bucketName, batchOfKeys, null); processed += batchOfKeys.Count; SendProgressNotification(progressCallback, deletionMsg, processed / artifactKeys.Count * 100); } while (processed < artifactKeys.Count); }
/// <summary> /// Deletes the artifacts associated with an import task using the bucket name /// and key prefix to the artifacts in Amazon S3. No check is performed to /// determine whether the associated conversion task is in progress. /// </summary> /// <param name="s3Client"> /// An Amazon S3 client for the operation to use. This should have been constructed /// using credentials that have access to the bucket containing the image file /// artifacts and be scoped to the region containing the bucket. /// </param> /// <param name="bucketName">The name of the bucket containing the artifacts</param> /// <param name="keyPrefix">The common key prefix of the artifacts</param> /// <param name="progressCallback">Optional progress callback</param> public static void DeleteImageArtifacts(ICoreAmazonS3 s3Client, string bucketName, string keyPrefix, CleanupProgressCallback progressCallback) { // build the full collection of keys to be deleted so that any progress // indicator managed by the caller is accurate SendProgressNotification(progressCallback, "Collating keys to image file artifacts", null); var artifactKeys = s3Client.GetAllObjectKeys(bucketName, keyPrefix, null); if (artifactKeys.Count == 0) { var msg = string.Format(CultureInfo.InvariantCulture, "Found no image file artifacts with key prefix '{0}' to delete in bucket '{1}'.", keyPrefix, bucketName); SendProgressNotification(progressCallback, msg, null); return; } var deletionMsg = string.Format(CultureInfo.InvariantCulture, "Deleting {0} image file artifacts (key prefix '{1}', bucket '{2}').", artifactKeys.Count, keyPrefix, bucketName); SendProgressNotification(progressCallback, deletionMsg, 0); var index = 0; var processed = 0; do { var batchOfKeys = new List<string>(); while (batchOfKeys.Count < 1000 && index < artifactKeys.Count) { batchOfKeys.Add(artifactKeys[index++]); } s3Client.Deletes(bucketName, batchOfKeys, null); processed += batchOfKeys.Count; SendProgressNotification(progressCallback, deletionMsg, processed/artifactKeys.Count * 100); } while (processed < artifactKeys.Count); }