diff --git a/OptimizelySDK.sln b/OptimizelySDK.sln index 4fb4cac3..5e9a17b7 100644 --- a/OptimizelySDK.sln +++ b/OptimizelySDK.sln @@ -28,6 +28,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OptimizelySDK.Net40", "Opti EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OptimizelySDK.NetStandard20", "OptimizelySDK.NetStandard20\OptimizelySDK.NetStandard20.csproj", "{CFEC91C6-B6E5-45D5-97D6-7081B0DC7453}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickStart", "QuickStart\QuickStart.csproj", "{74BAE350-8779-413A-A88E-AFE6A0A84D28}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -62,6 +64,10 @@ Global {CFEC91C6-B6E5-45D5-97D6-7081B0DC7453}.Debug|Any CPU.Build.0 = Debug|Any CPU {CFEC91C6-B6E5-45D5-97D6-7081B0DC7453}.Release|Any CPU.ActiveCfg = Release|Any CPU {CFEC91C6-B6E5-45D5-97D6-7081B0DC7453}.Release|Any CPU.Build.0 = Release|Any CPU + {74BAE350-8779-413A-A88E-AFE6A0A84D28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {74BAE350-8779-413A-A88E-AFE6A0A84D28}.Debug|Any CPU.Build.0 = Debug|Any CPU + {74BAE350-8779-413A-A88E-AFE6A0A84D28}.Release|Any CPU.ActiveCfg = Release|Any CPU + {74BAE350-8779-413A-A88E-AFE6A0A84D28}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/QuickStart/App.config b/QuickStart/App.config new file mode 100644 index 00000000..f54a54db --- /dev/null +++ b/QuickStart/App.config @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/QuickStart/Program.cs b/QuickStart/Program.cs new file mode 100644 index 00000000..c4f1e6c5 --- /dev/null +++ b/QuickStart/Program.cs @@ -0,0 +1,171 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using Newtonsoft.Json; +using OptimizelySDK; +using OptimizelySDK.Config; +using OptimizelySDK.Entity; +using OptimizelySDK.ErrorHandler; +using OptimizelySDK.Event; +using OptimizelySDK.Event.Dispatcher; +using OptimizelySDK.Logger; +using OptimizelySDK.Notifications; +using OptimizelySDK.Odp; + +namespace QuickStart +{ + public static class QuickStart + { + public static void Main() + { + + var logger = new DefaultLogger(); + var errorHandler = new DefaultErrorHandler(logger, false); + var eventDispatcher = new DefaultEventDispatcher(logger); + var builder = new HttpProjectConfigManager.Builder(); + var notificationCenter = new NotificationCenter(); + // Wire ConfigUpdate and LogEvent early + // for ConfigUpdate + // notificationCenter.AddNotification( + // NotificationCenter.NotificationType.OptimizelyConfigUpdate, + // NotificationCallbacks.ConfigUpdateCallback); + // // for LogEvent + // notificationCenter.AddNotification( + // NotificationCenter.NotificationType.LogEvent, + // NotificationCallbacks.LogEventCallback); + + var configManager = builder.WithSdkKey("TbrfRLeKvLyWGusqANoeR"). + WithLogger(logger). + WithPollingInterval(TimeSpan.FromSeconds(1)). + WithBlockingTimeoutPeriod(TimeSpan.FromSeconds(1)). + WithErrorHandler(errorHandler). + WithNotificationCenter(notificationCenter). + Build(); + var eventProcessor = new BatchEventProcessor.Builder().WithLogger(logger). + WithMaxBatchSize(1). + WithFlushInterval(TimeSpan.FromSeconds(1)). + WithEventDispatcher(eventDispatcher). + WithNotificationCenter(notificationCenter). + Build(); + var odpManager = new OdpManager.Builder() + .WithErrorHandler(errorHandler) + .WithLogger(logger) + .Build(); + var optimizelyClient = new Optimizely(configManager, notificationCenter, eventDispatcher, logger, + errorHandler, null, eventProcessor, null, odpManager); + + const string USER_ID = "matjaz-user-2"; + var user = optimizelyClient.CreateUserContext(USER_ID); + + // Fetch + // Console.WriteLine("Fetch:" + user.FetchQualifiedSegments()); + // var qualifiedSegments = user.GetQualifiedSegments(); + // Console.WriteLine(JsonConvert.SerializeObject(qualifiedSegments)); + // const string SEGMENT_ID = "atsbugbashsegmentdob"; + // Console.WriteLine($"Is Qualified for {SEGMENT_ID}: {user.IsQualifiedFor(SEGMENT_ID)}"); + + // TrackEvent + // user.TrackEvent("myevent"); + + // Decide + // var decision = user.Decide("flag1"); + // Console.WriteLine(JsonConvert.SerializeObject(decision)); + // var variables = decision.Variables.ToDictionary(); + // Console.WriteLine(JsonConvert.SerializeObject(variables)); + + // DecideForKeys + // var keys = new[] {"flag1", "flag2"}; + // var decisions = user.DecideForKeys(keys); + // Console.WriteLine(JsonConvert.SerializeObject(decisions)); + + // DecideAll + // var decisions = user.DecideAll(); + // Console.WriteLine(JsonConvert.SerializeObject(decisions)); + + // Set & Get & Remove ForcedDecision + // var context = new OptimizelyDecisionContext("flag1", "default-rollout-34902-22583870382"); + // var forcedDecision = new OptimizelyForcedDecision("off"); + // user.SetForcedDecision(context, forcedDecision); + // var result = user.GetForcedDecision(context); + // Console.WriteLine(JsonConvert.SerializeObject(result)); + // var wasRemoved = user.RemoveForcedDecision(context); + // Console.WriteLine($"Was removed: {wasRemoved}"); + + // Activate + // var variation = optimizelyClient.Activate("flag1", USER_ID); + // Console.WriteLine("Variation: " + JsonConvert.SerializeObject(variation)); + + // NotificationCenter + // // for Activate + // notificationCenter.AddNotification( + // NotificationCenter.NotificationType.Activate, + // NotificationCallbacks.ActivateCallback); + // optimizelyClient.Activate("flag1", USER_ID); + // // for Track + // notificationCenter.AddNotification( + // NotificationCenter.NotificationType.Track, + // NotificationCallbacks.TrackCallback); + // optimizelyClient.Track("myevent", USER_ID); + // // for Decision + // notificationCenter.AddNotification( + // NotificationCenter.NotificationType.Decision, + // NotificationCallbacks.DecisionCallback); + // user.Decide("flag1"); + + optimizelyClient.Dispose(); + } + } + + public static class NotificationCallbacks + { + public static void ActivateCallback(Experiment experiment, string userId, + UserAttributes userAttributes, + Variation variation, LogEvent logEvent + ) + { + Console.WriteLine(">>> Activate Callback"); + Console.WriteLine(experiment.Key); + Console.WriteLine(userId); + Console.WriteLine(userAttributes); + Console.WriteLine(variation.Key); + Console.WriteLine(JsonConvert.SerializeObject(logEvent)); + } + + public static void TrackCallback(string eventKey, string userId, + UserAttributes userAttributes, + EventTags eventTags, LogEvent logEvent + ) + { + Console.WriteLine(">>> Track Callback"); + Console.WriteLine(eventKey); + Console.WriteLine(userId); + Console.WriteLine(userAttributes); + Console.WriteLine(JsonConvert.SerializeObject(eventTags)); + Console.WriteLine(JsonConvert.SerializeObject(logEvent)); + } + + public static void DecisionCallback(string type, string userId, + UserAttributes userAttributes, + Dictionary decisionInfo + ) + { + Console.WriteLine(">>> Decision Callback"); + Console.WriteLine(type); + Console.WriteLine(userId); + Console.WriteLine(userAttributes); + Console.WriteLine(JsonConvert.SerializeObject(decisionInfo)); + } + + public static void ConfigUpdateCallback() + { + Console.WriteLine(">>> Config Update Callback"); + } + + public static void LogEventCallback(LogEvent logEvent) + { + Console.WriteLine(">>> Log Event Callback"); + Console.WriteLine(JsonConvert.SerializeObject(logEvent)); + } + } +} diff --git a/QuickStart/Properties/AssemblyInfo.cs b/QuickStart/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..f442705c --- /dev/null +++ b/QuickStart/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("QuickStart")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("QuickStart")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("74BAE350-8779-413A-A88E-AFE6A0A84D28")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/QuickStart/QuickStart.csproj b/QuickStart/QuickStart.csproj new file mode 100644 index 00000000..235f71cc --- /dev/null +++ b/QuickStart/QuickStart.csproj @@ -0,0 +1,68 @@ + + + + + Debug + AnyCPU + {74BAE350-8779-413A-A88E-AFE6A0A84D28} + Exe + Properties + QuickStart + QuickStart + v4.8 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll + + + + + + + + + + + + + {4dde7faa-110d-441c-ab3b-3f31b593e8bf} + OptimizelySDK + + + + + + + + + + diff --git a/QuickStart/packages.config b/QuickStart/packages.config new file mode 100644 index 00000000..4de699c9 --- /dev/null +++ b/QuickStart/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file