コード例 #1
0
        public void UpsertPassesDataToStore()
        {
            var flag1a   = new FeatureFlagBuilder().Version(100).Value(LdValue.Of(false)).Build();
            var initData = new DataSetBuilder().Add("key1", flag1a).Build();

            _updateSink.Init(_basicUser, initData);

            var flag1b = new FeatureFlagBuilder().Version(101).Value(LdValue.Of(true)).Build();

            _updateSink.Upsert(_basicUser, "key1", flag1b.ToItemDescriptor());

            Assert.Equal(flag1b.ToItemDescriptor(), _store.Get("key1"));
        }
コード例 #2
0
        EvaluationDetail <T> VariationInternal <T>(string featureKey, LdValue defaultJson, LdValue.Converter <T> converter, bool checkType, EventFactory eventFactory)
        {
            T defaultValue = converter.ToType(defaultJson);

            EvaluationDetail <T> errorResult(EvaluationErrorKind kind) =>
            new EvaluationDetail <T>(defaultValue, null, EvaluationReason.ErrorReason(kind));

            var flag = _dataStore.Get(featureKey)?.Item;

            if (flag == null)
            {
                if (!Initialized)
                {
                    _log.Warn("LaunchDarkly client has not yet been initialized. Returning default value");
                    SendEvaluationEventIfOnline(eventFactory.NewUnknownFlagEvaluationEvent(featureKey, User, defaultJson,
                                                                                           EvaluationErrorKind.ClientNotReady));
                    return(errorResult(EvaluationErrorKind.ClientNotReady));
                }
                else
                {
                    _log.Info("Unknown feature flag {0}; returning default value", featureKey);
                    SendEvaluationEventIfOnline(eventFactory.NewUnknownFlagEvaluationEvent(featureKey, User, defaultJson,
                                                                                           EvaluationErrorKind.FlagNotFound));
                    return(errorResult(EvaluationErrorKind.FlagNotFound));
                }
            }
            else
            {
                if (!Initialized)
                {
                    _log.Warn("LaunchDarkly client has not yet been initialized. Returning cached value");
                }
            }

            EvaluationDetail <T> result;
            LdValue valueJson;

            if (flag.Value.IsNull)
            {
                valueJson = defaultJson;
                result    = new EvaluationDetail <T>(defaultValue, flag.Variation, flag.Reason ?? EvaluationReason.OffReason);
            }
            else
            {
                if (checkType && !defaultJson.IsNull && flag.Value.Type != defaultJson.Type)
                {
                    valueJson = defaultJson;
                    result    = new EvaluationDetail <T>(defaultValue, null, EvaluationReason.ErrorReason(EvaluationErrorKind.WrongType));
                }
                else
                {
                    valueJson = flag.Value;
                    result    = new EvaluationDetail <T>(converter.ToType(flag.Value), flag.Variation, flag.Reason ?? EvaluationReason.OffReason);
                }
            }
            var featureEvent = eventFactory.NewEvaluationEvent(featureKey, flag, User,
                                                               new EvaluationDetail <LdValue>(valueJson, flag.Variation, flag.Reason ?? EvaluationReason.OffReason), defaultJson);

            SendEvaluationEventIfOnline(featureEvent);
            return(result);
        }