private static async Task CreateCommunicationServiceAsync(CommunicationManagementClient acsClient, string resourceGroupName, string resourceName)
        {
            try
            {
                Utilities.Log("\nCommunicationService Create...");

                // Set up a CommunicationServiceResource with attributes of the resource we intend to create
                var resource = new CommunicationServiceResource {
                    Location = "global", DataLocation = "UnitedStates"
                };

                // Create a resource in the specificed resource group and waits for a response
                Utilities.Log("Waiting for acsClient.CommunicationService.StartCreateOrUpdateAsync");
                var operation = await acsClient.CommunicationService.StartCreateOrUpdateAsync(resourceGroupName, resourceName, resource);

                Utilities.Log("Gained the CommunicationServiceCreateOrUpdateOperation. Waiting for it to complete...");
                Response <CommunicationServiceResource> response = await operation.WaitForCompletionAsync();

                Utilities.Log("\tresponse: " + response.ToString());
                Utilities.Print(response.Value);
            }
            catch (Exception e)
            {
                Utilities.Log("CreateCommunicationServiceAsync encountered: " + e.Message);
            }
        }
        private static async Task UpdateCommunicationServiceAsync(CommunicationManagementClient acsClient, string resourceGroupName, string resourceName)
        {
            try
            {
                Utilities.Log("\nCommunicationService Update...");

                // Create a CommunicationServiceResource with the updated resource attributes
                var resource = new CommunicationServiceResource {
                    Location = "global", DataLocation = "UnitedStates"
                };

                var tags = new Dictionary <string, string>();
                tags.Add("ExampleTagName1", "ExampleTagValue1");
                tags.Add("ExampleTagName2", "ExampleTagValue2");

                // Update an existing resource in Azure with the attributes in `resource` and wait for a response
                Utilities.Log("Waiting for acsClient.CommunicationService.StartCreateOrUpdateAsync");
                CommunicationServiceCreateOrUpdateOperation operation = await acsClient.CommunicationService.StartCreateOrUpdateAsync(resourceGroupName, resourceName, resource);

                Utilities.Log("Gained the communicationServiceCreateOrUpdateOperation. Waiting for it to complete...");
                Response <CommunicationServiceResource> response = await operation.WaitForCompletionAsync();

                Utilities.Log("\tresponse: " + response.ToString());
                Utilities.Print(response.Value);
            }
            catch (Exception e)
            {
                Utilities.Log("UpdateCommunicationServiceAsync encountered: " + e.Message);
            }
        }
        static async Task Main(string[] args)
        {
            // User Identity
            var subscriptionId             = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
            var communicationServiceClient = new CommunicationManagementClient(subscriptionId, new InteractiveBrowserCredential());

            // System assigned Managed Identity
            //var subscriptionId = "AZURE_SUBSCRIPTION_ID";
            //var acsClient = new CommunicationManagementClient(subscriptionId, new ManagedIdentityCredential());


            // User assigned Managed Identity
            /*var subscriptionId = "AZURE_SUBSCRIPTION_ID";*/

            /*var managedIdentityCredential = new ManagedIdentityCredential("AZURE_CLIENT_ID");
             * var acsClient = new CommunicationManagementClient(subscriptionId, managedIdentityCredential);*/

            // Using Service Principal

            /*var subscriptionId = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
             * var acsClient = new CommunicationManagementClient(subscriptionId, new EnvironmentCredential());*/

            // Create a Communication Services resource
            var resourceGroupName = "myResourceGroupName";
            var resourceName      = "myResource";
            var resource          = new CommunicationServiceResource {
                Location = "Global", DataLocation = "UnitedStates"
            };
            var operation = await communicationServiceClient.CommunicationService.StartCreateOrUpdateAsync(resourceGroupName, resourceName, resource);

            await operation.WaitForCompletionAsync();
        }
