Exemple #1
0
        public async Task <string> GetServiceBusNamespaceConnectionStringAsync(
            IResourceGroup resourceGroup,
            NamespaceModelInner serviceBusNamespace,
            CancellationToken cancellationToken = default
            )
        {
            try {
                Log.Verbose($"Fetching connection string for Azure Service Bus Namespace: {serviceBusNamespace.Name} ...");

                var keysList = await _serviceBusManagementClient
                               .Namespaces
                               .ListKeysAsync(
                    resourceGroup.Name,
                    serviceBusNamespace.Name,
                    SERVICE_BUS_AUTHORIZATION_RULE,
                    cancellationToken
                    );

                Log.Verbose($"Fetched connection string for Azure Service Bus Namespace: {serviceBusNamespace.Name}");

                return(keysList.PrimaryConnectionString);
            }
            catch (Exception ex) {
                Log.Error(ex, $"Failed to fetch connection string for Azure Service Bus Namespace: {serviceBusNamespace.Name}");
                throw;
            }
        }
Exemple #2
0
        public async Task <NamespaceModelInner> CreateServiceBusNamespaceAsync(
            IResourceGroup resourceGroup,
            string serviceBusNamespaceName,
            IDictionary <string, string> tags   = null,
            CancellationToken cancellationToken = default
            )
        {
            try {
                tags ??= new Dictionary <string, string>();

                Log.Information($"Creating Azure Service Bus Namespace: {serviceBusNamespaceName} ...");

                var namespaceModel = new NamespaceModelInner {
                    Location = resourceGroup.RegionName,
                    Tags     = tags,

                    Sku = new Sku {
                        Name = "Standard",
                        Tier = "Standard"
                    }
                };

                namespaceModel.Validate();

                var serviceBusNamespace = await _serviceBusManagementClient
                                          .Namespaces
                                          .CreateOrUpdateAsync(
                    resourceGroup.Name,
                    serviceBusNamespaceName,
                    namespaceModel,
                    cancellationToken
                    );

                //serviceBusAuthorizationRule = await _serviceBusManagementClient
                //    .Namespaces
                //    .GetAuthorizationRuleAsync(
                //        resourceGroup.Name,
                //        serviceBusNamespaceName,
                //        SERVICE_BUS_AUTHORIZATION_RULE,
                //        cancellationToken
                //    );

                Log.Information($"Created Azure Service Bus Namespace: {serviceBusNamespaceName}");

                return(serviceBusNamespace);
            }
            catch (Exception ex) {
                Log.Error(ex, $"Failed to create Azure Service Bus Namespace: {serviceBusNamespaceName}");
                throw;
            }
        }
Exemple #3
0
 /// <summary>
 /// Creates or updates a service namespace. Once created, this namespace's
 /// resource manifest is immutable. This operation is idempotent.
 /// <see href="https://msdn.microsoft.com/en-us/library/azure/mt639408.aspx" />
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Name of the Resource group within the Azure subscription.
 /// </param>
 /// <param name='namespaceName'>
 /// The namespace name
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to create a namespace resource.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <NamespaceModelInner> BeginCreateOrUpdateAsync(this INamespacesOperations operations, string resourceGroupName, string namespaceName, NamespaceModelInner parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, namespaceName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Exemple #4
0
        /// <summary>
        /// Gets the auth rules for a service bus and writes Application data.
        /// </summary>
        /// <param name="rgName">Name of the rg.</param>
        /// <param name="serviceBusManagementClient">The service bus management client.</param>
        /// <param name="selectedServiceBus">The selected service bus.</param>
        private void SetApplicationData(string rgName, ServiceBusManagementClient serviceBusManagementClient, NamespaceModelInner selectedServiceBus)
        {
            List <SharedAccessAuthorizationRuleInner> serviceBusAuthRuleList = new List <SharedAccessAuthorizationRuleInner>();
            var resp = serviceBusManagementClient.Namespaces.ListAuthorizationRulesAsync(rgName, selectedServiceBus.Name).ConfigureAwait(false).GetAwaiter().GetResult();

            serviceBusAuthRuleList.AddRange(resp);

            while (!string.IsNullOrEmpty(resp.NextPageLink))
            {
                resp = serviceBusManagementClient.Namespaces.ListAuthorizationRulesNextAsync(resp.NextPageLink).ConfigureAwait(false).GetAwaiter().GetResult();
                serviceBusAuthRuleList.AddRange(resp);
            }

            var selectedAuthRule = serviceBusAuthRuleList.FirstOrDefault(rule => rule.Rights != null && rule.Rights.Contains(AccessRights.Listen) && rule.Rights.Contains(AccessRights.Manage) && rule.Rights.Contains(AccessRights.Send));

            if (selectedAuthRule == null)
            {
                MessageBox.Show("Failed to find a suitable Authorization rule to use. Please create an Authorization rule with Listen, Manage and Send rights and retry the operation");
                this.Dispatcher.Invoke(() =>
                {
                    this.progressBar.Visibility = Visibility.Hidden;
                    this.btnDone.IsEnabled      = true;
                });
                return;
            }
            else
            {
                ApplicationData.Instance.ServiceBusSharedKey = serviceBusManagementClient.Namespaces.ListKeysAsync(
                    rgName,
                    selectedServiceBus.Name,
                    selectedAuthRule.Name).ConfigureAwait(false).GetAwaiter().GetResult().PrimaryKey;
                ApplicationData.Instance.ServiceBusKeyName = serviceBusManagementClient.Namespaces.ListKeysAsync(
                    rgName,
                    selectedServiceBus.Name,
                    selectedAuthRule.Name).ConfigureAwait(false).GetAwaiter().GetResult().KeyName;
                ApplicationData.Instance.ServiceBusUrl = selectedServiceBus.ServiceBusEndpoint;

                this.Dispatcher.Invoke(() =>
                {
                    MainWindow mainWindow = new MainWindow();
                    mainWindow.Show();
                    this.Close();
                });
            }
        }