<commit_before>﻿using System;
using System.IO;
using System.Linq;
using Cake.Core.IO;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;

namespace Cake.AzureStorage {
    /// <summary>
    /// Azure Storage Client for Cake.
    /// </summary>
    public class AzureStorage {

        private static void CheckSettings(AzureStorageSettings settings) {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings), "Settings are null");
            }
            if (string.IsNullOrEmpty(settings.AccountName))
            {
                throw new ArgumentNullException("account name", "Account name is null.");
            }
            if (string.IsNullOrEmpty(settings.Key))
            {
                throw new ArgumentNullException("key", "Key is null.");
            }
            if (string.IsNullOrEmpty(settings.ContainerName))
            {
                throw new ArgumentNullException("container name", "Container name is null.");
            }
            if (string.IsNullOrEmpty(settings.BlobName))
            {
                throw new ArgumentNullException("blob name", "Blob name is null.");
            }
        }
        /// <summary>
        /// Uploads file to an Azure blob storage account.
        /// </summary>
        /// <param name="settings">Azure Storage Settings</param>
        /// <param name="fileToUpload">File to upload to blob storage.</param>
        public static void UploadFileToBlob(AzureStorageSettings settings, FilePath fileToUpload) {
            CheckSettings(settings);
            if (fileToUpload == null)
            {
                throw new ArgumentNullException(nameof(fileToUpload), "File to upload is null.");
            }
            var storageAccount = new CloudStorageAccount(new StorageCredentials(settings.AccountName, settings.Key), true);

            var blobClient = storageAccount.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference(settings.ContainerName);
            var block = container.GetBlockBlobReference(settings.BlobName);
            block.UploadFromFile(fileToUpload.FullPath, FileMode.Open);
        }
        /// <summary>
        /// Deletes an Azure blob from Azure Storage
        /// </summary>
        /// <param name="settings">Azure Storage Settings</param>
        public static void DeleteBlob(AzureStorageSettings settings) {
            CheckSettings(settings);
            var storageAccount = new CloudStorageAccount(new StorageCredentials(settings.AccountName, settings.Key), true);

            var blobClient = storageAccount.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference(settings.ContainerName);
            var blob = container.GetBlockBlobReference(settings.BlobName);
            blob.Delete();
        }

        /// <summary>
        /// Deletes an Azure blob from Azure Storage using a prefix to determine which blobs to delete, prefix = BlobName
        /// </summary>
        /// <param name="settings">Azure Storage Settings</param>
        public static void DeleteBlobsByPrefix(AzureStorageSettings settings) {
            CheckSettings(settings);
            var storageAccount = new CloudStorageAccount(new StorageCredentials(settings.AccountName, settings.Key), true);
            var blobClient = storageAccount.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference(settings.ContainerName);

            var blobs = container.ListBlobs(settings.BlobName);

            foreach (var blob in blobs.Select(x => container.GetBlockBlobReference(x.Uri.ToString()))) {
                blob.Delete();
            }
        }

    }
}<commit_msg>Attempting to fix issue with Remote Server Returned An Error: 404 (Not Found)<commit_after>﻿using System;
using System.IO;
using System.Linq;
using Cake.Core.IO;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;

namespace Cake.AzureStorage {
    /// <summary>
    /// Azure Storage Client for Cake.
    /// </summary>
    public class AzureStorage {

        private static void CheckSettings(AzureStorageSettings settings) {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings), "Settings are null");
            }
            if (string.IsNullOrEmpty(settings.AccountName))
            {
                throw new ArgumentNullException("account name", "Account name is null.");
            }
            if (string.IsNullOrEmpty(settings.Key))
            {
                throw new ArgumentNullException("key", "Key is null.");
            }
            if (string.IsNullOrEmpty(settings.ContainerName))
            {
                throw new ArgumentNullException("container name", "Container name is null.");
            }
            if (string.IsNullOrEmpty(settings.BlobName))
            {
                throw new ArgumentNullException("blob name", "Blob name is null.");
            }
        }
        /// <summary>
        /// Uploads file to an Azure blob storage account.
        /// </summary>
        /// <param name="settings">Azure Storage Settings</param>
        /// <param name="fileToUpload">File to upload to blob storage.</param>
        public static void UploadFileToBlob(AzureStorageSettings settings, FilePath fileToUpload) {
            CheckSettings(settings);
            if (fileToUpload == null)
            {
                throw new ArgumentNullException(nameof(fileToUpload), "File to upload is null.");
            }
            var storageAccount = new CloudStorageAccount(new StorageCredentials(settings.AccountName, settings.Key), true);

            var blobClient = storageAccount.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference(settings.ContainerName);
            var block = container.GetBlockBlobReference(settings.BlobName);
            block.UploadFromFile(fileToUpload.FullPath, FileMode.Open);
        }
        /// <summary>
        /// Deletes an Azure blob from Azure Storage
        /// </summary>
        /// <param name="settings">Azure Storage Settings</param>
        public static void DeleteBlob(AzureStorageSettings settings) {
            CheckSettings(settings);
            var storageAccount = new CloudStorageAccount(new StorageCredentials(settings.AccountName, settings.Key), true);

            var blobClient = storageAccount.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference(settings.ContainerName);
            var blob = container.GetBlockBlobReference(settings.BlobName);
            blob.Delete();
        }

        /// <summary>
        /// Deletes an Azure blob from Azure Storage using a prefix to determine which blobs to delete, prefix = BlobName
        /// </summary>
        /// <param name="settings">Azure Storage Settings</param>
        public static void DeleteBlobsByPrefix(AzureStorageSettings settings) {
            CheckSettings(settings);
            var storageAccount = new CloudStorageAccount(new StorageCredentials(settings.AccountName, settings.Key), true);
            var blobClient = storageAccount.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference(settings.ContainerName);

            var blobs = container.ListBlobs(settings.BlobName);
            foreach (var blob in blobs) {
                var blobReference = container.GetBlockBlobReference(blob.Uri.ToString());
                blobReference.Delete();
            }
        }

    }
}
{'fraction_non_alphanumeric': 0.09572649572649573, 'fraction_numerical': 0.0003944773175542406, 'mean_word_length': 2.2826931376780317, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4130591', 'n_tokens_mistral': 1766, 'n_tokens_neox': 1737, 'n_words': 460}