Пример #4
0
        public async Task DeleteCommunicationService()
        {
            #region Snippet:Managing_CommunicationService_DeleteAnApplicationDefinition
            CommunicationServiceCollection collection = resourceGroup.GetCommunicationServices();

            CommunicationServiceResource communicationService = await collection.GetAsync("myCommunicationService");

            await communicationService.DeleteAsync(WaitUntil.Completed);

            #endregion Snippet:Managing_CommunicationService_DeleteAnApplicationDefinition
        }
        public async Task LinkNotificationHub()
        {
            // Setup resource group for the test. This resource group is deleted by CleanupResourceGroupsAsync after the test ends
            Subscription sub = await ResourcesManagementClient.GetDefaultSubscriptionAsync();

            var lro = await sub.GetResourceGroups().CreateOrUpdateAsync(
                NotificationHubsResourceGroupName,
                new ResourceGroupData(Location));

            ResourceGroup rg = lro.Value;

            CommunicationManagementClient acsClient = GetCommunicationManagementClient();
            var resourceName = Recording.GenerateAssetName("sdk-test-link-notif-hub-");

            // Create a new resource with a our test parameters
            CommunicationServiceCreateOrUpdateOperation result = await acsClient.CommunicationService.StartCreateOrUpdateAsync(
                rg.Data.Name,
                resourceName,
                new CommunicationServiceResource { Location = ResourceLocation, DataLocation = ResourceDataLocation });

            await result.WaitForCompletionAsync();

            // Check that our resource has been created successfully
            Assert.IsTrue(result.HasCompleted);
            Assert.IsTrue(result.HasValue);
            CommunicationServiceResource resource = result.Value;

            // Retrieve
            var resourceRetrieved = await acsClient.CommunicationService.GetAsync(rg.Data.Name, resourceName);

            Assert.AreEqual(
                resourceName,
                resourceRetrieved.Value.Name);
            Assert.AreEqual(
                "Succeeded",
                resourceRetrieved.Value.ProvisioningState.ToString());

            // Link NotificationHub
            var linkNotificationHubResponse = await acsClient.CommunicationService.LinkNotificationHubAsync(
                rg.Data.Name,
                resourceName,
                new LinkNotificationHubParameters(NotificationHubsResourceId, NotificationHubsConnectionString));

            Assert.AreEqual(NotificationHubsResourceId, linkNotificationHubResponse.Value.ResourceId);

            // Delete
            CommunicationServiceDeleteOperation deleteResult = await acsClient.CommunicationService.StartDeleteAsync(rg.Data.Name, resourceName);

            await deleteResult.WaitForCompletionAsync();

            // Check that our resource has been deleted successfully
            Assert.IsTrue(deleteResult.HasCompleted);
            Assert.IsTrue(deleteResult.HasValue);
        }
        public async Task LinkNotificationHub()
        {
            // Create communication service
            string communicationServiceName       = Recording.GenerateAssetName("communication-service-");
            CommunicationServiceResource resource = await CreateDefaultCommunicationServices(communicationServiceName, _resourceGroup);

            // Link NotificationHub
            var linkNotificationHubResponse = await resource.LinkNotificationHubAsync(
                new LinkNotificationHubContent(_notificationHubsResourceId, _notificationHubsConnectionString));

            Assert.AreEqual(_notificationHubsResourceId, linkNotificationHubResponse.Value.ResourceId);
        }
