コード例 #1
0
        public async Task GetBatchSettingWithAllFields()
        {
            ConfigurationClient service = GetClient();
            string key = GenerateKeyId("keyFields-");
            ConfigurationSetting setting = await service.AddAsync(key, "my_value", "my_label");

            try
            {
                SettingSelector selector = new SettingSelector(key)
                {
                    Fields = SettingFields.All
                };
                SettingBatch batch = await service.GetBatchAsync(selector, CancellationToken.None);

                Assert.AreEqual(1, batch.Count);

                Assert.IsNotNull(batch[0].Key);
                Assert.IsNotNull(batch[0].Label);
                Assert.IsNotNull(batch[0].Value);
                Assert.IsNotNull(batch[0].ContentType);
                Assert.IsNotNull(batch[0].ETag);
                Assert.IsNotNull(batch[0].LastModified);
                Assert.IsNotNull(batch[0].Locked);
            }
            finally
            {
                await service.DeleteAsync(setting.Key, setting.Label);
            }
        }
コード例 #2
0
        public async Task GetBatchWithFields()
        {
            var connectionString = Environment.GetEnvironmentVariable("AZ_CONFIG_CONNECTION");

            Assert.NotNull(connectionString, "Set AZ_CONFIG_CONNECTION environment variable to the connection string");
            var service = new ConfigurationClient(connectionString);

            try
            {
                await service.SetAsync(s_testSetting);

                SettingSelector selector = new SettingSelector()
                {
                    Fields = SettingFields.Key | SettingFields.Label | SettingFields.Value
                };

                SettingBatch batch = await service.GetBatchAsync(selector, CancellationToken.None);

                int resultsReturned = batch.Count;

                //At least there should be one key available
                Assert.GreaterOrEqual(resultsReturned, 1);
            }
            finally
            {
                await service.DeleteAsync(s_testSetting.Key, s_testSetting.Label);
            }
        }
コード例 #3
0
        public async Task GetBatchSettingOnlyLabel()
        {
            ConfigurationClient  service     = GetClient();
            ConfigurationSetting testSetting = CreateSetting();

            try
            {
                await service.SetAsync(testSetting);

                var selector = new SettingSelector(null, testSetting.Label);

                Assert.AreEqual("*", selector.Keys.First());

                SettingBatch batch = await service.GetBatchAsync(selector, CancellationToken.None);

                int resultsReturned = batch.Count;

                //At least there should be one key available
                Assert.GreaterOrEqual(resultsReturned, 1);
                Assert.AreEqual(testSetting.Label, batch[0].Label);
            }
            finally
            {
                await service.DeleteAsync(testSetting.Key, testSetting.Label);
            }
        }
コード例 #4
0
        public async Task GetBatchSettingPagination()
        {
            ConfigurationClient service = GetClient();

            const int expectedEvents = 105;
            var       key            = await SetMultipleKeys(service, expectedEvents);

            int             resultsReturned = 0;
            SettingSelector selector        = new SettingSelector(key);

            while (true)
            {
                using (Response <SettingBatch> response = await service.GetBatchAsync(selector, CancellationToken.None))
                {
                    SettingBatch batch = response.Value;
                    resultsReturned += batch.Count;
                    var nextBatch = batch.NextBatch;

                    if (nextBatch == null)
                    {
                        break;
                    }

                    selector = nextBatch;
                }
            }
            Assert.AreEqual(expectedEvents, resultsReturned);
        }
コード例 #5
0
        public async Task GetBatchSettingWithFields()
        {
            ConfigurationClient service = TestEnvironment.GetClient();

            try
            {
                await service.SetAsync(s_testSetting);

                SettingSelector selector = new SettingSelector()
                {
                    Fields = SettingFields.Key | SettingFields.Label | SettingFields.Value,
                };

                SettingBatch batch = await service.GetBatchAsync(selector, CancellationToken.None);

                int resultsReturned = batch.Count;

                //At least there should be one key available
                Assert.GreaterOrEqual(resultsReturned, 1);
            }
            finally
            {
                await service.DeleteAsync(s_testSetting.Key, s_testSetting.Label);
            }
        }
