public static void SetSerivceProperties(Constants.ServiceType serviceType, Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties serviceProperties) { switch (serviceType) { case Constants.ServiceType.Blob: StorageAccount.CreateCloudBlobClient().SetServiceProperties(serviceProperties); break; case Constants.ServiceType.Queue: StorageAccount.CreateCloudQueueClient().SetServiceProperties(serviceProperties); break; case Constants.ServiceType.Table: StorageAccount.CreateCloudTableClient().SetServiceProperties(serviceProperties); break; case Constants.ServiceType.File: FileServiceProperties fileProperties = new FileServiceProperties(); fileProperties.Cors = serviceProperties.Cors; fileProperties.HourMetrics = serviceProperties.HourMetrics; fileProperties.MinuteMetrics = serviceProperties.MinuteMetrics; StorageAccount.CreateCloudFileClient().SetServiceProperties(fileProperties); break; } }
public AzureFilesPatientReservoir(string connectionString, string shareName) { StorageAccount = CloudStorageAccount.Parse(connectionString); FileClient = StorageAccount.CreateCloudFileClient(); FileShare = FileClient.GetShareReference(shareName); PatientDirectory = FileShare.GetRootDirectoryReference().GetDirectoryReference(fhirFileFolder); }
private async Task FileShareClient(string shareReferenceName, string connectionString) { StorageAccount = CloudStorageAccount.Parse(connectionString); CloudFileClient fileClient = StorageAccount.CreateCloudFileClient(); Share = fileClient.GetShareReference(shareReferenceName); await Share.CreateIfNotExistsAsync(); }
public DumplingStorageAccount(string connection_string) { StorageAccount = CloudStorageAccount.Parse(connection_string); BlobClient = StorageAccount.CreateCloudBlobClient(); TableClient = StorageAccount.CreateCloudTableClient(); FileClient = StorageAccount.CreateCloudFileClient(); }
public void PipelineMultipleShareNamesTest() { // TODO: Generate more random names for file shares after the // naming rules is settled down. int numberOfShares = this.randomProvider.Next(2, 33); string[] names = Enumerable.Range(0, numberOfShares) .Select(i => CloudFileUtil.GenerateUniqueFileShareName()).ToArray(); var client = StorageAccount.CreateCloudFileClient(); // Ensure all file shares are not exists for (int i = 0; i < names.Length; i++) { while (client.GetShareReference(names[i]).Exists()) { names[i] = CloudFileUtil.GenerateUniqueFileShareName(); } } try { CommandAgent.NewFileShareFromPipeline(); var result = CommandAgent.Invoke(names); CommandAgent.AssertNoError(); result.AssertObjectCollection(obj => result.AssertCloudFileContainer(obj, new List <string>(names)), numberOfShares); } finally { foreach (string fileShareName in names) { fileUtil.DeleteFileShareIfExists(fileShareName); } } }
/// <summary> /// Run one powershell cmdlet and return the time cost in millisecond /// </summary> /// <param name="methodType">cmdlet type</param> /// <param name="sNames">a list of names(by pipeline)</param> /// <param name="prefix">the preffix of the names</param> /// <returns>The milliseconds of running the cmdlets</returns> private long DoPerfOperation(string methodType, string[] sNames, string prefix) { DoInit(methodType, sNames, prefix, ref CLIPerf.sharedObject); Stopwatch sw = new Stopwatch(); sw.Start(); switch (methodType) { case PsTag.NewContainer: { Test.Assert(CommandAgent.NewAzureStorageContainer(sNames), Utility.GenComparisonData("NewAzureStorageContainer", true)); } break; case PsTag.NewQueue: { Test.Assert(CommandAgent.NewAzureStorageQueue(sNames), Utility.GenComparisonData("NewAzureStorageQueue", true)); } break; case PsTag.NewTable: { Test.Assert(CommandAgent.NewAzureStorageTable(sNames), Utility.GenComparisonData("NewAzureStorageTable", true)); } break; case PsTag.NewShare: { Test.Assert(CommandAgent.NewFileShares(sNames), Utility.GenComparisonData("NewFileShare", true)); } break; case PsTag.NewDirectory: { Test.Assert(CommandAgent.NewDirectories(CLIPerf.sharedObject as string, sNames), Utility.GenComparisonData("NewDirectory", true)); } break; case PsTag.GetDirectory: { Test.Assert(CommandAgent.ListDirectories(CLIPerf.sharedObject as string), Utility.GenComparisonData("ListDirectory", true)); } break; case PsTag.RemoveDirectory: { Test.Assert(CommandAgent.ListDirectories(CLIPerf.sharedObject as string), Utility.GenComparisonData("ListDirectory", true)); } break; case PsTag.GetContainer: { Test.Assert(CommandAgent.GetAzureStorageContainerByPrefix(prefix), Utility.GenComparisonData("GetAzureStorageContainer", true)); } break; case PsTag.GetShare: { Test.Assert(CommandAgent.GetFileSharesByPrefix(prefix), Utility.GenComparisonData("GetFileShare", true)); } break; case PsTag.GetQueue: { Test.Assert(CommandAgent.GetAzureStorageQueueByPrefix(prefix), Utility.GenComparisonData("GetAzureStorageQueue", true)); } break; case PsTag.GetTable: { Test.Assert(CommandAgent.GetAzureStorageTableByPrefix(prefix), Utility.GenComparisonData("GetAzureStorageTable", true)); } break; case PsTag.RemoveContainer: { // use PowerShellAgent to remove a large number of containers in order to save time Test.Assert((new PowerShellAgent()).RemoveAzureStorageContainer(sNames), Utility.GenComparisonData("RemoveAzureStorageContainer", true)); } break; case PsTag.RemoveShare: { Test.Assert(CommandAgent.RemoveFileShares(sNames), Utility.GenComparisonData("RemoveFileShare", true)); } break; case PsTag.RemoveQueue: { Test.Assert(CommandAgent.RemoveAzureStorageQueue(sNames), Utility.GenComparisonData("RemoveAzureStorageQueue", true)); } break; case PsTag.RemoveTable: { Test.Assert(CommandAgent.RemoveAzureStorageTable(sNames), Utility.GenComparisonData("RemoveAzureStorageTable", true)); } break; case PsTag.SetContainerAcl: { Test.Assert(CommandAgent.SetAzureStorageContainerACL(sNames, BlobContainerPublicAccessType.Container), Utility.GenComparisonData("SetAzureStorageContainerACL", true)); } break; default: Test.Assert(false, "Wrong method type!"); break; } sw.Stop(); DoCleanup(methodType, sNames, prefix, CLIPerf.sharedObject); // Verification for returned values int nCount = sNames.Length; switch (methodType) { case PsTag.NewContainer: case PsTag.NewQueue: case PsTag.NewTable: case PsTag.NewShare: case PsTag.NewDirectory: case PsTag.SetContainerAcl: { if (!(CommandAgent is NodeJSAgent)) { // no need to check for Node.js commands as it does not support pipeline Test.Assert(CommandAgent.Output.Count == nCount, "{0} row returned : {1}", nCount, CommandAgent.Output.Count); if (CommandAgent.Output.Count != nCount) { //only for debug Test.Assert(false, "error found! terminate instantly for debug!"); Environment.Exit(0); } } } break; case PsTag.GetContainer: { CommandAgent.OutputValidation(StorageAccount.CreateCloudBlobClient().ListContainers(prefix, ContainerListingDetails.All)); } break; case PsTag.GetShare: { CommandAgent.OutputValidation(StorageAccount.CreateCloudFileClient().ListShares( prefix: prefix, detailsIncluded: Microsoft.WindowsAzure.Storage.File.ShareListingDetails.All)); } break; case PsTag.GetDirectory: { CommandAgent.OutputValidation(StorageAccount.CreateCloudFileClient().GetShareReference(CLIPerf.sharedObject as string).GetRootDirectoryReference().ListFilesAndDirectories()); } break; case PsTag.GetQueue: { CommandAgent.OutputValidation(StorageAccount.CreateCloudQueueClient().ListQueues(prefix, QueueListingDetails.All)); } break; case PsTag.GetTable: { CommandAgent.OutputValidation(StorageAccount.CreateCloudTableClient().ListTables(prefix)); } break; case PsTag.RemoveContainer: case PsTag.RemoveQueue: case PsTag.RemoveShare: case PsTag.RemoveDirectory: case PsTag.RemoveTable: { // No need to check the return object count now as it won't return any object for remove cmdlets //Test.Assert(agent.Output.Count == nContainerCount, "{0} row returned : {1}", nContainerCount, agent.Output.Count); } break; default: Test.Assert(false, "Wrong method type!"); break; } return(sw.ElapsedMilliseconds); }
public async void FileStorageTest() { ClearOutput(); WriteLine("-- Testing File Storage --"); WriteLine("0. Creating file client"); // Create a file client for interacting with the file service. CloudFileClient fileClient = StorageAccount.CreateCloudFileClient(); // Create a share for organizing files and directories within the storage account. WriteLine("1. Creating file share"); CloudFileShare share = fileClient.GetShareReference(DemoShare); try { await share.CreateIfNotExistsAsync(); } catch (StorageException) { WriteLine("Please make sure your storage account has storage file endpoint enabled and specified correctly in the app.config - then restart the sample."); throw; } // Get a reference to the root directory of the share. CloudFileDirectory root = share.GetRootDirectoryReference(); // Create a directory under the root directory WriteLine("2. Creating a directory under the root directory"); CloudFileDirectory dir = root.GetDirectoryReference(DemoDirectory); await dir.CreateIfNotExistsAsync(); // Uploading a local file to the directory created above WriteLine("3. Uploading a file to directory"); CloudFile file = dir.GetFileReference(ImageToUpload); #if WINDOWS_UWP && ENABLE_DOTNET StorageFolder storageFolder = await StorageFolder.GetFolderFromPathAsync(Application.streamingAssetsPath.Replace('/', '\\')); StorageFile sf = await storageFolder.GetFileAsync(ImageToUpload); await file.UploadFromFileAsync(sf); #else await file.UploadFromFileAsync(Path.Combine(Application.streamingAssetsPath, ImageToUpload)); #endif // List all files/directories under the root directory WriteLine("4. List Files/Directories in root directory"); List <IListFileItem> results = new List <IListFileItem>(); FileContinuationToken token = null; do { FileResultSegment resultSegment = await share.GetRootDirectoryReference().ListFilesAndDirectoriesSegmentedAsync(token); results.AddRange(resultSegment.Results); token = resultSegment.ContinuationToken; }while (token != null); // Print all files/directories listed above foreach (IListFileItem listItem in results) { // listItem type will be CloudFile or CloudFileDirectory WriteLine(string.Format("- {0} (type: {1})", listItem.Uri, listItem.GetType())); } // Download the uploaded file to your file system string path; WriteLine(string.Format("5. Download file from {0}", file.Uri.AbsoluteUri)); string fileName = string.Format("CopyOf{0}", ImageToUpload); #if WINDOWS_UWP && ENABLE_DOTNET storageFolder = ApplicationData.Current.TemporaryFolder; sf = await storageFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); path = sf.Path; await file.DownloadToFileAsync(sf); #else path = Path.Combine(Application.temporaryCachePath, fileName); await file.DownloadToFileAsync(path, FileMode.Create); #endif WriteLine("File written to " + path); // Clean up after the demo WriteLine("6. Delete file"); await file.DeleteAsync(); // When you delete a share it could take several seconds before you can recreate a share with the same // name - hence to enable you to run the demo in quick succession the share is not deleted. If you want // to delete the share uncomment the line of code below. WriteLine("7. Delete Share -- Note that it will take a few seconds before you can recreate a share with the same name"); await share.DeleteAsync(); WriteLine("-- Test Complete --"); }