Skip to content

Commit 59d0e1b

Browse files
test: WIP validation before release
1 parent 91eebfb commit 59d0e1b

File tree

4 files changed

+65
-63
lines changed

4 files changed

+65
-63
lines changed

QuickStart/App.config

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?><configuration>
2+
<runtime>
3+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
4+
<dependentAssembly>
5+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
6+
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
7+
</dependentAssembly>
8+
</assemblyBinding>
9+
</runtime>
10+
</configuration>

QuickStart/Program.cs

Lines changed: 44 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Linq;
3+
using Newtonsoft.Json;
24
using OptimizelySDK;
35

46
namespace QuickStart
@@ -7,78 +9,57 @@ public static class QuickStart
79
{
810
public static void Main()
911
{
10-
// This Optimizely initialization is synchronous. For other methods, see the C# SDK reference.
11-
var optimizelyClient = OptimizelyFactory.NewDefaultInstance("K4UmaV5Pk7cEh2hbcjgwe");
12+
var optimizelyClient = OptimizelyFactory.NewDefaultInstance("TbrfRLeKvLyWGusqANoeR");
1213
if (!optimizelyClient.IsValid)
1314
{
1415
Console.WriteLine(
1516
"Optimizely client invalid. " +
1617
"Verify in Settings>Environments that you used the primary environment's SDK key");
1718
optimizelyClient.Dispose();
1819
}
20+
21+
const string USER_ID = "matjaz-user-2";
1922

20-
var hasOnFlags = false;
21-
22-
/*
23-
* To get rapid demo results, generate random users.
24-
* Each user always sees the same variation unless you reconfigure the flag rule.
25-
*/
26-
var rnd = new Random();
27-
for (var i = 0; i < 10; i++)
28-
{
29-
var userId = rnd.Next(1000, 9999).ToString();
30-
31-
// Create a user context to bucket the user into a variation.
32-
var user = optimizelyClient.CreateUserContext(userId);
33-
34-
// "product_sort" corresponds to a flag key in your Optimizely project
35-
var decision = user.Decide("product_sort");
36-
37-
// Did decision fail with a critical error?
38-
if (string.IsNullOrEmpty(decision.VariationKey))
39-
{
40-
Console.WriteLine(Environment.NewLine + Environment.NewLine +
41-
"Decision error: " + string.Join(" ", decision.Reasons));
42-
continue;
43-
}
44-
45-
/*
46-
* Get a dynamic configuration variable.
47-
* "sort_method" corresponds to a variable key in your Optimizely project.
48-
*/
49-
var sortMethod = decision.Variables.ToDictionary()["sort_method"];
50-
51-
hasOnFlags = hasOnFlags || decision.Enabled;
52-
53-
/*
54-
* Mock what the user sees with print statements (in production, use flag variables to implement feature configuration)
55-
*/
56-
57-
// always returns false until you enable a flag rule in your Optimizely project
58-
Console.WriteLine(Environment.NewLine +
59-
$"Flag {(decision.Enabled ? "on" : "off")}. " +
60-
$"User number {user.GetUserId()} saw " +
61-
$"flag variation {decision.VariationKey} and got " +
62-
$"products sorted by {sortMethod} config variable as part of " +
63-
$"flag rule {decision.RuleKey}");
64-
}
65-
66-
if (!hasOnFlags)
67-
{
68-
var projectId = optimizelyClient.ProjectConfigManager.GetConfig().ProjectId;
69-
var projectSettingsUrl =
70-
$"https://app.optimizely.com/v2/projects/{projectId}/settings/implementation";
71-
72-
Console.WriteLine(Environment.NewLine + Environment.NewLine +
73-
"Flag was off for everyone. Some reasons could include:" +
74-
Environment.NewLine +
75-
"1. Your sample size of visitors was too small. Re-run, or increase the iterations in the FOR loop" +
76-
Environment.NewLine +
77-
"2. By default you have 2 keys for 2 project environments (dev/prod). Verify in Settings>Environments that you used the right key for the environment where your flag is toggled to ON." +
78-
Environment.NewLine + Environment.NewLine +
79-
$"Check your key at {projectSettingsUrl}");
80-
}
23+
var user = optimizelyClient.CreateUserContext(USER_ID);
8124

25+
// Fetch
26+
// Console.WriteLine("Fetch:" + user.FetchQualifiedSegments());
27+
// var qualifiedSegments = user.GetQualifiedSegments();
28+
// Console.WriteLine(JsonConvert.SerializeObject(qualifiedSegments));
29+
// const string SEGMENT_ID = "atsbugbashsegmentdob";
30+
// Console.WriteLine($"Is Qualified for {SEGMENT_ID}: {user.IsQualifiedFor(SEGMENT_ID)}");
31+
32+
// TrackEvent
33+
// user.TrackEvent("myevent");
34+
35+
// Decide
36+
// var decision = user.Decide("flag1");
37+
// Console.WriteLine(JsonConvert.SerializeObject(decision));
38+
// var variables = decision.Variables.ToDictionary();
39+
// Console.WriteLine(JsonConvert.SerializeObject(variables));
40+
41+
// DecideForKeys
42+
var keys = new[] {"flag1", "flag2"};
43+
var decisions = user.DecideForKeys(keys);
44+
Console.WriteLine(JsonConvert.SerializeObject(decisions));
45+
46+
// DecideAll
47+
// var decisions = user.DecideAll();
48+
// Console.WriteLine(JsonConvert.SerializeObject(decisions));
49+
50+
// Set & Get & Remove ForcedDecision
51+
// var context = new OptimizelyDecisionContext("flag1", "default-rollout-34902-22583870382");
52+
// var forcedDecision = new OptimizelyForcedDecision("off");
53+
// user.SetForcedDecision(context, forcedDecision);
54+
// var result = user.GetForcedDecision(context);
55+
// Console.WriteLine(JsonConvert.SerializeObject(result));
56+
// var wasRemoved = user.RemoveForcedDecision(context);
57+
// Console.WriteLine($"Was removed: {wasRemoved}");
58+
59+
// Activate
60+
// var variation = optimizelyClient.Activate("flag1", USER_ID);
61+
// Console.WriteLine("Variation: " + JsonConvert.SerializeObject(variation));
62+
8263
optimizelyClient.Dispose();
8364
}
8465
}

QuickStart/QuickStart.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
<WarningLevel>4</WarningLevel>
3535
</PropertyGroup>
3636
<ItemGroup>
37+
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
38+
<HintPath>..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
39+
</Reference>
3740
<Reference Include="System"/>
3841
<Reference Include="System.Core"/>
3942
<Reference Include="System.Data"/>
@@ -49,6 +52,10 @@
4952
<Name>OptimizelySDK</Name>
5053
</ProjectReference>
5154
</ItemGroup>
55+
<ItemGroup>
56+
<None Include="App.config" />
57+
<None Include="packages.config" />
58+
</ItemGroup>
5259
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
5360
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
5461
Other similar extension points exist, see Microsoft.Common.targets.

QuickStart/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Newtonsoft.Json" version="13.0.2" targetFramework="net48" />
4+
</packages>

0 commit comments

Comments
 (0)