-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathProgram.cs
64 lines (56 loc) · 2.41 KB
/
Program.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.Threading;
using io.harness.cfsdk.client.api;
using io.harness.cfsdk.client.dto;
using Serilog;
using Serilog.Extensions.Logging;
namespace getting_started
{
internal class Program
{
public static string apiKey = Environment.GetEnvironmentVariable("FF_API_KEY");
public static string flagName = Environment.GetEnvironmentVariable("FF_FLAG_NAME") is string v && v.Length > 0
? v
: "harnessappdemodarkmode";
private static void Main(string[] args)
{
var loggerFactory = new SerilogLoggerFactory(
new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.Console()
.CreateLogger());
// Create a feature flag client
var client = new CfClient(apiKey, Config.Builder().LoggerFactory(loggerFactory).Build());
// Create a target (different targets can get different results based on rules)
var target = Target.builder()
.Name("DotNET SDK")
.Identifier("dotnetsdk")
.Attributes(new Dictionary<string, string> { { "email", "[email protected]" } })
.build();
// Events need to be created **before** calling WaitForInitialization
client.InitializationCompleted += (sender, e) =>
{
Console.WriteLine("NOTIFICATION: Initialization Completed");
};
client.EvaluationChanged += (sender, identifier) =>
{
var resultBool = client.boolVariation(flagName, target, false);
Console.WriteLine($"stream: Flag '{flagName}' = " + resultBool);
};
client.FlagsLoaded += (sender, identifiers) =>
{
foreach (var identifier in identifiers) Console.WriteLine($"Flag loaded: Flag '{identifier}");
};
var isInit = client.WaitForInitialization(30000);
if (!isInit) Console.WriteLine("Failed to init the SDK within 30seconds");
// Loop forever reporting the state of the flag
while (true)
{
var resultBool = client.boolVariation(flagName, target, false);
Console.WriteLine($"POLL: Flag '{flagName}' = " + resultBool);
Thread.Sleep(10 * 1000);
}
}
}
}