public GradeStoreAzureQueue(IAzureClientFactory <QueueServiceClient> clientFactory)
        {
            var queueService = clientFactory.CreateClient(QueueClientName);

            this.queueSetGrade         = new QueueWithCreateIfNotExists(queueService, QueueNameSetGrade);
            this.queueConfirmAutoGrade = new QueueWithCreateIfNotExists(queueService, QueueNameConfirmAutoGrade);
        }
Example #2
0
 public AzureBusConfig(Dictionary <Type, string> commandTypeAndQueueName, Dictionary <Type, string> eventTypeAndTopicName, IQueueAndTopicNamingConvention queueAndTopicNamingConvention, IAzureClientFactory clientFactory)
 {
     CommandTypeAndQueueName       = commandTypeAndQueueName;
     EventTypeAndTopicName         = eventTypeAndTopicName;
     QueueAndTopicNamingConvention = queueAndTopicNamingConvention;
     ClientFactory = clientFactory;
 }
        public void CanSetClientOptionsInConfigurationBasedClientsViaConfigureOptions()
        {
            var configuration = GetConfiguration(
                new KeyValuePair <string, string>("TestClient:connectionString", "http://localhost/"),
                new KeyValuePair <string, string>("TestClient2:connectionString", "http://localhost2/")
                );

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClients(builder => {
                builder.UseConfiguration(_ => configuration);
            });

            serviceCollection.ConfigureAll <TestClientOptions>(options => options.Property = "client option value");
            serviceCollection.Configure <TestClientOptions>("TestClient", options => options.IntProperty = 2);

            ServiceProvider provider = serviceCollection.BuildServiceProvider();
            IAzureClientFactory <TestClient> factory = provider.GetService <IAzureClientFactory <TestClient> >();
            TestClient client  = factory.CreateClient("TestClient");
            TestClient client2 = factory.CreateClient("TestClient2");

            Assert.AreEqual("http://localhost/", client.ConnectionString);
            Assert.AreEqual("client option value", client.Options.Property);
            Assert.AreEqual(2, client.Options.IntProperty);

            Assert.AreEqual("http://localhost2/", client2.ConnectionString);
            Assert.AreEqual("client option value", client2.Options.Property);
        }
 public IoTHubReaderService(
     IAzureClientFactory <EventHubConsumerClient> producerFactory,
     ILogger <IoTHubReaderService> logger,
     IConfiguration configuration)
 {
     _logger        = logger;
     _resultsClient = producerFactory.CreateClient("IoTHub");
     readEventsCanseler.Token.Register(() => {
         _logger.LogInformation("ReadEventsFromPartitionAsync cansel");
     });
 }
        public void CreateClientThrowsWhenClientIsNotRegistered()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClients(builder => builder.AddTestClient(new Uri("http://localhost/")));

            ServiceProvider provider = serviceCollection.BuildServiceProvider();
            IAzureClientFactory <TestClient> factory = provider.GetService <IAzureClientFactory <TestClient> >();
            var exception = Assert.Throws <InvalidOperationException>(() => factory.CreateClient("Other"));

            Assert.AreEqual(exception.Message, "Unable to find client registration with type 'TestClient' and name 'Other'.");
        }
        public void RetrhowsExceptionFromClientCreation()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClients(builder => builder.AddTestClient("throw"));
            ServiceProvider provider = serviceCollection.BuildServiceProvider();
            IAzureClientFactory <TestClient> factory = provider.GetService <IAzureClientFactory <TestClient> >();

            var exception      = Assert.Throws <ArgumentException>(() => factory.CreateClient("Default"));
            var otherException = Assert.Throws <ArgumentException>(() => factory.CreateClient("Default"));

            Assert.AreSame(otherException, exception);
            Assert.AreEqual(exception.Message, "Throwing");
        }
        public void ReturnsSameInstanceWhenResolvedMultipleTimes()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClients(builder => builder.AddTestClient(new Uri("http://localhost/")));

            ServiceProvider provider = serviceCollection.BuildServiceProvider();
            IAzureClientFactory <TestClient> factory = provider.GetService <IAzureClientFactory <TestClient> >();

            TestClient client        = factory.CreateClient("Default");
            TestClient anotherClient = factory.CreateClient("Default");

            Assert.AreSame(client, anotherClient);
        }
        public void AllowsResolvingFactoryAndCreatingClientInstance()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClients(builder => builder.AddTestClient(new Uri("http://localhost/")));

            ServiceProvider provider = serviceCollection.BuildServiceProvider();
            IAzureClientFactory <TestClient> factory = provider.GetService <IAzureClientFactory <TestClient> >();

            TestClient client = factory.CreateClient("Default");

            Assert.NotNull(client);
            Assert.AreEqual("http://localhost/", client.Uri.ToString());
        }
        public void CanCreateClientFromConfiguration()
        {
            var configuration     = GetConfiguration(new KeyValuePair <string, string>("uri", "http://localhost/"));
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClients(builder => builder.AddTestClient(configuration));

            ServiceProvider provider = serviceCollection.BuildServiceProvider();
            IAzureClientFactory <TestClient> factory = provider.GetService <IAzureClientFactory <TestClient> >();

            TestClient client = factory.CreateClient("Default");

            Assert.NotNull(client);
            Assert.AreEqual("http://localhost/", client.Uri.ToString());
        }
 public LineCounterService(
     IAzureClientFactory <EventHubProducerClient> producerFactory,
     BlobServiceClient blobServiceClient,
     ILogger <LineCounterService> logger,
     IConfiguration configuration)
 {
     _logger = logger;
     _blobContainerClient = blobServiceClient.GetBlobContainerClient("uploads");
     _resultsClient       = producerFactory.CreateClient("Results");
     _processor           = new EventProcessorClient(
         _blobContainerClient,
         EventHubConsumerClient.DefaultConsumerGroupName,
         configuration["Uploads:connectionString"],
         configuration["Uploads:eventHubName"]);
 }
        public void CanCreateClientWithoutRegistrationUsingConnectionString()
        {
            var configuration = GetConfiguration(
                new KeyValuePair <string, string>("TestClient", "http://localhost/"));

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClients(builder => builder.UseConfiguration(_ => configuration));

            ServiceProvider provider = serviceCollection.BuildServiceProvider();
            IAzureClientFactory <TestClient> factory = provider.GetService <IAzureClientFactory <TestClient> >();
            TestClient client = factory.CreateClient("TestClient");

            Assert.AreEqual("http://localhost/", client.ConnectionString);
        }
        public void ExecutesConfigureDelegateOnOptions()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClients(builder => builder.AddTestClient(new Uri("http://localhost/")));
            serviceCollection.Configure <TestClientOptions>("Default", options => options.Property = "Value");

            ServiceProvider provider = serviceCollection.BuildServiceProvider();
            IAzureClientFactory <TestClient> factory = provider.GetService <IAzureClientFactory <TestClient> >();

            TestClient client = factory.CreateClient("Default");

            Assert.AreSame(client, client);
            Assert.AreEqual("Value", client.Options.Property);
        }
