Пример #1
0
        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 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);
         }
     }
 }
Пример #3
0
        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 LdClientEvaluationTest(ITestOutputHelper testOutput) : base(testOutput)
        {
            var config = BasicConfig()
                         .DataSource(testData)
                         .Build();

            client = new LdClient(config);
        }
 private void VerifyNoFlagValues(ILdClient client, IDictionary <string, string> flags)
 {
     Assert.True(client.Initialized);
     foreach (var e in flags)
     {
         Assert.Null(client.StringVariation(e.Key, null));
     }
 }
Пример #6
0
 private void VerifyNoFlagValues(ILdClient client, FullDataSet flags)
 {
     Assert.True(client.Initialized);
     foreach (var e in flags.Items)
     {
         Assert.Equal(LdValue.Null, client.JsonVariation(e.Key, LdValue.Null));
     }
 }
Пример #7
0
        public LdClientEvaluationTest()
        {
            var config = Configuration.Default("SDK_KEY")
                         .WithFeatureStoreFactory(new SpecificFeatureStoreFactory(featureStore))
                         .WithEventProcessorFactory(Components.NullEventProcessor)
                         .WithUpdateProcessorFactory(Components.NullUpdateProcessor);

            client = new LdClient(config);
        }
Пример #8
0
        public LdClientEventTest()
        {
            var config = Configuration.Default("SDK_KEY")
                         .WithFeatureStoreFactory(TestUtils.SpecificFeatureStore(featureStore))
                         .WithEventProcessorFactory(TestUtils.SpecificEventProcessor(eventSink))
                         .WithUpdateProcessorFactory(Components.NullUpdateProcessor);

            client = new LdClient(config);
        }
Пример #9
0
        public LdClientEventTest(ITestOutputHelper testOutput) : base(testOutput)
        {
            var config = BasicConfig()
                         .DataSource(testData)
                         .Events(eventSink.AsSingletonFactory())
                         .Build();

            client = new LdClient(config);
        }
Пример #10
0
        public LdClientEventTest(ITestOutputHelper testOutput) : base(testOutput)
        {
            var config = Configuration.Builder("SDK_KEY")
                         .DataSource(testData)
                         .Events(TestUtils.SpecificEventProcessor(eventSink))
                         .Logging(Components.Logging(testLogging))
                         .Build();

            client = new LdClient(config);
        }
Пример #11
0
        public LdClientEvaluationTest()
        {
            var config = Configuration.Builder("SDK_KEY")
                         .FeatureStoreFactory(new SpecificFeatureStoreFactory(featureStore))
                         .EventProcessorFactory(Components.NullEventProcessor)
                         .UpdateProcessorFactory(Components.NullUpdateProcessor)
                         .Build();

            client = new LdClient(config);
        }
        public LdClientEventTest()
        {
            var config = Configuration.Builder("SDK_KEY")
                         .FeatureStoreFactory(TestUtils.SpecificFeatureStore(featureStore))
                         .EventProcessorFactory(TestUtils.SpecificEventProcessor(eventSink))
                         .UpdateProcessorFactory(Components.NullUpdateProcessor)
                         .Build();

            client = new LdClient(config);
        }
        public LdClientEvaluationTest(ITestOutputHelper testOutput) : base(testOutput)
        {
            var config = Configuration.Builder("SDK_KEY")
                         .DataSource(testData)
                         .Events(Components.NoEvents)
                         .Logging(Components.Logging(testLogging))
                         .Build();

            client = new LdClient(config);
        }
Пример #14
0
        public FeatureToggleService(IFeatureToggleConfiguration configuration, ILogger <FeatureToggleService> logger)
        {
            var store = DynamoDBComponents.DynamoDBFeatureStore(configuration.TableName)
                        .WithCaching(FeatureStoreCacheConfig.Enabled.WithTtlSeconds(configuration.CacheDurationInSeconds));

            var ldConfig = new LaunchDarkly.Client.Configuration()
                           .WithFeatureStoreFactory(store).WithOffline(true);

            _ldClient = new LdClient(ldConfig);
            _logger   = logger;
        }
