Esempio n. 1
0
        /// <summary>
        /// Use a connection string to connect to a Storage account.
        ///
        /// A connection string includes the authentication information
        /// required for your application to access data in an Azure Storage
        /// account at runtime using Shared Key authorization.
        /// </summary>
        public AzureBlobAdapter(IAzureBlobSettings azureBlobSettings)
        {
            Path = new PathWrapper(this);

            AzureBlobSettingsData = azureBlobSettings;

            //authentication methods
            //https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/storage/Azure.Storage.Blobs/samples/Sample02_Auth.cs
            // Create a BlobServiceClient object which will be used to create a container client
            BlobServiceClientObject = new BlobServiceClient(azureBlobSettings.ConnectionString);

            // Make a service request to verify we've successfully authenticated
            var servicePropertiesResponse = BlobServiceClientObject.GetProperties();

            BlobServicePropertiesObject = servicePropertiesResponse.Value;

            StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(
                azureBlobSettings.StorageAccountName, azureBlobSettings.Key);

            DataLakeServiceClientObject = new DataLakeServiceClient(new Uri(azureBlobSettings.StorageAccountUrl), sharedKeyCredential);

            File      = new AzureFile(this);
            DriveInfo = new AzureDriveInfoFactory(this);
            Directory = new AzureDirectory(this);
        }
Esempio n. 2
0
        public void UploadLocalFolder(string localFolderPath, string AzureFolderPath)
        {
            //if target directory not exists create it
            if (!this.Exists(AzureFolderPath))
            {
                this.CreateDirectory(AzureFolderPath);
            }

            // Copy each file into the new directory.
            var filePaths = System.IO.Directory.EnumerateFiles(localFolderPath);

            foreach (var filePath in filePaths)
            {
                string filenameWithExt = new System.IO.FileInfo(filePath).Name;
                // filenameWithExt = filePath.Replace(localFolderPath, "");
                string azurePath = this.FileSystem.Path.Combine(AzureFolderPath, filenameWithExt);
                Debug.WriteLine(@"Copying {0} to azure {1}", filePath, azurePath);
                AzureFile azureFile = (AzureFile)this.FileSystem.File;
                azureFile.UploadToBlob(filePath, azurePath, isOverWrite: true);
            }
            // Copy each subdirectory using recursion.
            var subFolderPaths = System.IO.Directory.EnumerateDirectories(localFolderPath);

            foreach (var subFolderPath in subFolderPaths)
            {
                string folderNameOnly     = new System.IO.DirectoryInfo(subFolderPath).Name; //subFolderPath.Replace(localFolderPath, "");
                string azureSubFolderPath = this.FileSystem.Path.Combine(AzureFolderPath, folderNameOnly);
                UploadLocalFolder(subFolderPath, azureSubFolderPath);
            }
        }