<commit_before>﻿// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier:  Apache-2.0

/// <summary>
/// This interactive example shows some of the standard procedures for Amazon
/// Simple Storage Service (Amazon S3) buckets. It will walk through the
/// process of creating an Amazon S3 bucket, uploading
/// </summary>
namespace S3_BasicsScenario
{
    using System;
    using System.IO;
    using System.Threading.Tasks;
    using Amazon.S3;
    using Amazon.S3.Model;
    using Amazon.S3.Transfer;

    public class S3Bucket
    {
        // snippet-start:[S3.dotnetv3.S3_Basics-CreateBucket]

        /// <summary>
        /// Shows how to create a new Amazon S3 bucket.
        /// </summary>
        /// <param name="client">An initialized Amazon S3 client object.</param>
        /// <param name="bucketName">The name of the bucket to create.</param>
        /// <returns>A boolean value representing the success or failure of
        /// the bucket creation process.</returns>
        public static async Task<bool> CreateBucketAsync(IAmazonS3 client, string bucketName)
        {
            try
            {
                var request = new PutBucketRequest
                {
                    BucketName = bucketName,
                    UseClientRegion = true,
                };

                var response = await client.PutBucketAsync(request);
                return response.HttpStatusCode == System.Net.HttpStatusCode.OK;
            }
            catch (AmazonS3Exception ex)
            {
                Console.WriteLine($"Error creating bucket: '{ex.Message}'");
                return false;
            }
        }

        // snippet-end:[S3.dotnetv3.S3_Basics-CreateBucket]

        // snippet-start:[S3.dotnetv3.S3_Basics-UploadFile]

        /// <summary>
        /// Shows how to upload a file from the local computer to an Amazon S3
        /// bucket.
        /// </summary>
        /// <param name="client">An initialized Amazon S3 client object.</param>
        /// <param name="bucketName">The Amazon S3 bucket to which the object
        /// will be uploaded.</param>
        /// <param name="objectName">The object to upload.</param>
        /// <param name="filePath">The path, including file name, of the object
        /// on the local computer to upload.</param>
        /// <returns>A boolean value indicating the success or failure of the
        /// upload procedure.</returns>
        public static async Task<bool> UploadFileAsync(
            IAmazonS3 client,
            string bucketName,
            string objectName,
            string filePath)
        {
            using ITransferUtility transfer = new TransferUtility(client);
            try
            {
                var request = new TransferUtilityUploadRequest
                {
                    BucketName = bucketName,
                    Key = objectName,
                    FilePath = filePath,
                };

                await transfer.UploadAsync(request);
                return true;
            }
            catch (AmazonS3Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
                return false;
            }
        }

        // snippet-start:[S3.dotnetv3.S3_Basics-UploadFile]

        // snippet-start:[S3.dotnetv3.S3_Basics-DownloadObject]

        /// <summary>
        /// Sows how to download an object from and Amazon S3 bucket to the
        /// local computer.
        /// </summary>
        /// <param name="client">An initialized Amazon S3 client object.</param>
        /// <param name="bucketName">The name of the bucket where the object is
        /// currently stored.</param>
        /// <param name="objectName">The name of the object to download.</param>
        /// <param name="filePath">The path, including filename, where the
        /// downloaded object will be stored.</param>
        /// <returns>A boolean value indicating the success or failure of the
        /// download process.</returns>
        public static async Task<bool> DownloadObjectFromBucketAsync(
            IAmazonS3 client,
            string bucketName,
            string objectName,
            string filePath)
        {
            using ITransferUtility transfer = new TransferUtility(client);
            try
            {
                var request = new TransferUtilityDownloadRequest
                {
                    BucketName = bucketName,
                    FilePath = filePath,
                    Key = objectName,
                };

                await transfer.DownloadAsync(request);

                if (File.Exists($"{filePath}\\{objectName}"))
                {
                    return true;
                }

                return false;
            }
            catch (AmazonS3Exception e)
            {
                // If the bucket or the object do not exist
                Console.WriteLine($"Error: '{e.Message}'");
                return false;
            }
        }

        // snippet-start:[S3.dotnetv3.S3_Basics-DownloadObject]

        // snippet-start:[S3.dotnetv3.S3_Basics-CopyObject]