コード例 #6
0
        public async Task GetBatchSettingAny()
        {
            ConfigurationClient service = TestEnvironment.GetClient();

            try
            {
                await service.SetAsync(s_testSetting);

                var selector = new SettingSelector();

                Assert.AreEqual(selector.Keys.First(), "*");
                Assert.AreEqual(selector.Labels.First(), "*");

                SettingBatch batch = await service.GetBatchAsync(selector, CancellationToken.None);

                int resultsReturned = batch.Count;

                //At least there should be one key available
                Assert.GreaterOrEqual(resultsReturned, 1);
            }
            finally
            {
                await service.DeleteAsync(s_testSetting.Key, s_testSetting.Label);
            }
        }
コード例 #7
0
        public async Task GetBatchPagination()
        {
            var connectionString = Environment.GetEnvironmentVariable("AZ_CONFIG_CONNECTION");

            Assert.NotNull(connectionString, "Set AZ_CONFIG_CONNECTION environment variable to the connection string");
            var service = new ConfigurationClient(connectionString);

            const int expectedEvents = 105;
            var       key            = await SetMultipleKeys(service, expectedEvents);

            int             resultsReturned = 0;
            SettingSelector selector        = new SettingSelector(key);

            while (true)
            {
                using (Response <SettingBatch> response = await service.GetBatchAsync(selector, CancellationToken.None))
                {
                    SettingBatch batch = response.Result;
                    resultsReturned += batch.Count;
                    var nextBatch = batch.NextBatch;

                    if (nextBatch == null)
                    {
                        break;
                    }

                    selector = nextBatch;
                }
            }
            Assert.AreEqual(expectedEvents, resultsReturned);
        }
コード例 #8
0
        public async Task GetBatchPagination()
        {
            var connectionString = Environment.GetEnvironmentVariable("AZ_CONFIG_CONNECTION");

            Assert.NotNull(connectionString, "Set AZ_CONFIG_CONNECTION environment variable to the connection string");
            var service = new ConfigurationClient(connectionString);

            const int expectedEvents = 105;
            var       key            = await SetMultipleKeys(service, expectedEvents);

            int resultsReturned         = 0;
            BatchRequestOptions options = new BatchRequestOptions()
            {
                Key = key
            };

            while (true)
            {
                using (Response <SettingBatch> response = await service.GetBatchAsync(options, CancellationToken.None))
                {
                    SettingBatch batch = response.Result;
                    resultsReturned += batch.Count;
                    options          = batch.NextBatch;

                    if (string.IsNullOrEmpty(options.BatchLink))
                    {
                        break;
                    }
                }
            }
            Assert.AreEqual(expectedEvents, resultsReturned);
        }
コード例 #9
0
 public SettingBatchDebugView(SettingBatch batch)
 {
     _batch = batch;
     _items = new ConfigurationSetting[_batch.Count];
     for (int i = 0; i < _batch.Count; i++)
     {
         _items[i] = _batch[i];
     }
 }
