public async Task createStorageAccountAndGetBlobContainerCollection() { ArmClient armClient = new ArmClient(new DefaultAzureCredential()); Subscription subscription = await armClient.GetDefaultSubscriptionAsync(); string rgName = "myRgName"; AzureLocation location = AzureLocation.WestUS2; ArmOperation <ResourceGroup> operation = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, new ResourceGroupData(location)); ResourceGroup resourceGroup = operation.Value; this.resourceGroup = resourceGroup; StorageSku sku = new StorageSku(StorageSkuName.StandardGRS); StorageKind kind = StorageKind.Storage; string locationStr = "westus2"; StorageAccountCreateParameters parameters = new StorageAccountCreateParameters(sku, kind, locationStr); StorageAccountCollection accountCollection = resourceGroup.GetStorageAccounts(); string accountName = "myAccount"; ArmOperation <StorageAccount> accountCreateOperation = await accountCollection.CreateOrUpdateAsync(WaitUntil.Started, accountName, parameters); storageAccount = await accountCreateOperation.WaitForCompletionAsync(); #region Snippet:Managing_BlobContainers_GetBlobService BlobService blobService = storageAccount.GetBlobService(); #endregion this.blobService = blobService; }
public async Task createStorageAccountAndGetBlobContainerContainer() { _resourceGroup = await CreateResourceGroupAsync(); string accountName = await CreateValidAccountNameAsync("teststoragemgmt"); StorageAccountCollection storageAccountCollection = _resourceGroup.GetStorageAccounts(); _storageAccount = (await storageAccountCollection.CreateOrUpdateAsync(accountName, GetDefaultStorageAccountParameters())).Value; _blobService = _storageAccount.GetBlobService(); _blobService = await _blobService.GetAsync(); _blobContainerCollection = _blobService.GetBlobContainers(); }
public async Task CreateGetDeleteObjectReplicationPolicy() { //create 2 storage accounts string accountName1 = await CreateValidAccountNameAsync("teststoragemgmt"); string accountName2 = await CreateValidAccountNameAsync("teststoragemgmt"); StorageAccountCreateParameters createParameters = GetDefaultStorageAccountParameters(kind: Kind.StorageV2); StorageAccount sourceAccount = (await _resourceGroup.GetStorageAccounts().CreateOrUpdateAsync(accountName1, createParameters)).Value; StorageAccount destAccount = (await _resourceGroup.GetStorageAccounts().CreateOrUpdateAsync(accountName2, createParameters)).Value; //update 2 accounts properties var updateparameter = new StorageAccountUpdateParameters { AllowCrossTenantReplication = true, EnableHttpsTrafficOnly = true }; destAccount = await destAccount.UpdateAsync(updateparameter); sourceAccount = await sourceAccount.UpdateAsync(updateparameter); BlobService blobService1 = await destAccount.GetBlobService().GetAsync(); BlobContainerCollection blobContainerCollection1 = blobService1.GetBlobContainers(); BlobService blobService2 = await destAccount.GetBlobService().GetAsync(); BlobContainerCollection blobContainerCollection2 = blobService2.GetBlobContainers(); //enable changefeed and versoning blobService1.Data.IsVersioningEnabled = true; await blobService1.CreateOrUpdateAsync(blobService1.Data); //create 2 pairs of source and dest blob containers string containerName1 = Recording.GenerateAssetName("testblob1"); string containerName2 = Recording.GenerateAssetName("testblob2"); string containerName3 = Recording.GenerateAssetName("testblob3"); string containerName4 = Recording.GenerateAssetName("testblob4"); BlobContainer container1 = (await blobContainerCollection1.CreateOrUpdateAsync(containerName1, new BlobContainerData())).Value; BlobContainer container2 = (await blobContainerCollection2.CreateOrUpdateAsync(containerName2, new BlobContainerData())).Value; BlobContainer container3 = (await blobContainerCollection1.CreateOrUpdateAsync(containerName3, new BlobContainerData())).Value; BlobContainer container4 = (await blobContainerCollection2.CreateOrUpdateAsync(containerName4, new BlobContainerData())).Value; //prepare rules and policy ObjectReplicationPolicyData parameter = new ObjectReplicationPolicyData() { SourceAccount = sourceAccount.Id.Name, DestinationAccount = destAccount.Id.Name }; List <string> prefix = new List <string>(); prefix.Add("aa"); prefix.Add("bc d"); prefix.Add("123"); string minCreationTime = "2021-03-19T16:06:00Z"; List <ObjectReplicationPolicyRule> rules = new List <ObjectReplicationPolicyRule>(); parameter.Rules.Add( new ObjectReplicationPolicyRule(containerName1, containerName2) { Filters = new ObjectReplicationPolicyFilter(prefix, minCreationTime), } ); parameter.Rules.Add( new ObjectReplicationPolicyRule(containerName3, containerName4) ); //create policy ObjectReplicationPolicyCollection objectReplicationPolicyCollection = destAccount.GetObjectReplicationPolicies(); ObjectReplicationPolicy objectReplicationPolicy = (await objectReplicationPolicyCollection.CreateOrUpdateAsync("default", parameter)).Value; Assert.NotNull(objectReplicationPolicy); Assert.AreEqual(objectReplicationPolicy.Data.DestinationAccount, destAccount.Id.Name); Assert.AreEqual(objectReplicationPolicy.Data.SourceAccount, sourceAccount.Id.Name); //get policy List <ObjectReplicationPolicy> policies = await objectReplicationPolicyCollection.GetAllAsync().ToEnumerableAsync(); objectReplicationPolicy = policies[0]; Assert.NotNull(objectReplicationPolicy); Assert.AreEqual(objectReplicationPolicy.Data.DestinationAccount, destAccount.Id.Name); Assert.AreEqual(objectReplicationPolicy.Data.SourceAccount, sourceAccount.Id.Name); //delete policy await objectReplicationPolicy.DeleteAsync(); }