Пример #7
0
        public async Task CreateCommunicationService()
        {
            #region Snippet:Managing_CommunicationService_CreateAnApplicationDefinition
            CommunicationServiceResourceCollection collection = resourceGroup.GetCommunicationServiceResources();
            string communicationServiceName       = "myCommunicationService";
            CommunicationServiceResourceData data = new CommunicationServiceResourceData("global")
            {
                DataLocation = "UnitedStates",
            };
            ArmOperation <CommunicationServiceResource> communicationServiceLro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, communicationServiceName, data);

            CommunicationServiceResource communicationService = communicationServiceLro.Value;
            #endregion Snippet:Managing_CommunicationService_CreateAnApplicationDefinition
        }
        public async Task CheckNameUniqueness()
        {
            // Setup resource group for the test. This resource group is deleted by CleanupResourceGroupsAsync after the test ends
            Subscription sub = await ResourcesManagementClient.GetDefaultSubscriptionAsync();

            var lro = await sub.GetResourceGroups().CreateOrUpdateAsync(
                Recording.GenerateAssetName(ResourceGroupPrefix),
                new ResourceGroupData(Location));

            ResourceGroup rg = lro.Value;

            CommunicationManagementClient acsClient = GetCommunicationManagementClient();
            var resourceName = Recording.GenerateAssetName("sdk-test-name-availablity-");

            // Check if name is unique
            Response <NameAvailability> nameAvailabilityResult = await acsClient.CommunicationService.CheckNameAvailabilityAsync(new NameAvailabilityParameters("Microsoft.Communication/CommunicationServices", resourceName));

            Assert.IsTrue(nameAvailabilityResult.Value.NameAvailable);

            // Create a new resource with a our test parameters
            CommunicationServiceCreateOrUpdateOperation result = await acsClient.CommunicationService.StartCreateOrUpdateAsync(
                rg.Data.Name, resourceName,
                new CommunicationServiceResource { Location = ResourceLocation, DataLocation = ResourceDataLocation });

            await result.WaitForCompletionAsync();

            // Check that our resource has been created successfully
            Assert.IsTrue(result.HasCompleted);
            Assert.IsTrue(result.HasValue);
            CommunicationServiceResource resource = result.Value;

            // Retrieve
            var resourceRetrieved = await acsClient.CommunicationService.GetAsync(rg.Data.Name, resourceName);

            Assert.AreEqual(
                resourceName,
                resourceRetrieved.Value.Name);
            Assert.AreEqual(
                "Succeeded",
                resourceRetrieved.Value.ProvisioningState.ToString());

            // Check if name is unique
            nameAvailabilityResult = await acsClient.CommunicationService.CheckNameAvailabilityAsync(new NameAvailabilityParameters("Microsoft.Communication/CommunicationServices", resourceName));

            Assert.IsFalse(nameAvailabilityResult.Value.NameAvailable);
        }
        public async Task ListByRg()
        {
            // Setup resource group for the test. This resource group is deleted by CleanupResourceGroupsAsync after the test ends
            Subscription sub = await ResourcesManagementClient.GetDefaultSubscriptionAsync();

            var lro = await sub.GetResourceGroups().CreateOrUpdateAsync(
                Recording.GenerateAssetName(ResourceGroupPrefix),
                new ResourceGroupData(Location));

            ResourceGroup rg = lro.Value;

            // Create a new resource with the test parameters
            CommunicationManagementClient acsClient = GetCommunicationManagementClient();
            var resourceName = Recording.GenerateAssetName("sdk-test-list-by-rg-");
            var testResource = new CommunicationServiceResource {
                Location = ResourceLocation, DataLocation = ResourceDataLocation
            };

            CommunicationServiceCreateOrUpdateOperation result = await acsClient.CommunicationService.StartCreateOrUpdateAsync(
                rg.Data.Name,
                resourceName,
                testResource);

            await result.WaitForCompletionAsync();

            Assert.IsTrue(result.HasCompleted);
            Assert.IsTrue(result.HasValue);

            // Verify that the resource we just created is in the list
            var  resources     = acsClient.CommunicationService.ListByResourceGroupAsync(rg.Data.Name);
            bool resourceFound = false;

            await foreach (var resource in resources)
            {
                if (resource.Name.Equals(resourceName))
                {
                    resourceFound = true;
                    break;
                }
            }
            Assert.True(resourceFound);
        }
        public static void Print(CommunicationServiceResource resource)
        {
            StringBuilder info = new StringBuilder();

            info.Append("CommunicationServiceResource")
            .Append("\n\t Name: ").Append(resource.Name)
            .Append("\n\t ProvisioningState: ").Append(resource.ProvisioningState)
            .Append("\n\t HostName: ").Append(resource.HostName)
            .Append("\n\t DataLocation: ").Append(resource.DataLocation)
            .Append("\n\t NotificationHubId: ").Append(resource.NotificationHubId)
            .Append("\n\t ImmutableResourceId: ").Append(resource.ImmutableResourceId)
            .Append("\n\t Location: ").Append(resource.Location);

            string tags = "None";

            if (resource.Tags != null)
            {
                tags = string.Join(", ", resource.Tags.Select(kvp => kvp.Key + ": " + kvp.Value.ToString()));
            }
            info.Append("Tags: " + tags);

            Utilities.Log(info.ToString());
        }
Пример #11
0
        public async Task CrudSimpleResource()
        {
            // Setup resource group for the test. This resource group is deleted by CleanupResourceGroupsAsync after the test ends
            ResourceGroup rg = await ResourcesManagementClient.ResourceGroups.CreateOrUpdateAsync(
                Recording.GenerateAssetName(ResourceGroupPrefix),
                new ResourceGroup(Location));

            CommunicationManagementClient acsClient = GetCommunicationManagementClient();
            var resourceName = Recording.GenerateAssetName("sdk-test-crud-simple-");

            // Create a new resource with a our test parameters
            CommunicationServiceCreateOrUpdateOperation result = await acsClient.CommunicationService.StartCreateOrUpdateAsync(
                rg.Name,
                resourceName,
                new CommunicationServiceResource { Location = ResourceLocation, DataLocation = ResourceDataLocation });

            await result.WaitForCompletionAsync();

            // Check that our resource has been created successfully
            Assert.IsTrue(result.HasCompleted);
            Assert.IsTrue(result.HasValue);
            CommunicationServiceResource resource = result.Value;

            // Check that the keys are there.
            // Note: These values have been sanitized.
            var keys = await acsClient.CommunicationService.ListKeysAsync(rg.Name, resourceName);

            Assert.NotNull(keys.Value.PrimaryKey);
            Assert.NotNull(keys.Value.SecondaryKey);
            Assert.NotNull(keys.Value.PrimaryConnectionString);
            Assert.NotNull(keys.Value.SecondaryConnectionString);

            keys = await acsClient.CommunicationService.RegenerateKeyAsync(rg.Name, resourceName, new RegenerateKeyParameters { KeyType = KeyType.Primary });

            Assert.NotNull(keys.Value.PrimaryKey);
            Assert.Null(keys.Value.SecondaryKey);
            Assert.NotNull(keys.Value.PrimaryConnectionString);
            Assert.Null(keys.Value.SecondaryConnectionString);

            keys = await acsClient.CommunicationService.RegenerateKeyAsync(rg.Name, resourceName, new RegenerateKeyParameters { KeyType = KeyType.Secondary });

            Assert.Null(keys.Value.PrimaryKey);
            Assert.NotNull(keys.Value.SecondaryKey);
            Assert.Null(keys.Value.PrimaryConnectionString);
            Assert.NotNull(keys.Value.SecondaryConnectionString);

            // Retrieve
            var resourceRetrieved = await acsClient.CommunicationService.GetAsync(rg.Name, resourceName);

            Assert.AreEqual(
                resourceName,
                resourceRetrieved.Value.Name);
            Assert.AreEqual(
                "Succeeded",
                resourceRetrieved.Value.ProvisioningState.ToString());

            // Update
            CommunicationServiceResource emptyResource = new CommunicationServiceResource();

            resource = await acsClient.CommunicationService.UpdateAsync(
                rg.Name,
                resourceName,
                emptyResource);

            Assert.True(resource.Tags.Count == 0);

            // Delete
            CommunicationServiceDeleteOperation deleteResult = await acsClient.CommunicationService.StartDeleteAsync(rg.Name, resourceName);

            await deleteResult.WaitForCompletionAsync();

            // Check that our resource has been deleted successfully
            Assert.IsTrue(deleteResult.HasCompleted);
            Assert.IsTrue(deleteResult.HasValue);
        }