コード例 #10
0
        /*
         * Sample demonstrates how to use Azure App Configuration to save information about two(2) environments
         * "beta" and "production".
         * To do this, we will create Configuration Settings with the same key,
         * but different labels: one for "beta" and one for "production".
         */
        public async Task HelloWorldExtended()
        {
            // Retrieve the connection string from the configuration store.
            // You can get the string from your Azure portal or using Azure CLI.
            var connectionString = Environment.GetEnvironmentVariable("AZ_CONFIG_CONNECTION");

            // Instantiate a client that will be used to call the service.
            var client = new ConfigurationClient(connectionString);

            // Create the Configuration Settings to be stored in the Configuration Store.
            var betaEndpoint        = new ConfigurationSetting("endpoint", "https://beta.endpoint.com", "beta");
            var betaInstances       = new ConfigurationSetting("instances", "1", "beta");
            var productionEndpoint  = new ConfigurationSetting("endpoint", "https://production.endpoint.com", "production");
            var productionInstances = new ConfigurationSetting("instances", "1", "production");

            // There are two(2) ways to store a Configuration Setting:
            //   -AddAsync creates a setting only if the setting does not already exist in the store.
            //   -SetAsync creates a setting if it doesn't exist or overrides an existing setting
            await client.AddAsync(betaEndpoint);

            await client.AddAsync(betaInstances);

            await client.AddAsync(productionEndpoint);

            await client.AddAsync(productionInstances);

            // There is a need to increase the production instances from 1 to 5.
            // The UpdateSync will help us with this.
            ConfigurationSetting instancesToUpdate = await client.GetAsync(productionInstances.Key, productionInstances.Label);

            instancesToUpdate.Value = "5";

            await client.UpdateAsync(instancesToUpdate);

            // We want to gather all the information available for the "production' environment.
            // By calling GetBatchSync with the proper filter for label "production", we will get
            // all the Configuration Settings that satisfy that condition.
            var          selector = new SettingSelector(null, "production");
            SettingBatch batch    = await client.GetBatchAsync(selector);

            Debug.WriteLine("Settings for Production environmnet");
            for (int i = 0; i < batch.Count; i++)
            {
                var value = batch[i];
                Debug.WriteLine(batch[i]);
            }

            // Once we don't need the Configuration Setting, we can delete them.
            await client.DeleteAsync(betaEndpoint.Key, betaEndpoint.Label);

            await client.DeleteAsync(betaInstances.Key, betaInstances.Label);

            await client.DeleteAsync(productionEndpoint.Key, productionEndpoint.Label);

            await client.DeleteAsync(productionInstances.Key, productionInstances.Label);
        }
コード例 #11
0
        /// <summary>
        /// Executes the setting method async.
        /// </summary>
        /// <param name="method">The method.</param>
        /// <param name="settingStorePartitions">The settingStorePartitions.</param>
        /// <param name="settingCollection">collection of settings.</param>
        /// <returns>Async task.</returns>
        public Task <SettingCollection> CallSettingMethodAsync(SettingMethods method, SettingStorePartitions settingStorePartitions, SettingCollection settingCollection)
        {
            var requestUri = this.CreateRequestUri(RelativePaths.Settings);
            var batch      = new SettingBatch
            {
                SettingStorePartitions = settingStorePartitions,
                SettingCollection      = settingCollection,
                Method = method.ToString()
            };

            return(this.SendAsync <SettingBatch, SettingCollection>(requestUri, HttpMethod.Post, batch));
        }
コード例 #12
0
        public async Task Revisions()
        {
            var connectionString = Environment.GetEnvironmentVariable("AZ_CONFIG_CONNECTION");

            Assert.NotNull(connectionString, "Set AZ_CONFIG_CONNECTION environment variable to the connection string");
            var service = new ConfigurationClient(connectionString);

            //Prepare environment
            ConfigurationSetting setting = s_testSetting;

            setting.Key = string.Concat("key-", Guid.NewGuid().ToString("N"));
            var testSettingUpdate = setting.Clone();

            testSettingUpdate.Label = "test_label_update";
            int expectedEvents = 2;

            try
            {
                await service.SetAsync(setting);

                await service.SetAsync(testSettingUpdate);

                // Test
                var filter = new BatchRequestOptions();
                filter.Key      = setting.Key;
                filter.Revision = DateTimeOffset.MaxValue;
                SettingBatch batch = await service.GetRevisionsAsync(filter, CancellationToken.None);

                int resultsReturned = 0;
                for (int i = 0; i < batch.Count; i++)
                {
                    var value = batch[i];
                    if (value.Label.Contains("update"))
                    {
                        Assert.AreEqual(value, testSettingUpdate);
                    }
                    else
                    {
                        Assert.AreEqual(value, setting);
                    }
                    resultsReturned++;
                }

                Assert.AreEqual(expectedEvents, resultsReturned);
            }
            finally
            {
                await service.DeleteAsync(setting.Key, setting.Label);

                await service.DeleteAsync(testSettingUpdate.Key, testSettingUpdate.Label);
            }
        }