        /// <summary>
        /// Copies an object in an Amazon S3 bucket to a folder within the
        /// same bucket.
        /// </summary>
        /// <param name="client">An initialized Amazon S3 client object.</param><commit_msg>Fixed snippet tags in the scenario example.<commit_after>﻿// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier:  Apache-2.0

/// <summary>
/// This interactive example shows some of the standard procedures for Amazon
/// Simple Storage Service (Amazon S3) buckets. It will walk through the
/// process of creating an Amazon S3 bucket, uploading
/// </summary>
namespace S3_BasicsScenario
{
    using System;
    using System.IO;
    using System.Threading.Tasks;
    using Amazon.S3;
    using Amazon.S3.Model;
    using Amazon.S3.Transfer;

    public class S3Bucket
    {
        // snippet-start:[S3.dotnetv3.S3_Basics-CreateBucket]

        /// <summary>
        /// Shows how to create a new Amazon S3 bucket.
        /// </summary>
        /// <param name="client">An initialized Amazon S3 client object.</param>
        /// <param name="bucketName">The name of the bucket to create.</param>
        /// <returns>A boolean value representing the success or failure of
        /// the bucket creation process.</returns>
        public static async Task<bool> CreateBucketAsync(IAmazonS3 client, string bucketName)
        {
            try
            {
                var request = new PutBucketRequest
                {
                    BucketName = bucketName,
                    UseClientRegion = true,
                };

                var response = await client.PutBucketAsync(request);
                return response.HttpStatusCode == System.Net.HttpStatusCode.OK;
            }
            catch (AmazonS3Exception ex)
            {
                Console.WriteLine($"Error creating bucket: '{ex.Message}'");
                return false;
            }
        }

        // snippet-end:[S3.dotnetv3.S3_Basics-CreateBucket]

        // snippet-start:[S3.dotnetv3.S3_Basics-UploadFile]

        /// <summary>
        /// Shows how to upload a file from the local computer to an Amazon S3
        /// bucket.
        /// </summary>
        /// <param name="client">An initialized Amazon S3 client object.</param>
        /// <param name="bucketName">The Amazon S3 bucket to which the object
        /// will be uploaded.</param>
        /// <param name="objectName">The object to upload.</param>
        /// <param name="filePath">The path, including file name, of the object
        /// on the local computer to upload.</param>
        /// <returns>A boolean value indicating the success or failure of the
        /// upload procedure.</returns>
        public static async Task<bool> UploadFileAsync(
            IAmazonS3 client,
            string bucketName,
            string objectName,
            string filePath)
        {
            using ITransferUtility transfer = new TransferUtility(client);
            try
            {
                var request = new TransferUtilityUploadRequest
                {
                    BucketName = bucketName,
                    Key = objectName,
                    FilePath = filePath,
                };

                await transfer.UploadAsync(request);
                return true;
            }
            catch (AmazonS3Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
                return false;
            }
        }

        // snippet-end:[S3.dotnetv3.S3_Basics-UploadFile]

        // snippet-start:[S3.dotnetv3.S3_Basics-DownloadObject]

        /// <summary>
        /// Sows how to download an object from and Amazon S3 bucket to the
        /// local computer.
        /// </summary>
        /// <param name="client">An initialized Amazon S3 client object.</param>
        /// <param name="bucketName">The name of the bucket where the object is
        /// currently stored.</param>
        /// <param name="objectName">The name of the object to download.</param>
        /// <param name="filePath">The path, including filename, where the
        /// downloaded object will be stored.</param>
        /// <returns>A boolean value indicating the success or failure of the
        /// download process.</returns>
        public static async Task<bool> DownloadObjectFromBucketAsync(
            IAmazonS3 client,
            string bucketName,
            string objectName,
            string filePath)
        {
            using ITransferUtility transfer = new TransferUtility(client);
            try
            {
                var request = new TransferUtilityDownloadRequest
                {
                    BucketName = bucketName,
                    FilePath = filePath,
                    Key = objectName,
                };

                await transfer.DownloadAsync(request);

                if (File.Exists($"{filePath}\\{objectName}"))
                {
                    return true;
                }

                return false;
            }
            catch (AmazonS3Exception e)
            {
                // If the bucket or the object do not exist
                Console.WriteLine($"Error: '{e.Message}'");
                return false;
            }
        }

        // snippet-end:[S3.dotnetv3.S3_Basics-DownloadObject]

        // snippet-start:[S3.dotnetv3.S3_Basics-CopyObject]

        /// <summary>
        /// Copies an object in an Amazon S3 bucket to a folder within the
        /// same bucket.
        /// </summary>
        /// <param name="client">An initialized Amazon S3 client object.</param>
{'fraction_non_alphanumeric': 0.09854351032448377, 'fraction_numerical': 0.008296460176991151, 'mean_word_length': 1.5684185606060606, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3931368', 'n_tokens_mistral': 2735, 'n_tokens_neox': 2603, 'n_words': 791}