-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathProgram.cs
65 lines (53 loc) · 1.72 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
65
// See https://aka.ms/new-console-template for more information
using FeatBit.Sdk.Server;
using FeatBit.Sdk.Server.Model;
using FeatBit.Sdk.Server.Options;
using Microsoft.Extensions.Logging;
// Set secret to your FeatBit SDK secret.
const string secret = "";
if (string.IsNullOrWhiteSpace(secret))
{
Console.WriteLine("Please edit Program.cs to set secret to your FeatBit SDK secret first. Exiting...");
Environment.Exit(1);
}
// Creates a new client to connect to FeatBit with a custom option.
// use console logging for FbClient
var consoleLoggerFactory = LoggerFactory.Create(opt => opt.AddConsole());
var options = new FbOptionsBuilder(secret)
.LoggerFactory(consoleLoggerFactory)
.Build();
var client = new FbClient(options);
if (!client.Initialized)
{
Console.WriteLine("FbClient failed to initialize. Exiting...");
Environment.Exit(-1);
}
while (true)
{
Console.WriteLine("Please input userKey/flagKey, for example 'user-id/use-new-algorithm'. Input 'exit' to exit.");
var input = Console.ReadLine();
if (string.IsNullOrWhiteSpace(input))
{
continue;
}
if (input == "exit")
{
Console.WriteLine("Exiting, please wait...");
break;
}
var keys = input.Split('/');
if (keys.Length != 2)
{
Console.WriteLine();
continue;
}
var userKey = keys[0];
var flagKey = keys[1];
var user = FbUser.Builder(userKey).Build();
var detail = client.StringVariationDetail(flagKey, user, "fallback");
Console.WriteLine($"Kind: {detail.Kind}, Reason: {detail.Reason}, Value: {detail.Value}");
Console.WriteLine();
}
// Shuts down the client to ensure all pending events are sent.
await client.CloseAsync();
Environment.Exit(1);