Пример #12
0
        public async Task CrudResourceWithTags()
        {
            // Setup resource group for the test. This resource group is deleted by CleanupResourceGroupsAsync after the test ends
            ResourceGroup rg = await ResourcesManagementClient.ResourceGroups.CreateOrUpdateAsync(
                Recording.GenerateAssetName(ResourceGroupPrefix),
                new ResourceGroup(Location));

            CommunicationManagementClient acsClient = GetCommunicationManagementClient();
            var resourceName = Recording.GenerateAssetName("sdk-test-crud-with-tags-");

            // Create a new resource with a our test parameters
            CommunicationServiceResource serviceResource = new CommunicationServiceResource {
                Location = ResourceLocation, DataLocation = ResourceDataLocation
            };

            serviceResource.Tags.Add("tag1", "tag1val");
            serviceResource.Tags.Add("tag2", "tag2val");
            CommunicationServiceCreateOrUpdateOperation result = await acsClient.CommunicationService.StartCreateOrUpdateAsync(
                rg.Name,
                resourceName,
                serviceResource);

            await result.WaitForCompletionAsync();

            // Check that our resource has been created successfully
            Assert.IsTrue(result.HasCompleted);
            Assert.IsTrue(result.HasValue);
            CommunicationServiceResource resource = result.Value;

            Assert.AreEqual("tag1val", resource.Tags["tag1"]);
            Assert.AreEqual("tag2val", resource.Tags["tag2"]);
            Assert.IsFalse(resource.Tags.ContainsKey("tag3"));

            // Check that the keys are there.
            // Note: These values have been sanitized.
            var keys = await acsClient.CommunicationService.ListKeysAsync(rg.Name, resourceName);

            Assert.NotNull(keys.Value.PrimaryKey);
            Assert.NotNull(keys.Value.SecondaryKey);
            Assert.NotNull(keys.Value.PrimaryConnectionString);
            Assert.NotNull(keys.Value.SecondaryConnectionString);

            // Retrieve
            var resourceRetrieved = await acsClient.CommunicationService.GetAsync(rg.Name, resourceName);

            Assert.AreEqual(
                resourceName,
                resourceRetrieved.Value.Name);
            Assert.AreEqual(
                "Succeeded",
                resourceRetrieved.Value.ProvisioningState.ToString());;
            Assert.AreEqual(
                resource.Tags as IEnumerable <KeyValuePair <string, string> >,
                resourceRetrieved.Value.Tags as IEnumerable <KeyValuePair <string, string> >);

            // Update
            resource.Tags.Remove("tag1");
            resource.Tags["tag2"] = "tag2newval";
            resource.Tags.Add("tag3", "tag3val");

            resource = await acsClient.CommunicationService.UpdateAsync(
                rg.Name,
                resourceName,
                resource);

            Assert.False(resource.Tags.ContainsKey("tag1"));
            Assert.AreEqual("tag2newval", resource.Tags["tag2"]);
            Assert.AreEqual("tag3val", resource.Tags["tag3"]);

            // Delete
            CommunicationServiceDeleteOperation deleteResult = await acsClient.CommunicationService.StartDeleteAsync(rg.Name, resourceName);

            await deleteResult.WaitForCompletionAsync();

            // Check that our resource has been deleted successfully
            Assert.IsTrue(deleteResult.HasCompleted);
            Assert.IsTrue(deleteResult.HasValue);
        }