Пример #15
0
        /// <summary>
        /// Equivalent to <see cref="ILdClient.StringVariation(string, string)"/>, but converts the
        /// flag's string value to an enum value.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If the flag has a value that is not one of the allowed enum value names, or is not a string,
        /// <c>defaultValue</c> is returned.
        /// </para>
        /// </remarks>
        /// <typeparam name="T">the enum type</typeparam>
        /// <param name="client">the client instance</param>
        /// <param name="key">the unique feature key for the feature flag</param>
        /// <param name="defaultValue">the default value of the flag (as an enum value)</param>
        /// <returns>the variation for the given user, or <c>defaultValue</c> if the flag cannot
        /// be evaluated or does not have a valid enum value</returns>
        public static T EnumVariation <T>(this ILdClient client, string key, T defaultValue) where T : struct, Enum
        {
            var stringVal = client.StringVariation(key, defaultValue.ToString());

            if (stringVal != null)
            {
                if (Enum.TryParse <T>(stringVal, out var enumValue))
                {
                    return(enumValue);
                }
            }
            return(defaultValue);
        }
Пример #16
0
        /// <summary>
        /// Equivalent to <see cref="ILdClient.StringVariationDetail(string, string)"/>, but converts the
        /// flag's string value to an enum value.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If the flag has a value that is not one of the allowed enum value names, or is not a string,
        /// <c>defaultValue</c> is returned.
        /// </para>
        /// </remarks>
        /// <typeparam name="T">the enum type</typeparam>
        /// <param name="client">the client instance</param>
        /// <param name="key">the unique feature key for the feature flag</param>
        /// <param name="defaultValue">the default value of the flag (as an enum value)</param>
        /// <returns>an <see cref="EvaluationDetail{T}"/> object</returns>
        public static EvaluationDetail <T> EnumVariationDetail <T>(this ILdClient client,
                                                                   string key, T defaultValue) where T : struct, Enum
        {
            var stringDetail = client.StringVariationDetail(key, defaultValue.ToString());

            if (!stringDetail.IsDefaultValue && stringDetail.Value != null)
            {
                if (Enum.TryParse <T>(stringDetail.Value, out var enumValue))
                {
                    return(new EvaluationDetail <T>(enumValue, stringDetail.VariationIndex, stringDetail.Reason));
                }
                return(new EvaluationDetail <T>(defaultValue, stringDetail.VariationIndex, EvaluationReason.ErrorReason(EvaluationErrorKind.WrongType)));
            }
            return(new EvaluationDetail <T>(defaultValue, stringDetail.VariationIndex, stringDetail.Reason));
        }
        /// <summary>
        /// Equivalent to <see cref="ILdClient.StringVariation(string, User, string)"/>, but converts the
        /// flag's string value to an enum value.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If the flag has a value that is not one of the allowed enum value names, or is not a string,
        /// <c>defaultValue</c> is returned.
        /// </para>
        /// <para>
        /// Note that there is no type constraint to guarantee that T really is an enum type, because that is
        /// a C# 7.3 feature that is unavailable in older versions of .NET Standard. If you try to use a
        /// non-enum type, you will simply receive the default value back.
        /// </para>
        /// </remarks>
        /// <typeparam name="T">the enum type</typeparam>
        /// <param name="client">the client instance</param>
        /// <param name="key">the unique feature key for the feature flag</param>
        /// <param name="user">the end user requesting the flag</param>
        /// <param name="defaultValue">the default value of the flag (as an enum value)</param>
        /// <returns>the variation for the given user, or <c>defaultValue</c> if the flag cannot
        /// be evaluated or does not have a valid enum value</returns>
        public static T EnumVariation <T>(this ILdClient client, string key, User user, T defaultValue)
        {
            var stringVal = client.StringVariation(key, user, defaultValue.ToString());

            if (stringVal != null)
            {
                try
                {
                    return((T)System.Enum.Parse(typeof(T), stringVal, true));
                }
                catch (System.ArgumentException)
                { }
            }
            return(defaultValue);
        }
        /// <summary>
        /// Equivalent to <see cref="ILdClient.StringVariationDetail(string, User, string)"/>, but converts the
        /// flag's string value to an enum value.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If the flag has a value that is not one of the allowed enum value names, or is not a string,
        /// <c>defaultValue</c> is returned.
        /// </para>
        /// <para>
        /// Note that there is no type constraint to guarantee that T really is an enum type, because that is
        /// a C# 7.3 feature that is unavailable in older versions of .NET Standard. If you try to use a
        /// non-enum type, you will simply receive the default value back.
        /// </para>
        /// </remarks>
        /// <typeparam name="T">the enum type</typeparam>
        /// <param name="client">the client instance</param>
        /// <param name="key">the unique feature key for the feature flag</param>
        /// <param name="user">the end user requesting the flag</param>
        /// <param name="defaultValue">the default value of the flag (as an enum value)</param>
        /// <returns>an <see cref="EvaluationDetail{T}"/> object</returns>
        public static EvaluationDetail <T> EnumVariationDetail <T>(this ILdClient client, string key, User user, T defaultValue)
        {
            var stringDetail = client.StringVariationDetail(key, user, defaultValue.ToString());

            if (stringDetail.Value != null)
            {
                try
                {
                    var enumValue = (T)System.Enum.Parse(typeof(T), stringDetail.Value, true);
                    return(new EvaluationDetail <T>(enumValue, stringDetail.VariationIndex, stringDetail.Reason));
                }
                catch (System.ArgumentException)
                {
                    return(new EvaluationDetail <T>(defaultValue, stringDetail.VariationIndex, EvaluationReason.ErrorReason(EvaluationErrorKind.WRONG_TYPE)));
                }
            }
            return(new EvaluationDetail <T>(defaultValue, stringDetail.VariationIndex, stringDetail.Reason));
        }