コード例 #13
0
        public async Task GetRevisions()
        {
            ConfigurationClient  service     = GetClient();
            ConfigurationSetting testSetting = CreateSetting();

            //Prepare environment
            ConfigurationSetting setting = testSetting;

            setting.Key = GenerateKeyId("key-");
            var testSettingUpdate = setting.Clone();

            testSettingUpdate.Label = "test_label_update";
            int expectedEvents = 2;

            try
            {
                await service.SetAsync(setting);

                await service.SetAsync(testSettingUpdate);

                // Test
                var selector = new SettingSelector(setting.Key);
                selector.AsOf = DateTimeOffset.MaxValue;
                SettingBatch batch = await service.GetRevisionsAsync(selector, CancellationToken.None);

                int resultsReturned = 0;
                for (int i = 0; i < batch.Count; i++)
                {
                    var value = batch[i];
                    if (value.Label.Contains("update"))
                    {
                        Assert.AreEqual(value, testSettingUpdate);
                    }
                    else
                    {
                        Assert.AreEqual(value, setting);
                    }
                    resultsReturned++;
                }

                Assert.AreEqual(expectedEvents, resultsReturned);
            }
            finally
            {
                await service.DeleteAsync(setting.Key, setting.Label);

                await service.DeleteAsync(testSettingUpdate.Key, testSettingUpdate.Label);
            }
        }
コード例 #14
0
        public async Task GetBatchSettingOnlyKey()
        {
            ConfigurationClient service = TestEnvironment.GetClient();

            try
            {
                await service.SetAsync(s_testSetting);

                var          selector = new SettingSelector(s_testSetting.Key);
                SettingBatch batch    = await service.GetBatchAsync(selector, CancellationToken.None);

                Assert.AreEqual(batch.Count, 1);
                Assert.AreEqual(batch[0].Key, s_testSetting.Key);
            }
            finally
            {
                await service.DeleteAsync(s_testSetting.Key, s_testSetting.Label);
            }
        }
コード例 #15
0
        public async Task GetBatchSettingOnlyKey()
        {
            ConfigurationClient  service     = GetClient();
            ConfigurationSetting testSetting = CreateSetting();

            try
            {
                await service.SetAsync(testSetting);

                var          selector = new SettingSelector(testSetting.Key);
                SettingBatch batch    = await service.GetBatchAsync(selector, CancellationToken.None);

                Assert.AreEqual(1, batch.Count);
                Assert.AreEqual(testSetting.Key, batch[0].Key);
            }
            finally
            {
                await service.DeleteAsync(testSetting.Key, testSetting.Label);
            }
        }
コード例 #16
0
        public async Task GetBatch()
        {
            var response1 = new MockResponse(200);

            response1.SetContent(SerializationHelpers.Serialize(new []
            {
                CreateSetting(0),
                CreateSetting(1),
            }, SerializeBatch));
            response1.AddHeader(new HttpHeader("Link", $"</kv?after=5>;rel=\"next\""));

            var response2 = new MockResponse(200);

            response2.SetContent(SerializationHelpers.Serialize(new []
            {
                CreateSetting(2),
                CreateSetting(3),
                CreateSetting(4),
            }, SerializeBatch));

            var mockTransport           = new MockTransport(response1, response2);
            ConfigurationClient service = CreateTestService(mockTransport);

            var query    = new SettingSelector();
            int keyIndex = 0;

            while (true)
            {
                using (Response <SettingBatch> response = await service.GetBatchAsync(query, CancellationToken.None))
                {
                    SettingBatch batch = response.Value;
                    for (int i = 0; i < batch.Count; i++)
                    {
                        ConfigurationSetting value = batch[i];
                        Assert.AreEqual("key" + keyIndex, value.Key);
                        keyIndex++;
                    }

                    var nextBatch = batch.NextBatch;

                    if (nextBatch == null)
                    {
                        break;
                    }

                    query = nextBatch;
                }
            }

            Assert.AreEqual(2, mockTransport.Requests.Count);

            MockRequest request1 = mockTransport.Requests[0];

            Assert.AreEqual(HttpPipelineMethod.Get, request1.Method);
            Assert.AreEqual("https://contoso.azconfig.io/kv/?key=*&label=*", request1.UriBuilder.ToString());
            AssertRequestCommon(request1);

            MockRequest request2 = mockTransport.Requests[1];

            Assert.AreEqual(HttpPipelineMethod.Get, request2.Method);
            Assert.AreEqual("https://contoso.azconfig.io/kv/?key=*&label=*&after=5", request2.UriBuilder.ToString());
            AssertRequestCommon(request1);
        }