Esempio n. 1
0
        private void UpdateInternal(string key, FlagBuilder builder)
        {
            DataSourceImpl[] instances;
            int newVersion;

            lock (_lock)
            {
                if (!_currentFlagVersions.TryGetValue(key, out var oldVersion))
                {
                    oldVersion = 0;
                }
                newVersion = oldVersion + 1;
                _currentFlagVersions[key] = newVersion;
                if (builder is null)
                {
                    _currentBuilders.Remove(key);
                }
                else
                {
                    _currentBuilders[key] = builder;
                }
                instances = _instances.ToArray();
            }

            foreach (var instance in instances)
            {
                instance.DoUpdate(key, builder.CreateFlag(newVersion, instance.User));
            }
        }
Esempio n. 2
0
        private void UpdateInternal(string key, Func <int, ItemDescriptor> makeFlag, FlagBuilder builder)
        {
            ItemDescriptor newItem;

            DataSourceImpl[] instances;

            lock (_lock)
            {
                var oldVersion = _currentFlags.TryGetValue(key, out var oldItem) ?
                                 oldItem.Version : 0;
                newItem            = makeFlag(oldVersion + 1);
                _currentFlags[key] = newItem;
                if (builder is null)
                {
                    _currentBuilders.Remove(key);
                }
                else
                {
                    _currentBuilders[key] = builder;
                }
                instances = _instances.ToArray();
            }

            foreach (var instance in instances)
            {
                instance.DoUpdate(DataModel.Features, key, newItem);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Register flag for the command
        /// </summary>
        /// <param name="buildFlag">Action to configure flag using builder</param>
        /// <returns>Self instance</returns>
        public CommandConfigurator RegisterFlag(Action <FlagBuilder> buildFlag)
        {
            var flagBuilder = new FlagBuilder();

            buildFlag(flagBuilder);

            return(RegisterFlagInstance(flagBuilder.Build()));
        }
Esempio n. 4
0
        /// <summary>
        /// Updates the test data with the specified flag configuration.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This has the same effect as if a flag were added or modified on the LaunchDarkly dashboard.
        /// It immediately propagates the flag change to any <see cref="LdClient"/> instance(s) that
        /// you have already configured to use this <see cref="TestData"/>. If no <see cref="LdClient"/>
        /// has been started yet, it simply adds this flag to the test data which will be provided to any
        /// <see cref="LdClient"/> that you subsequently configure.
        /// </para>
        /// <para>
        /// Any subsequent changes to this <see cref="FlagBuilder"/> instance do not affect the test data,
        /// unless you call <see cref="Update(FlagBuilder)"/> again.
        /// </para>
        /// </remarks>
        /// <param name="flagBuilder">a flag configuration builder</param>
        /// <returns>the same <see cref="TestData"/> instance</returns>
        /// <seealso cref="Flag(string)"/>
        public TestData Update(FlagBuilder flagBuilder)
        {
            var key           = flagBuilder._key;
            var clonedBuilder = new FlagBuilder(flagBuilder);

            UpdateInternal(key, clonedBuilder);
            return(this);
        }
Esempio n. 5
0
 internal FlagBuilder(FlagBuilder from)
 {
     _key                = from._key;
     _variations         = new List <LdValue>(from._variations);
     _defaultVariation   = from._defaultVariation;
     _variationFunc      = from._variationFunc;
     _variationByUserKey = new Dictionary <string, int>(from._variationByUserKey);
     _preconfiguredFlag  = from._preconfiguredFlag;
 }
Esempio n. 6
0
 internal FlagBuilder(FlagBuilder from)
 {
     _key                  = from._key;
     _offVariation         = from._offVariation;
     _on                   = from._on;
     _fallthroughVariation = from._fallthroughVariation;
     _variations           = new List <LdValue>(from._variations);
     _targets              = from._targets == null ? null :
                             new Dictionary <int, ISet <string> >(from._targets);
     _rules = from._rules == null ? null :
              new List <FlagRuleBuilder>(from._rules);
 }
Esempio n. 7
0
 /// <summary>
 /// Finishes defining the rule, specifying the result value as a boolean.
 /// </summary>
 /// <param name="variation">the value to return if the rule matches the user</param>
 /// <returns></returns>
 public FlagBuilder ThenReturn(bool variation)
 {
     _parent.BooleanFlag();
     return(ThenReturn(FlagBuilder.VariationForBoolean(variation)));
 }
Esempio n. 8
0
 internal FlagRuleBuilder(FlagBuilder parent)
 {
     _parent = parent;
 }