Пример #19
0
 protected LaunchDarklyFeatureToggleProvider(ILdClient ldClient)
 {
     _ldClient = ldClient;
 }
 public LaunchDarklyFeatureFlagProvider(Configuration configuration)
 {
     _ldClient    = new LdClient(configuration);
     _defaultUser = new User("Default");
 }
Пример #21
0
 public FeatureFlagService(ILdClient ldClient)
 {
     _ldClient = ldClient;
 }
Пример #22
0
 public HomeController(ILdClient ldClient, IOptions <SampleAppOptions> sampleAppOptions)
 {
     _ldClient         = ldClient;
     _sampleAppOptions = sampleAppOptions;
 }
Пример #23
0
 public AnonymousFeatureToggleProvider(ILdClient ldClient)
     : base(ldClient)
 {
     _key = Guid.NewGuid().ToString();
 }
Пример #24
0
        /// <summary>
        /// Add the Launch Darkly Service with a custom LaunchDarkly client config.
        /// </summary>
        /// <param name="serviceCollection">Services Collection to add the singleton to.</param>
        /// <param name="ldClient">Launch darkly client</param>
        /// <returns>IServiceCollection</returns>
        ///
        public static IServiceCollection AddLaunchDarklyFeatureFlags(this IServiceCollection serviceCollection, ILdClient ldClient)
        {
            var launchDarklyClient = new LaunchDarklyService(ldClient);

            serviceCollection.AddSingleton <IFeatureFlag>(launchDarklyClient);

            return(serviceCollection);
        }
Пример #25
0
 /// <summary>
 /// Simple constructor when using custom Launch Darkly Client - should only be used for testing
 /// </summary>
 /// <param name="ldClient">Launch Darkly client</param>
 /// <param name="logger">Optional logger</param>
 internal LaunchDarklyService(ILdClient ldClient, ILogger logger = null)
 {
     _ldClient = ldClient;
     _logger   = logger;
 }