Ejemplo n.º 1
0
        protected async Task GenerateAzureResourceNamesAsync(
            CancellationToken cancellationToken = default
            )
        {
            // It might happen that there is no registered resource provider
            // found for specified location and/or api version to perform name
            // availability check. In these cases, we will silently ignore
            // errors and just use generated random names.
            const string notAvailableApiFormat = "Name availability APIs are not available for '{0}'";

            // KeyVault names
            try {
                _keyVaultName = await _keyVaultManagementClient
                                .GenerateAvailableNameAsync(cancellationToken);
            }
            catch (Microsoft.Rest.Azure.CloudException) {
                Log.Warning(notAvailableApiFormat, "KeyVault");
                _keyVaultName = KeyVaultMgmtClient.GenerateName();
            }

            // Storage Account names
            try {
                _storageAccountName = await _storageManagementClient
                                      .GenerateAvailableNameAsync(cancellationToken);
            }
            catch (Microsoft.Rest.Azure.CloudException) {
                Log.Warning(notAvailableApiFormat, "Storage Account");
                _storageAccountName = StorageMgmtClient.GenerateStorageAccountName();
            }

            // IoT hub names
            try {
                _iotHubName = await _iotHubManagementClient
                              .GenerateAvailableNameAsync(cancellationToken);
            }
            catch (Microsoft.Rest.Azure.CloudException) {
                Log.Warning(notAvailableApiFormat, "IoT Hub");
                _iotHubName = IotHubMgmtClient.GenerateIotHubName();
            }

            // CosmosDB names
            try {
                _cosmosDBAccountName = await _cosmosDBManagementClient
                                       .GenerateAvailableNameAsync(cancellationToken);
            }
            catch (Microsoft.Rest.Azure.CloudException) {
                Log.Warning(notAvailableApiFormat, "CosmosDB Account");
                _cosmosDBAccountName = CosmosDBMgmtClient.GenerateCosmosDBAccountName();
            }

            // Service Bus Namespace names
            try {
                _serviceBusNamespaceName = await _serviceBusManagementClient
                                           .GenerateAvailableNamespaceNameAsync(cancellationToken);
            }
            catch (Microsoft.Rest.Azure.CloudException) {
                Log.Warning(notAvailableApiFormat, "ServiceBus Namespace");
                _serviceBusNamespaceName = ServiceBusMgmtClient.GenerateNamespaceName();
            }

            // Event Hub Namespace names
            try {
                _eventHubNamespaceName = await _eventHubManagementClient
                                         .GenerateAvailableNamespaceNameAsync(cancellationToken);
            }
            catch (Microsoft.Rest.Azure.CloudException) {
                Log.Warning(notAvailableApiFormat, "EventHub Namespace");
                _eventHubNamespaceName = EventHubMgmtClient.GenerateEventHubNamespaceName();
            }

            _eventHubName = EventHubMgmtClient.GenerateEventHubName();

            // Operational Insights workspace name.
            _operationalInsightsWorkspaceName = OperationalInsightsMgmtClient.GenerateWorkspaceName();

            // Application Insights name.
            _applicationInsightsName = ApplicationInsightsMgmtClient.GenerateName();

            // AppService Plan name
            _appServicePlanName = WebSiteMgmtClient.GenerateAppServicePlanName(_applicationName);
            _azureWebsiteName   = _applicationName;

            // Networking names
            _networkSecurityGroupName = NetworkMgmtClient.GenerateNetworkSecurityGroupName();
            //_routTableName = NetworkMgmtClient.GenerateRoutTableName();
            _virtualNetworkName = NetworkMgmtClient.GenerateVirtualNetworkName();
            //_networkInterfaceName = NetworkMgmtClient.GenerateNetworkInterfaceName();
            //_publicIPAddressName = NetworkMgmtClient.GeneratePublicIPAddressName();
            //_domainNameLabel = SdkContext.RandomResourceName(_applicationName + "-", 5);

            // AKS cluster name
            _aksClusterName = AksMgmtClient.GenerateName();

            // SignalR name
            try {
                _signalRName = await _signalRManagementClient
                               .GenerateAvailableNameAsync(_resourceGroup, cancellationToken);
            }
            catch (Microsoft.Rest.Azure.CloudException) {
                Log.Warning(notAvailableApiFormat, "SignalR");
                _signalRName = SignalRMgmtClient.GenerateName();
            }
        }