static void Main(string[] args) { var ldConfig = LaunchDarkly.Client.Configuration.Default("sdk-219b665b-50fd-4c57-809f-d5e9c94fcd9a"); var client = new LdClient(ldConfig); var user = User.Builder("*****@*****.**") .FirstName("Gohar") .LastName("Aziz") .Custom("groups", "beta_testers") .Build(); var value = client.BoolVariation("search-bug-fix", user, false); if (value) { Console.WriteLine("Showing feature for user " + user.Key); } else { Console.WriteLine("Not showing feature for user " + user.Key); } client.Flush(); Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
public void VariationSendsFeatureEventWithReasonForUnknownFlagWhenClientIsNotInitialized() { var config = TestUtil.ConfigWithFlagsJson(user, "appkey", "") .UpdateProcessorFactory(MockUpdateProcessorThatNeverInitializes.Factory()) .EventProcessor(eventProcessor); config.EventProcessor(eventProcessor); using (LdClient client = TestUtil.CreateClient(config.Build(), user)) { EvaluationDetail <string> result = client.StringVariationDetail("flag", "b"); var expectedReason = EvaluationReason.ErrorReason(EvaluationErrorKind.CLIENT_NOT_READY); Assert.Equal("b", result.Value); Assert.Equal(expectedReason, result.Reason); Assert.Collection(eventProcessor.Events, e => CheckIdentifyEvent(e, user), e => { FeatureRequestEvent fe = Assert.IsType <FeatureRequestEvent>(e); Assert.Equal("flag", fe.Key); Assert.Equal("b", fe.Value.AsString); Assert.Null(fe.Variation); Assert.Null(fe.Version); Assert.Equal("b", fe.Default.AsString); Assert.False(fe.TrackEvents); Assert.Null(fe.DebugEventsUntilDate); Assert.Equal(expectedReason, fe.Reason); }); } }
public void VariationSendsFeatureEventForValidFlag() { string flagsJson = @"{""flag"":{ ""value"":""a"",""variation"":1,""version"":1000, ""trackEvents"":true, ""debugEventsUntilDate"":2000 }}"; using (LdClient client = MakeClient(user, flagsJson)) { string result = client.StringVariation("flag", "b"); Assert.Equal("a", result); Assert.Collection(eventProcessor.Events, e => CheckIdentifyEvent(e, user), e => { FeatureRequestEvent fe = Assert.IsType <FeatureRequestEvent>(e); Assert.Equal("flag", fe.Key); Assert.Equal("a", fe.Value.AsString); Assert.Equal(1, fe.Variation); Assert.Equal(1000, fe.Version); Assert.Equal("b", fe.Default.AsString); Assert.True(fe.TrackEvents); Assert.Equal(2000, fe.DebugEventsUntilDate); Assert.Null(fe.Reason); }); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Main); messageView = FindViewById <TextView>(Resource.Id.MessageView); if (string.IsNullOrEmpty(LaunchDarklyParameters.MobileKey)) { SetMessage(ExampleMessages.MobileKeyNotSet); } else { client = LdClient.Init( // These values are set in the Shared project LaunchDarklyParameters.MobileKey, LaunchDarklyParameters.DefaultUser, LaunchDarklyParameters.SDKTimeout ); if (client.Initialized) { UpdateFlagValue(); client.FlagChanged += FeatureFlagChanged; } else { SetMessage(ExampleMessages.InitializationFailed); } } }
public void VariationSendsFeatureEventForUnknownFlagWhenClientIsNotInitialized() { var config = TestUtil.ConfigWithFlagsJson(user, "appkey", "") .UpdateProcessorFactory(MockUpdateProcessorThatNeverInitializes.Factory()) .EventProcessor(eventProcessor); config.EventProcessor(eventProcessor); using (LdClient client = TestUtil.CreateClient(config.Build(), user)) { string result = client.StringVariation("flag", "b"); Assert.Equal("b", result); Assert.Collection(eventProcessor.Events, e => CheckIdentifyEvent(e, user), e => { FeatureRequestEvent fe = Assert.IsType <FeatureRequestEvent>(e); Assert.Equal("flag", fe.Key); Assert.Equal("b", fe.Value.AsString); Assert.Null(fe.Variation); Assert.Null(fe.Version); Assert.Equal("b", fe.Default.AsString); Assert.Null(fe.Reason); }); } }
public void DiagnosticStoreNotPassedToFactoriesWhenOptedOut() { var epfwd = new Mock <IEventProcessorFactoryWithDiagnostics>(); var upfwd = new Mock <IUpdateProcessorFactoryWithDiagnostics>(); var config = Configuration.Builder("SDK_KEY") .IsStreamingEnabled(false) .BaseUri(new Uri("http://fake")) .StartWaitTime(TimeSpan.Zero) .EventProcessorFactory(epfwd.Object) .UpdateProcessorFactory(upfwd.Object) .DiagnosticOptOut(true) .Build(); epfwd.Setup(epf => epf.CreateEventProcessor(config, It.IsAny <IDiagnosticStore>())) .Returns(Components.NullEventProcessor.CreateEventProcessor(config)); upfwd.Setup(upf => upf.CreateUpdateProcessor(config, It.IsAny <IFeatureStore>(), It.IsAny <IDiagnosticStore>())) .Returns(updateProcessor); using (var client = new LdClient(config)) { epfwd.Verify(epf => epf.CreateEventProcessor(config, null), Times.Once()); epfwd.VerifyNoOtherCalls(); upfwd.Verify(upf => upf.CreateUpdateProcessor(config, It.IsNotNull <IFeatureStore>(), null), Times.Once()); upfwd.VerifyNoOtherCalls(); } }
public void DiagnosticStorePassedToFactoriesWhenSupported() { var epfwd = new Mock <IEventProcessorFactoryWithDiagnostics>(); var upfwd = new Mock <IUpdateProcessorFactoryWithDiagnostics>(); var config = Configuration.Builder("SDK_KEY") .IsStreamingEnabled(false) .BaseUri(new Uri("http://fake")) .StartWaitTime(TimeSpan.Zero) .EventProcessorFactory(epfwd.Object) .UpdateProcessorFactory(upfwd.Object) .Build(); IDiagnosticStore eventProcessorDiagnosticStore = null; IDiagnosticStore updateProcessorDiagnosticStore = null; epfwd.Setup(epf => epf.CreateEventProcessor(config, It.IsAny <IDiagnosticStore>())) .Callback <Configuration, IDiagnosticStore>((c, ds) => eventProcessorDiagnosticStore = ds) .Returns(Components.NullEventProcessor.CreateEventProcessor(config)); upfwd.Setup(upf => upf.CreateUpdateProcessor(config, It.IsAny <IFeatureStore>(), It.IsAny <IDiagnosticStore>())) .Callback <Configuration, IFeatureStore, IDiagnosticStore>((c, fs, ds) => updateProcessorDiagnosticStore = ds) .Returns(updateProcessor); using (var client = new LdClient(config)) { epfwd.Verify(epf => epf.CreateEventProcessor(config, It.IsNotNull <IDiagnosticStore>()), Times.Once()); epfwd.VerifyNoOtherCalls(); upfwd.Verify(upf => upf.CreateUpdateProcessor(config, It.IsNotNull <IFeatureStore>(), It.IsNotNull <IDiagnosticStore>()), Times.Once()); upfwd.VerifyNoOtherCalls(); Assert.True(eventProcessorDiagnosticStore == updateProcessorDiagnosticStore); } }
private static void ConnectUsingLdClient() { var props = new Common.Logging.Configuration.NameValueCollection { { "level", "warn" } }; LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(props); var ldConfig = LaunchDarkly.Client.Configuration .Default(TestSdkKey) //.WithIsStreamingEnabled(false)//; .WithUri("http://sudawsm:49345/") .WithStreamUri("http://sudawsm:49345/") .WithEventsUri("http://sudawsm:49345/"); LdClient client = new LdClient(ldConfig); User user = User.WithKey("Default"); for (int i = 0; i < 100; i++) { var value = client.BoolVariation(TestFeatureFlag, user, false); Log("got value {0}", value); Log( value ? "Showing feature for user {0}, iteration: {1}" : "Not showing feature for user {0}, iteration: {1}", user.Key, i); client.Flush(); Task.Delay(TimeSpan.FromMilliseconds(5000)).Wait(); } Log("Finished, press any key to continue"); Console.ReadKey(); }
public static void TrackFeatureFlag(LdClient ldclient, string userkey, string customEvent) { User user = User.WithKey(userkey); ldclient.Track(customEvent, user, null); ldclient.Flush(); }
public override void ViewDidLoad() { base.ViewDidLoad(); if (string.IsNullOrEmpty(DemoParameters.MobileKey)) { SetMessage(DemoMessages.MobileKeyNotSet); } else { client = LdClient.Init( DemoParameters.MobileKey, DemoParameters.MakeDemoUser(), DemoParameters.SDKTimeout ); if (client.Initialized) { UpdateFlagValue(); client.FlagTracker.FlagValueChanged += FeatureFlagChanged; } else { SetMessage(DemoMessages.InitializationFailed); } } }
public void SharedClientIsTheOnlyClientAvailable() { var client = Client(); var config = Configuration.Default(appKey); Assert.ThrowsAsync <Exception>(async() => await LdClient.InitAsync(config, User.WithKey("otherUserKey"))); }
static void Main(string[] args) { var props = new Common.Logging.Configuration.NameValueCollection { { "level", "Debug" } }; LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(props); Configuration ldConfig = LaunchDarkly.Client.Configuration // TODO: Enter your LaunchDarkly SDK key here .Default("YOUR_SDK_KEY"); LdClient client = new LdClient(ldConfig); User user = User.WithKey("*****@*****.**") .AndFirstName("Bob") .AndLastName("Loblaw") .AndCustomAttribute("groups", "beta_testers"); // TODO: Enter the key for your feature flag key here var value = client.BoolVariation("YOUR_FEATURE_FLAG_KEY", user, false); if (value) { Console.WriteLine("Showing feature for user " + user.Key); } else { Console.WriteLine("Not showing feature for user " + user.Key); } client.Flush(); Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
private async Task IdentifyCompletesOnlyWhenNewFlagsAreAvailable(Func <LdClient, User, Task> identifyTask) { var userA = User.WithKey("a"); var userB = User.WithKey("b"); var flagKey = "flag"; var userAFlags = TestUtil.MakeSingleFlagData(flagKey, "a-value"); var userBFlags = TestUtil.MakeSingleFlagData(flagKey, "b-value"); var startedIdentifyUserB = new SemaphoreSlim(0, 1); var canFinishIdentifyUserB = new SemaphoreSlim(0, 1); var finishedIdentifyUserB = new SemaphoreSlim(0, 1); Func <Configuration, IFlagCacheManager, User, IMobileUpdateProcessor> updateProcessorFactory = (c, flags, user) => new MockUpdateProcessorFromLambda(user, async() => { switch (user.Key) { case "a": flags.CacheFlagsFromService(userAFlags, user); break; case "b": startedIdentifyUserB.Release(); await canFinishIdentifyUserB.WaitAsync(); flags.CacheFlagsFromService(userBFlags, user); break; } }); var config = TestUtil.ConfigWithFlagsJson(userA, appKey, "{}") .UpdateProcessorFactory(updateProcessorFactory) .Build(); ClearCachedFlags(userA); ClearCachedFlags(userB); using (var client = await LdClient.InitAsync(config, userA)) { Assert.True(client.Initialized); Assert.Equal("a-value", client.StringVariation(flagKey, null)); var identifyUserBTask = Task.Run(async() => { await identifyTask(client, userB); finishedIdentifyUserB.Release(); }); await startedIdentifyUserB.WaitAsync(); Assert.False(client.Initialized); Assert.Null(client.StringVariation(flagKey, null)); canFinishIdentifyUserB.Release(); await finishedIdentifyUserB.WaitAsync(); Assert.True(client.Initialized); Assert.Equal("b-value", client.StringVariation(flagKey, null)); } }
public void CanCreateClientWithInfiniteWaitTime() { var config = TestUtil.ConfigWithFlagsJson(simpleUser, appKey, "{}").Build(); using (var client = LdClient.Init(config, simpleUser, System.Threading.Timeout.InfiniteTimeSpan)) { } TestUtil.ClearClient(); }
public void SetupClient() { if (string.IsNullOrEmpty(LaunchDarklyParameters.MobileKey)) { SetMessage(ExampleMessages.MobileKeyNotSet); } else { client = LdClient.Init( // These values are set in the Shared project LaunchDarklyParameters.MobileKey, LaunchDarklyParameters.DefaultUser, LaunchDarklyParameters.SDKTimeout ); if (client.Initialized) { UpdateFlagValue(); client.FlagChanged += FeatureFlagChanged; } else { SetMessage(ExampleMessages.InitializationFailed); } } }
public Startup(IConfiguration configuration) { Configuration = configuration; var featureFlagKey = Environment.GetEnvironmentVariable("FEATUREFLAG_KEY"); FeatureFlag = new LdClient(featureFlagKey); }
public void VariationDetailSendsFeatureEventWithReasonForValidFlag() { string flagsJson = @"{""flag"":{ ""value"":""a"",""variation"":1,""version"":1000, ""trackEvents"":true, ""debugEventsUntilDate"":2000, ""reason"":{""kind"":""OFF""} }}"; using (LdClient client = MakeClient(user, flagsJson)) { EvaluationDetail <string> result = client.StringVariationDetail("flag", "b"); Assert.Equal("a", result.Value); Assert.Equal(EvaluationReason.Off.Instance, result.Reason); Assert.Collection(eventProcessor.Events, e => CheckIdentifyEvent(e, user), e => { FeatureRequestEvent fe = Assert.IsType <FeatureRequestEvent>(e); Assert.Equal("flag", fe.Key); Assert.Equal("a", fe.Value); Assert.Equal(1, fe.Variation); Assert.Equal(1000, fe.Version); Assert.Equal("b", fe.Default); Assert.True(fe.TrackEvents); Assert.Equal(2000, fe.DebugEventsUntilDate); Assert.Equal(EvaluationReason.Off.Instance, fe.Reason); }); } }
public void InitializesWithEmptyData() { using (var client = new LdClient(_config)) { Assert.True(client.Initialized); } }
static void Main(string[] args) { if (string.IsNullOrEmpty(DemoParameters.MobileKey)) { ShowMessage(DemoMessages.MobileKeyNotSet); Environment.Exit(1); } LdClient client = LdClient.Init( DemoParameters.MobileKey, DemoParameters.MakeDemoUser(), DemoParameters.SDKTimeout ); if (client.Initialized) { ShowMessage(DemoMessages.InitializationSucceeded); } else { ShowMessage(DemoMessages.InitializationFailed); Environment.Exit(1); } var flagValue = client.BoolVariation(DemoParameters.FeatureFlagKey, false); ShowMessage(string.Format(DemoMessages.FlagValueIs, DemoParameters.FeatureFlagKey, flagValue)); // Here we ensure that the SDK shuts down cleanly and has a chance to deliver analytics // events to LaunchDarkly before the program exits. If analytics events are not delivered, // the user properties and flag usage statistics will not appear on your dashboard. In a // normal long-running application, the SDK would continue running and events would be // delivered automatically in the background. client.Dispose(); }
public Demo() { _client = LaunchDarklyConfig.Configure(); PopulateUsers(); PopulateFlags(); }
public void CanSetValuePerUser() { _td.Update(_td.Flag("flag") .Variations(LdValue.Of("red"), LdValue.Of("green"), LdValue.Of("blue")) .Variation(LdValue.Of("red")) .VariationForUser("user1", LdValue.Of("green")) .VariationForUser("user2", LdValue.Of("blue")) .VariationFunc(user => user.GetAttribute(UserAttribute.ForName("favoriteColor")) )); var user1 = User.WithKey("user1"); var user2 = User.WithKey("user2"); var user3 = User.Builder("user3").Custom("favoriteColor", "green").Build(); using (var client = LdClient.Init(_config, user1, TimeSpan.FromSeconds(1))) { Assert.Equal("green", client.StringVariation("flag", "")); client.Identify(user2, TimeSpan.FromSeconds(1)); Assert.Equal("blue", client.StringVariation("flag", "")); client.Identify(user3, TimeSpan.FromSeconds(1)); Assert.Equal("green", client.StringVariation("flag", "")); } }
public bool Initialize() { if (IsInitialized) { return(false); } if (mobileKey.Length == 0 || userKey.Length == 0) { Debug.LogError("User and mobile key must be defined for initialization to complete. Initialization failed."); return(false); } Configuration ldConfiguration = Configuration.Builder(mobileKey).Build(); RefreshUserAttributes(); User ldUser = userBuilder.Build(); ldClient = LdClient.Init(ldConfiguration, ldUser, System.TimeSpan.FromMilliseconds(connectionTimeoutMS)); hasAttributesPending = false; ldClient.FlagChanged += OnFlagChanged; ManuallyCallCallbacks(); return(ldClient.Initialized); }
public void InitializesWithEmptyData() { using (var client = LdClient.Init(_config, _user, TimeSpan.FromSeconds(1))) { Assert.True(client.Initialized); } }
private async void InitializeClients() { var config = Configuration.Default(MOBILE_KEY_TEST) .WithStartWaitTime(TimeSpan.Zero); var _user = User.WithKey("*****@*****.**"); var _client = LdClient.Init(config, _user); }
public void InitializesWithFlag() { _td.Update(_td.Flag("flag").On(true)); using (var client = new LdClient(_config)) { Assert.True(client.BoolVariation("flag", _user, false)); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { LdClient ldClient = new LdClient(Configuration["LaunchDarklySdkKey"]); services.AddSingleton(ldClient); services.AddTransient <IProductsProvider>(x => new ProductsProvider(Configuration.GetSection("ConnectionStrings")["FoodDb"])); services.AddTransient <IUsersProvider, InMemoryUsersProvider>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
public void InitializesWithFlag() { _td.Update(_td.Flag("flag").Variation(true)); using (var client = LdClient.Init(_config, _user, TimeSpan.FromSeconds(1))) { Assert.True(client.BoolVariation("flag", false)); } }
public FeatureToggleRepository(string launchDarkleyApiKey) { if (string.IsNullOrWhiteSpace(launchDarkleyApiKey)) { throw new ArgumentNullException(nameof(launchDarkleyApiKey)); } client = new LdClient(launchDarkleyApiKey); }
public void OfflineReturnsDefaultValue() { var config = Configuration.Builder("SDK_KEY").Offline(true).Build(); using (var client = new LdClient(config)) { Assert.Equal("x", client.StringVariation("key", User.WithKey("user"), "x")); } }
public void OfflineClientIsInitialized() { var config = Configuration.Builder("SDK_KEY").Offline(true).Build(); using (var client = new LdClient(config)) { Assert.True(client.Initialized()); } }