forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sample1_HelloWorld.cs
40 lines (33 loc) · 1.6 KB
/
Sample1_HelloWorld.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.
using NUnit.Framework;
using System;
using System.Diagnostics;
namespace Azure.ApplicationModel.Configuration.Samples
{
[Category("Live")]
public partial class ConfigurationSamples
{
[Test]
public void HelloWorld()
{
// Retrieve the connection string from the configuration store.
// You can get the string from your Azure portal.
var connectionString = Environment.GetEnvironmentVariable("APP_CONFIG_CONNECTION");
// Instantiate a client that will be used to call the service.
var client = new ConfigurationClient(connectionString);
// Create a Configuration Setting to be stored in the Configuration Store.
var setting = new ConfigurationSetting("some_key", "some_value");
// There are two 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
client.Set(setting);
// Retrieve a previously stored Configuration Setting by calling GetAsync.
ConfigurationSetting gotSetting = client.Get("some_key");
Debug.WriteLine(gotSetting.Value);
// Delete the Configuration Setting from the Configuration Store when you don't need it anymore.
client.Delete("some_key");
}
}
}