Exemplo n.º 1
0
        //--//

        public bool GetInputs(out CloudWebDeployInputs result)
        {
            result = new CloudWebDeployInputs( );

            result.Credentials = AzureConsoleHelper.GetUserSubscriptionCredentials( );
            if (result.Credentials == null)
            {
                result = null;
                return(false);
            }

            ServiceBusNamespace selectedNamespace = AzureConsoleHelper.SelectNamespace(result.Credentials);

            if (selectedNamespace == null)
            {
                result = null;
                Console.WriteLine("Quiting...");
                return(false);
            }
            result.NamePrefix = selectedNamespace.Name;
            result.Location   = selectedNamespace.Region;

            result.SBNamespace        = result.NamePrefix + "-ns";
            result.StorageAccountName = result.NamePrefix.ToLowerInvariant( ) + "storage";

            result.EventHubNameDevices = "ehdevices";
            result.EventHubNameAlerts  = "ehalerts";

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new service bus namespace.
        /// </summary>
        /// <param name="subscriptionId">The user subscription id</param>
        /// <param name="name">The namespace name</param>
        /// <param name="region">The region name</param>
        /// <returns>The created service bus namespace</returns>
        public override void ExecuteCmdlet()
        {
            ServiceBusNamespace namespaceDescription = null;
            string subscriptionId = CurrentSubscription.SubscriptionId;
            string name           = Name;
            string region         = string.IsNullOrEmpty(Location) ? GetDefaultLocation() : Location;

            if (!Regex.IsMatch(name, ServiceBusConstants.NamespaceNamePattern))
            {
                throw new ArgumentException(string.Format(Resources.InvalidNamespaceName, name), "Name");
            }

            if (!Channel.ListServiceBusRegions(subscriptionId)
                .Exists(r => r.Code.Equals(region, StringComparison.OrdinalIgnoreCase)))
            {
                throw new ArgumentException(string.Format(Resources.InvalidServiceBusLocation, region), "Location");
            }

            try
            {
                namespaceDescription = new ServiceBusNamespace {
                    Region = region
                };
                namespaceDescription = Channel.CreateServiceBusNamespace(subscriptionId, namespaceDescription, name);
                WriteObject(namespaceDescription);
            }
            catch (Exception ex)
            {
                if (ex.Message.Equals(Resources.InternalServerErrorMessage))
                {
                    throw new Exception(Resources.NewNamespaceErrorMessage);
                }
            }
        }
Exemplo n.º 3
0
        public async Task CreateDeleteNamespace()
        {
            IgnoreTestInLiveMode();
            //create namespace and wait for completion
            string namespaceName = await CreateValidNamespaceName(namespacePrefix);

            _resourceGroup = await CreateResourceGroupAsync();

            ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces();
            ServiceBusNamespace           serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(true, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value;

            VerifyNamespaceProperties(serviceBusNamespace, true);

            //validate if created successfully
            serviceBusNamespace = await namespaceCollection.GetAsync(namespaceName);

            Assert.IsTrue(await namespaceCollection.ExistsAsync(namespaceName));
            VerifyNamespaceProperties(serviceBusNamespace, true);

            //delete namespace
            await serviceBusNamespace.DeleteAsync(true);

            //validate if deleted successfully
            serviceBusNamespace = await namespaceCollection.GetIfExistsAsync(namespaceName);

            Assert.IsNull(serviceBusNamespace);
            Assert.IsFalse(await namespaceCollection.ExistsAsync(namespaceName));
        }
Exemplo n.º 4
0
        public async Task GetAllNamespaces()
        {
            IgnoreTestInLiveMode();
            //create two namespaces
            _resourceGroup = await CreateResourceGroupAsync();

            ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces();
            string namespaceName1 = await CreateValidNamespaceName(namespacePrefix);

            _ = (await namespaceCollection.CreateOrUpdateAsync(true, namespaceName1, new ServiceBusNamespaceData(DefaultLocation))).Value;
            string namespaceName2 = await CreateValidNamespaceName(namespacePrefix);

            _ = (await namespaceCollection.CreateOrUpdateAsync(true, namespaceName2, new ServiceBusNamespaceData(DefaultLocation))).Value;
            int count = 0;
            ServiceBusNamespace namespace1 = null;
            ServiceBusNamespace namespace2 = null;

            //validate
            await foreach (ServiceBusNamespace serviceBusNamespace in namespaceCollection.GetAllAsync())
            {
                count++;
                if (serviceBusNamespace.Id.Name == namespaceName1)
                {
                    namespace1 = serviceBusNamespace;
                }
                if (serviceBusNamespace.Id.Name == namespaceName2)
                {
                    namespace2 = serviceBusNamespace;
                }
            }
            Assert.AreEqual(count, 2);
            VerifyNamespaceProperties(namespace1, true);
            VerifyNamespaceProperties(namespace2, true);
        }
Exemplo n.º 5
0
        //--//

        public bool GetInputs(out CloudWebDeployInputs result)
        {
            result = new CloudWebDeployInputs( );

            result.Credentials = AzureConsoleHelper.GetUserSubscriptionCredentials( );
            if (result.Credentials == null)
            {
                result = null;
                return(false);
            }

            ServiceBusNamespace selectedNamespace = AzureConsoleHelper.SelectNamespace(result.Credentials);

            if (selectedNamespace == null)
            {
                result = null;
                Console.WriteLine("Quiting...");
                return(false);
            }
            result.NamePrefix = selectedNamespace.Name;
            if (result.NamePrefix.EndsWith("-ns"))
            {
                result.NamePrefix = result.NamePrefix.Substring(0, result.NamePrefix.Length - 3);
            }

            result.SBNamespace        = selectedNamespace.Name;
            result.StorageAccountName = result.NamePrefix.ToLowerInvariant( ) + "storage";

            result.Location = selectedNamespace.Region;

            return(true);
        }
Exemplo n.º 6
0
        public ExtendedServiceBusNamespace(
            ServiceBusNamespace serviceBusNamespace,
            IList <NamespaceDescription> descriptions)
        {
            Name = serviceBusNamespace.Name;

            Region = serviceBusNamespace.Region;

            Status = serviceBusNamespace.Status;

            CreatedAt = serviceBusNamespace.CreatedAt;

            AcsManagementEndpoint = serviceBusNamespace.AcsManagementEndpoint != null?serviceBusNamespace.AcsManagementEndpoint.ToString() : string.Empty;

            ServiceBusEndpoint = serviceBusNamespace.ServiceBusEndpoint != null?serviceBusNamespace.ServiceBusEndpoint.ToString() : string.Empty;

            if (descriptions != null && descriptions.Count != 0)
            {
                NamespaceDescription desc = descriptions.FirstOrDefault();
                DefaultKey       = this.GetKeyFromConnectionString(desc.ConnectionString);
                ConnectionString = desc.ConnectionString;
            }
            else
            {
                DefaultKey       = string.Empty;
                ConnectionString = string.Empty;
            }
        }
Exemplo n.º 7
0
        //--//

        public bool GetInputs(out ClearResourcesInputs result)
        {
            result = new ClearResourcesInputs( );

            result.Credentials = AzureConsoleHelper.GetUserSubscriptionCredentials( );
            if (result.Credentials == null)
            {
                result = null;
                return(false);
            }

            ServiceBusNamespace selectedNamespace = AzureConsoleHelper.SelectNamespace(result.Credentials,
                                                                                       "Please select namespace you want to clear resources for: ", "Enter manually (if Namespace was deleted but there are resources with the same name prefix).");

            if (selectedNamespace == null)
            {
                result = null;
                Console.WriteLine("Quiting...");
                return(false);
            }
            result.NamePrefix = selectedNamespace.Name;

            if (selectedNamespace.Region != null)
            {
                result.NamespaceExists = true;
                result.Location        = selectedNamespace.Region;
            }

            result.SBNamespace        = result.NamePrefix + "-ns";
            result.StorageAccountName = result.NamePrefix.ToLowerInvariant( ) + "storage";

            return(true);
        }
Exemplo n.º 8
0
        public async Task UpdateNamespace()
        {
            IgnoreTestInLiveMode();
            //create namespace
            string namespaceName = await CreateValidNamespaceName(namespacePrefix);

            _resourceGroup = await CreateResourceGroupAsync();

            ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces();
            ServiceBusNamespace           serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(true, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value;

            VerifyNamespaceProperties(serviceBusNamespace, true);

            //update namespace
            ServiceBusNamespaceUpdateOptions parameters = new ServiceBusNamespaceUpdateOptions(DefaultLocation);

            parameters.Tags.Add("key1", "value1");
            parameters.Tags.Add("key2", "value2");
            serviceBusNamespace = await serviceBusNamespace.UpdateAsync(parameters);

            //validate
            Assert.AreEqual(serviceBusNamespace.Data.Tags.Count, 2);
            Assert.AreEqual("value1", serviceBusNamespace.Data.Tags["key1"]);
            Assert.AreEqual("value2", serviceBusNamespace.Data.Tags["key2"]);

            //wait until provision state is succeeded
            await GetSucceededNamespace(serviceBusNamespace);
        }
Exemplo n.º 9
0
        public void NewAzureSBNamespaceSuccessfull()
        {
            // Setup
            SimpleServiceBusManagement channel            = new SimpleServiceBusManagement();
            MockCommandRuntime         mockCommandRuntime = new MockCommandRuntime();
            string name     = "test";
            string location = "West US";
            NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand(channel)
            {
                Name = name, Location = location, CommandRuntime = mockCommandRuntime
            };
            ServiceBusNamespace expected = new ServiceBusNamespace {
                Name = name, Region = location
            };

            channel.CreateServiceBusNamespaceThunk = csbn => { return(expected); };
            channel.ListServiceBusRegionsThunk     = lsbr =>
            {
                List <ServiceBusRegion> list = new List <ServiceBusRegion>();
                list.Add(new ServiceBusRegion {
                    Code = location
                });
                return(list);
            };

            // Test
            cmdlet.ExecuteCmdlet();

            // Assert
            ServiceBusNamespace actual = mockCommandRuntime.OutputPipeline[0] as ServiceBusNamespace;

            Assert.AreEqual <ServiceBusNamespace>(expected, actual);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates a new service bus namespace.
        /// </summary>
        /// <param name="subscriptionId">The user subscription id</param>
        /// <param name="name">The namespace name</param>
        /// <param name="region">The region name</param>
        /// <returns>The created service bus namespace</returns>
        public override void ExecuteCmdlet()
        {
            ServiceBusNamespace namespaceDescription = null;
            string subscriptionId = CurrentSubscription.SubscriptionId;
            string name           = Name;
            string region         = Location;

            if (!Regex.IsMatch(name, ServiceBusConstants.NamespaceNamePattern))
            {
                throw new ArgumentException(string.Format(Resources.InvalidNamespaceName, name), "Name");
            }

            if (!Channel.ListServiceBusRegions(subscriptionId).Contains(new ServiceBusRegion {
                Code = region
            }))
            {
                throw new ArgumentException(string.Format(Resources.InvalidServiceBusLocation, region), "Location");
            }

            try
            {
                namespaceDescription = new ServiceBusNamespace {
                    Region = region
                };
                namespaceDescription = Channel.CreateServiceBusNamespace(subscriptionId, namespaceDescription, name);
                WriteObject(namespaceDescription);
            }
            catch (Exception ex)
            {
                if (ex.Message.Equals(Resources.InternalServerErrorMessage))
                {
                    throw new Exception(Resources.NewNamespaceErrorMessage);
                }
            }
        }
Exemplo n.º 11
0
        private List <ServiceBusNamespace> ReadServiceBusNamespaces(IResourceGroup resourceGroup)
        {
            var serviceBusNamespaces = new List <ServiceBusNamespace>();

            try
            {
                var azureServiceBusNamespaces = _azure.ServiceBusNamespaces.ListByResourceGroup(resourceGroup.Name);
                foreach (var azureServiceBusNamespace in azureServiceBusNamespaces)
                {
                    var serviceBusNamespace = new ServiceBusNamespace(azureServiceBusNamespace);
                    foreach (var queue in azureServiceBusNamespace.Queues.List())
                    {
                        serviceBusNamespace.AddQueue(new ServiceBusQueue {
                            Name = queue.Name
                        });
                    }
                    foreach (var topic in azureServiceBusNamespace.Topics.List())
                    {
                        serviceBusNamespace.AddTopic(new ServiceBusTopic {
                            Name = topic.Name
                        });
                    }
                    serviceBusNamespaces.Add(serviceBusNamespace);
                }
            }
            catch (Exception ex)
            {
                _logger.LogException(ex);
            };
            return(serviceBusNamespaces);
        }
 public async Task CreateOrUpdate()
 {
     #region Snippet:Managing_ServiceBusNamespaces_CreateNamespace
     string namespaceName = "myNamespace";
     ServiceBusNamespaceCollection namespaceCollection = resourceGroup.GetServiceBusNamespaces();
     AzureLocation       location            = AzureLocation.EastUS2;
     ServiceBusNamespace serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(true, namespaceName, new ServiceBusNamespaceData(location))).Value;
     #endregion
 }
        public async Task Get()
        {
            #region Snippet:Managing_ServiceBusNamespaces_GetNamespace
            ServiceBusNamespaceCollection namespaceCollection = resourceGroup.GetServiceBusNamespaces();
            ServiceBusNamespace           serviceBusNamespace = await namespaceCollection.GetAsync("myNamespace");

            Console.WriteLine(serviceBusNamespace.Id.Name);
            #endregion
        }
Exemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyRotationConfig" /> class.
        /// </summary>
        /// <param name="keyVault">The config to represent a Azure Key Vault secret.</param>
        /// <param name="servicePrincipal">The config to authenticate to Azure resources.</param>
        /// <param name="serviceBusNamespace">The config to represent a Azure Service Bus namespace.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when the <paramref name="keyVault"/>, <paramref name="servicePrincipal"/>, or <paramref name="serviceBusNamespace"/> is <c>null</c>.
        /// </exception>
        public KeyRotationConfig(KeyVaultConfig keyVault, ServicePrincipal servicePrincipal, ServiceBusNamespace serviceBusNamespace)
        {
            Guard.NotNull(keyVault, nameof(keyVault));
            Guard.NotNull(servicePrincipal, nameof(servicePrincipal));
            Guard.NotNull(serviceBusNamespace, nameof(serviceBusNamespace));

            KeyVault            = keyVault;
            ServicePrincipal    = servicePrincipal;
            ServiceBusNamespace = serviceBusNamespace;
        }
        public async Task Delete()
        {
            #region Snippet:Managing_ServiceBusNamespaces_DeleteNamespace
            ServiceBusNamespaceCollection namespaceCollection = resourceGroup.GetServiceBusNamespaces();
            ServiceBusNamespace           serviceBusNamespace = await namespaceCollection.GetAsync("myNamespace");

            await serviceBusNamespace.DeleteAsync(true);

            #endregion
        }
Exemplo n.º 16
0
        //--//

        public bool GetInputs(out CloudWebDeployInputs result)
        {
            result = new CloudWebDeployInputs( );

            result.Credentials = AzureConsoleHelper.GetUserSubscriptionCredentials( );
            if (result.Credentials == null)
            {
                result = null;
                return(false);
            }

            ServiceBusNamespace selectedNamespace = AzureConsoleHelper.SelectNamespace(result.Credentials);

            if (selectedNamespace == null)
            {
                result = null;
                Console.WriteLine("Quiting...");
                return(false);
            }
            result.NamePrefix = selectedNamespace.Name;
            result.Location   = selectedNamespace.Region;

/*
 *          Console.WriteLine( "Need to select or not Transform flag." );
 *          Console.WriteLine( "If selected, the input and output file name will be \"web.config\" placed in Web project location." );
 *          Console.WriteLine( "Otherwise, input file name will be \"web.PublishTemplate.config\" and output - \"" +
 *              String.Format("web.{0}.config", result.NamePrefix) + "\".");
 *
 *          for( ;; )
 *          {
 *              Console.WriteLine( "Do you want to use Transform flag? (y/n)" );
 *
 *              string answer = Console.ReadLine( );
 *              string request = "not use";
 *              result.Transform = false;
 *              if( !string.IsNullOrEmpty( answer ) && answer.ToLower( ).StartsWith( "y" ) )
 *              {
 *                  result.Transform = true;
 *                  request = "use";
 *              }
 *              if( ConsoleHelper.Confirm( "Are you sure you want to " + request + " Transform flag?" ) )
 *              {
 *                  break;
 *              }
 *          }
 */
            result.SBNamespace        = result.NamePrefix + "-ns";
            result.StorageAccountName = result.NamePrefix.ToLowerInvariant( ) + "storage";

            result.EventHubNameDevices = "ehdevices";
            result.EventHubNameAlerts  = "ehalerts";

            //result.WebSiteDirectory = "..\\..\\..\\..\\WebSite\\ConnectTheDotsWebSite"; // Default for running the tool from the bin/debug or bin/release directory (i.e within VS)
            return(true);
        }
Exemplo n.º 17
0
        public IAsyncResult BeginCreateServiceBusNamespace(string subscriptionId, ServiceBusNamespace namespaceDescription, string name, AsyncCallback callback, object state)
        {
            SimpleServiceManagementAsyncResult result = new SimpleServiceManagementAsyncResult();

            result.Values["subscriptionId"]       = subscriptionId;
            result.Values["namespaceDescription"] = namespaceDescription;
            result.Values["name"]     = name;
            result.Values["callback"] = callback;
            result.Values["state"]    = state;

            return(result);
        }
        public static string ServiceBusNamespaceAsString(ServiceBusNamespace ns)
        {
            var sb = new StringBuilder();

            sb.AppendLine("Name: ".PadRight(30) + ns.Name);
            sb.AppendLine("Region: ".PadRight(30) + ns.Region);
            sb.AppendLine("NamespaceType: ".PadRight(30) + ns.NamespaceType);
            sb.AppendLine("ServiceBusEndpoint: ".PadRight(30) + ns.ServiceBusEndpoint);
            sb.AppendLine("Status: ".PadRight(30) + ns.Status);
            sb.AppendLine("CreatedAt: ".PadRight(30) + ns.CreatedAt);
            return(sb.ToString());
        }
Exemplo n.º 19
0
        public async Task <IActionResult> OnGetAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ServiceBusNamespace = await _context.ServiceBusNamespace.FirstOrDefaultAsync(m => m.Namespace == id);

            if (ServiceBusNamespace == null)
            {
                return(NotFound());
            }
            return(Page());
        }
 public static void VerifyNamespaceProperties(ServiceBusNamespace sBNamespace, bool useDefaults)
 {
     Assert.NotNull(sBNamespace);
     Assert.NotNull(sBNamespace.Id);
     Assert.NotNull(sBNamespace.Id.Name);
     Assert.NotNull(sBNamespace.Data);
     Assert.NotNull(sBNamespace.Data.Location);
     Assert.NotNull(sBNamespace.Data.CreatedAt);
     Assert.NotNull(sBNamespace.Data.Sku);
     if (useDefaults)
     {
         Assert.AreEqual(DefaultLocation, sBNamespace.Data.Location);
         Assert.AreEqual(SkuTier.Standard, sBNamespace.Data.Sku.Tier);
     }
 }
Exemplo n.º 21
0
        public static ServiceBusNamespace[] GetNamespaces(SubscriptionCloudCredentials creds)
        {
            var sbMgmt          = new ServiceBusManagementClient(creds);
            var regionsResponse = sbMgmt.Namespaces.ListAsync( ).Result;

            int currentNamespace = 0, namespaceCount = regionsResponse.Count( );

            ServiceBusNamespace[] namespaces = new ServiceBusNamespace[namespaceCount];
            foreach (var region in regionsResponse)
            {
                namespaces[currentNamespace++] = region;
            }

            return(namespaces);
        }
Exemplo n.º 22
0
        public async Task CreateGetDeletePrivateEndPointConnection()
        {
            //create namespace
            _resourceGroup = await CreateResourceGroupAsync();

            ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces();
            string namespaceName = await CreateValidNamespaceName(namespacePrefix);

            ServiceBusNamespace serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(true, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value;
            PrivateEndpointConnectionCollection privateEndpointConnectionCollection = serviceBusNamespace.GetPrivateEndpointConnections();

            //create another namespace for connection
            string namespaceName2 = await CreateValidNamespaceName(namespacePrefix);

            ServiceBusNamespace serviceBusNamespace2 = (await namespaceCollection.CreateOrUpdateAsync(true, namespaceName2, new ServiceBusNamespaceData(DefaultLocation))).Value;

            //create an endpoint connection
            string connectionName = Recording.GenerateAssetName("endpointconnection");
            PrivateEndpointConnectionData parameter = new PrivateEndpointConnectionData()
            {
                PrivateEndpoint = new WritableSubResource()
                {
                    Id = serviceBusNamespace2.Id
                }
            };
            PrivateEndpointConnection privateEndpointConnection = (await privateEndpointConnectionCollection.CreateOrUpdateAsync(true, connectionName, parameter)).Value;

            Assert.NotNull(privateEndpointConnection);
            Assert.AreEqual(privateEndpointConnection.Data.PrivateEndpoint.Id, serviceBusNamespace2.Id.ToString());
            connectionName = privateEndpointConnection.Id.Name;

            //get the endpoint connection and validate
            privateEndpointConnection = await privateEndpointConnectionCollection.GetAsync(connectionName);

            Assert.NotNull(privateEndpointConnection);
            Assert.AreEqual(privateEndpointConnection.Data.PrivateEndpoint.Id, serviceBusNamespace2.Id.ToString());

            //get all endpoint connections and validate
            List <PrivateEndpointConnection> privateEndpointConnections = await privateEndpointConnectionCollection.GetAllAsync().ToEnumerableAsync();

            Assert.AreEqual(privateEndpointConnections, 1);
            Assert.AreEqual(privateEndpointConnections.First().Data.PrivateEndpoint.Id, serviceBusNamespace2.Id.ToString());

            //delete endpoint connection and validate
            await privateEndpointConnection.DeleteAsync(true);

            Assert.IsFalse(await privateEndpointConnectionCollection.ExistsAsync(connectionName));
        }
Exemplo n.º 23
0
        public async Task GetPrivateLinkResources()
        {
            IgnoreTestInLiveMode();
            //create namespace
            _resourceGroup = await CreateResourceGroupAsync();

            ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces();
            string namespaceName = await CreateValidNamespaceName(namespacePrefix);

            ServiceBusNamespace serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value;

            //get private link resource
            IReadOnlyList <PrivateLinkResource> privateLinkResources = (await serviceBusNamespace.GetPrivateLinkResourcesAsync()).Value;

            Assert.NotNull(privateLinkResources);
        }
        public async Task GetIfExist()
        {
            #region Snippet:Managing_ServiceBusNamespaces_GetNamespaceIfExists
            ServiceBusNamespaceCollection namespaceCollection = resourceGroup.GetServiceBusNamespaces();
            ServiceBusNamespace           serviceBusNamespace = await namespaceCollection.GetIfExistsAsync("foo");

            if (serviceBusNamespace != null)
            {
                Console.WriteLine("namespace 'foo' exists");
            }
            if (await namespaceCollection.ExistsAsync("bar"))
            {
                Console.WriteLine("namespace 'bar' exists");
            }
            #endregion
        }
Exemplo n.º 25
0
        private ExtendedServiceBusNamespace GetExtendedServiceBusNamespace(string name)
        {
            ServiceBusNamespace sbNamespace = TryGetNamespace(name);

            if (sbNamespace != null &&
                sbNamespace.Status.Equals("Active", StringComparison.OrdinalIgnoreCase))
            {
                IList <ServiceBusNamespaceDescription> descriptions = ServiceBusClient.Namespaces
                                                                      .GetNamespaceDescription(name)
                                                                      .NamespaceDescriptions;

                return(new ExtendedServiceBusNamespace(sbNamespace, descriptions));
            }

            return(null);
        }
Exemplo n.º 26
0
 public async Task CreateNamespaceAndGetTopicCollection()
 {
     IgnoreTestInLiveMode();
     _resourceGroup = await CreateResourceGroupAsync();
     string namespaceName = await CreateValidNamespaceName("testnamespacemgmt");
     ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces();
     ServiceBusNamespaceData parameters = new ServiceBusNamespaceData(DefaultLocation)
     {
         Sku = new Sku(SkuName.Premium)
         {
             Tier = SkuTier.Premium
         }
     };
     ServiceBusNamespace serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(true, namespaceName, parameters)).Value;
     _topicCollection = serviceBusNamespace.GetServiceBusTopics();
 }
Exemplo n.º 27
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ServiceBusNamespace = await _context.ServiceBusNamespace.FindAsync(id);

            if (ServiceBusNamespace != null)
            {
                _context.ServiceBusNamespace.Remove(ServiceBusNamespace);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 28
0
        public async Task GetPrivateLinkResources()
        {
            IgnoreTestInLiveMode();
            //create namespace
            _resourceGroup = await CreateResourceGroupAsync();

            ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces();
            string namespaceName = await CreateValidNamespaceName(namespacePrefix);

            ServiceBusNamespace serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(true, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value;

            //get private link resource
            await foreach (var _ in serviceBusNamespace.GetPrivateLinkResourcesAsync())
            {
                return;
            }
        }
Exemplo n.º 29
0
        public async Task NamespaceAuthorizationRuleRegenerateKey()
        {
            IgnoreTestInLiveMode();
            //create namespace
            _resourceGroup = await CreateResourceGroupAsync();

            ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces();
            string namespaceName = await CreateValidNamespaceName(namespacePrefix);

            ServiceBusNamespace serviceBusNamespace             = (await namespaceCollection.CreateOrUpdateAsync(true, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value;
            NamespaceAuthorizationRuleCollection ruleCollection = serviceBusNamespace.GetNamespaceAuthorizationRules();

            //create authorization rule
            string ruleName = Recording.GenerateAssetName("authorizationrule");
            ServiceBusAuthorizationRuleData parameter = new ServiceBusAuthorizationRuleData()
            {
                Rights = { AccessRights.Listen, AccessRights.Send }
            };
            NamespaceAuthorizationRule authorizationRule = (await ruleCollection.CreateOrUpdateAsync(true, ruleName, parameter)).Value;

            Assert.NotNull(authorizationRule);
            Assert.AreEqual(authorizationRule.Data.Rights.Count, parameter.Rights.Count);

            AccessKeys keys1 = await authorizationRule.GetKeysAsync();

            Assert.NotNull(keys1);
            Assert.NotNull(keys1.PrimaryConnectionString);
            Assert.NotNull(keys1.SecondaryConnectionString);

            AccessKeys keys2 = await authorizationRule.RegenerateKeysAsync(new RegenerateAccessKeyOptions(KeyType.PrimaryKey));

            if (Mode != RecordedTestMode.Playback)
            {
                Assert.AreNotEqual(keys1.PrimaryKey, keys2.PrimaryKey);
                Assert.AreEqual(keys1.SecondaryKey, keys2.SecondaryKey);
            }

            AccessKeys keys3 = await authorizationRule.RegenerateKeysAsync(new RegenerateAccessKeyOptions(KeyType.SecondaryKey));

            if (Mode != RecordedTestMode.Playback)
            {
                Assert.AreEqual(keys2.PrimaryKey, keys3.PrimaryKey);
                Assert.AreNotEqual(keys2.SecondaryKey, keys3.SecondaryKey);
            }
        }
Exemplo n.º 30
0
        public ServiceBusNamespace EndGetServiceBusNamespace(IAsyncResult asyncResult)
        {
            ServiceBusNamespace serviceBusNamespace = new ServiceBusNamespace();

            if (GetNamespaceThunk != null)
            {
                SimpleServiceManagementAsyncResult result = asyncResult as SimpleServiceManagementAsyncResult;
                Assert.IsNotNull(result, "asyncResult was not SimpleServiceManagementAsyncResult!");

                serviceBusNamespace = GetNamespaceThunk(result);
            }
            else if (ThrowsIfNotImplemented)
            {
                throw new NotImplementedException("GetNamespaceThunk is not implemented!");
            }

            return(serviceBusNamespace);
        }