Example #13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

        #region Snippet:Inject
        public void Configure(IApplicationBuilder app, SecretClient secretClient, IAzureClientFactory <BlobServiceClient> blobClientFactory)
        #endregion
        {
            #region Snippet:ResolveNamed
            BlobServiceClient blobServiceClient = blobClientFactory.CreateClient("NamedBlobClient");
            #endregion

            app.Run(async context => {
                context.Response.ContentType = "text";

                await foreach (var response in blobServiceClient.GetBlobContainerClient("myblobcontainer").GetBlobsAsync())
                {
                    await context.Response.WriteAsync(response.Name + Environment.NewLine);
                }
            });
        }
        public void RegistrationOverridesConfigurationBasedClient()
        {
            var configuration = GetConfiguration(
                new KeyValuePair <string, string>("TestClient:connectionString", "http://localhost/"),
                new KeyValuePair <string, string>("AnotherTestClient:connectionString", "http://betterhost/"));

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClients(builder => {
                builder.AddTestClient(configuration.GetSection("AnotherTestClient")).WithName("TestClient");
                builder.UseConfiguration(_ => configuration);
            });

            ServiceProvider provider = serviceCollection.BuildServiceProvider();
            IAzureClientFactory <TestClient> factory = provider.GetService <IAzureClientFactory <TestClient> >();
            TestClient client = factory.CreateClient("TestClient");

            Assert.AreEqual("http://betterhost/", client.ConnectionString);
        }
