11// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22// SPDX-License-Identifier: Apache-2.0
33
4- namespace S3_BasicsScenario ;
54// snippet-start:[S3.dotnetv4.S3_BasicsBucket]
5+ using Amazon . S3 ;
6+ using Amazon . S3 . Model ;
7+
8+ namespace S3_Actions ;
69
710/// <summary>
811/// This class contains all of the methods for working with Amazon Simple
912/// Storage Service (Amazon S3) buckets.
1013/// </summary>
11- public class S3Bucket
14+ public class S3Wrapper
1215{
1316 private readonly IAmazonS3 _amazonS3 ;
1417
1518 /// <summary>
16- /// Initializes a new instance of the <see cref="S3Bucket "/> class.
19+ /// Initializes a new instance of the <see cref="S3Wrapper "/> class.
1720 /// </summary>
1821 /// <param name="amazonS3">An initialized Amazon S3 client object.</param>
19- public S3Bucket ( IAmazonS3 amazonS3 )
22+ public S3Wrapper ( IAmazonS3 amazonS3 )
2023 {
2124 _amazonS3 = amazonS3 ;
2225 }
@@ -176,9 +179,9 @@ public async Task<bool> CopyObjectInBucketAsync(
176179 /// Shows how to list the objects in an Amazon S3 bucket.
177180 /// </summary>
178181 /// <param name="bucketName">The name of the bucket for which to list.
179- /// the contents.</ param>
182+ /// < param name="printList">True to print out the list.
180183 /// <returns>The collection of objects.</returns>
181- public async Task < List < S3Object > > ListBucketContentsAsync ( string bucketName )
184+ public async Task < List < S3Object > ? > ListBucketContentsAsync ( string bucketName , bool printList = true )
182185 {
183186 try
184187 {
@@ -188,9 +191,12 @@ public async Task<List<S3Object>> ListBucketContentsAsync(string bucketName)
188191 MaxKeys = 5 ,
189192 } ;
190193
191- Console . WriteLine ( "--------------------------------------" ) ;
192- Console . WriteLine ( $ "Listing the contents of { bucketName } :") ;
193- Console . WriteLine ( "--------------------------------------" ) ;
194+ if ( printList )
195+ {
196+ Console . WriteLine ( "--------------------------------------" ) ;
197+ Console . WriteLine ( $ "Listing the contents of { bucketName } :") ;
198+ Console . WriteLine ( "--------------------------------------" ) ;
199+ }
194200
195201 var listObjectsV2Paginator = _amazonS3 . Paginators . ListObjectsV2 ( new ListObjectsV2Request
196202 {
@@ -205,10 +211,13 @@ public async Task<List<S3Object>> ListBucketContentsAsync(string bucketName)
205211 }
206212 }
207213
208- Console . WriteLine ( $ "Number of Objects: { s3Objects . Count } ") ;
209- foreach ( var entry in s3Objects )
214+ if ( printList )
210215 {
211- Console . WriteLine ( $ "Key = { entry . Key } Size = { entry . Size } ") ;
216+ Console . WriteLine ( $ "Number of Objects: { s3Objects . Count } ") ;
217+ foreach ( var entry in s3Objects )
218+ {
219+ Console . WriteLine ( $ "Key = { entry . Key } Size = { entry . Size } ") ;
220+ }
212221 }
213222
214223 return s3Objects ;
@@ -237,7 +246,7 @@ public async Task<bool> DeleteBucketContentsAsync(string bucketName)
237246 try
238247 {
239248 // Delete all objects in the bucket.
240- var deleteList = await ListBucketContentsAsync ( bucketName ) ;
249+ var deleteList = await ListBucketContentsAsync ( bucketName , false ) ;
241250 if ( deleteList != null && deleteList . Any ( ) )
242251 {
243252 await _amazonS3 . DeleteObjectsAsync ( new DeleteObjectsRequest ( )
0 commit comments