Example #15
0
        public void CanRegisterMultipleClients()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClients(builder => builder
                                              .AddTestClient("Default", new Uri("http://localhost/"), options => options.Property     = "Value1")
                                              .AddTestClient("OtherClient", new Uri("http://otherhost/"), options => options.Property = "Value2"));

            ServiceProvider provider = serviceCollection.BuildServiceProvider();
            IAzureClientFactory <TestClient> factory = provider.GetService <IAzureClientFactory <TestClient> >();

            TestClient client      = factory.CreateClient("Default");
            TestClient otherClient = factory.CreateClient("OtherClient");

            Assert.AreEqual("http://localhost/", client.Uri.ToString());
            Assert.AreEqual("http://otherhost/", otherClient.Uri.ToString());

            Assert.AreEqual("Value1", client.Options.Property);
            Assert.AreEqual("Value2", otherClient.Options.Property);

            Assert.AreNotSame(client, otherClient);
        }
Example #16
0
        public IndexModel(ILogger <IndexModel> logger, IAzureClientFactory <BlobServiceClient> blobServiceClientFactory, MyFileContext context, MongoHelper mongoHelper)
        {
            _logger = logger;

            var blobServiceA = blobServiceClientFactory.CreateClient("Default"); // storageA
            var blobServiceB = blobServiceClientFactory.CreateClient("storageB");

            _blobContainerA = blobServiceA.GetBlobContainerClient(BlobContainerNameA);
            _blobContainerB = blobServiceB.GetBlobContainerClient(BlobContainerNameB);

            _blobContainerA.CreateIfNotExists();
            _blobContainerB.CreateIfNotExists();

            myFilesA = new List <MyFile>();
            myFilesB = new List <MyFile>();

            entries     = new List <DBEntry>();
            chatHistory = new List <MyChat>();

            _context     = context;
            _mongoHelper = mongoHelper;
        }
        public void SetsOptionsPropertiesFromConfiguration()
        {
            var configuration = GetConfiguration(
                new KeyValuePair <string, string>("connectionstring", "http://localhost/"),
                new KeyValuePair <string, string>("property", "value"),
                new KeyValuePair <string, string>("nested:property", "nested-value"),
                new KeyValuePair <string, string>("intproperty", "15")
                );

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClients(builder => builder.AddTestClient(configuration));

            ServiceProvider provider = serviceCollection.BuildServiceProvider();
            IAzureClientFactory <TestClient> factory = provider.GetService <IAzureClientFactory <TestClient> >();

            TestClient client = factory.CreateClient("Default");

            Assert.AreEqual("value", client.Options.Property);
            Assert.AreEqual("nested-value", client.Options.Nested.Property);
            Assert.AreEqual(15, client.Options.IntProperty);
            Assert.AreEqual("http://localhost/", client.ConnectionString);
        }
        public void CanCreateClientWithoutRegistration()
        {
            var configuration = GetConfiguration(
                new KeyValuePair <string, string>("TestClient:uri", "http://localhost/"),
                new KeyValuePair <string, string>("TestClient:clientId", "ConfigurationClientId"),
                new KeyValuePair <string, string>("TestClient:clientSecret", "ConfigurationClientSecret"),
                new KeyValuePair <string, string>("TestClient:tenantId", "ConfigurationTenantId"));

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClients(builder => builder.UseConfiguration(_ => configuration));

            ServiceProvider provider = serviceCollection.BuildServiceProvider();
            IAzureClientFactory <TestClientWithCredentials> factory = provider.GetService <IAzureClientFactory <TestClientWithCredentials> >();
            TestClientWithCredentials client = factory.CreateClient("TestClient");

            Assert.IsInstanceOf <ClientSecretCredential>(client.Credential);
            var clientSecretCredential = (ClientSecretCredential)client.Credential;

            Assert.AreEqual("http://localhost/", client.Uri.ToString());
            Assert.AreEqual("ConfigurationClientId", clientSecretCredential.ClientId);
            Assert.AreEqual("ConfigurationClientSecret", clientSecretCredential.ClientSecret);
            Assert.AreEqual("ConfigurationTenantId", clientSecretCredential.TenantId);
        }
Example #19
0
 public EventGridTopicFactory(IAzureClientFactory <EventGridPublisherClient> clientFactory)
 {
     _clientFactory = clientFactory;
 }
 public AzureEnvironmentBuilder(IAzureClientFactory clientFactory)
 {
     namespaceManager = clientFactory.CreateNamespaceManager();
 }