Ejemplo n.º 1
0
        // This method was formerly part of User. It has been moved here because it is only needed
        // for server-side evaluation logic, specifically for comparing values with an Operator.
        // Note that ImmutableJsonValue.Of(string) is an efficient operation that does not allocate
        // a new object, but just wraps the string in a struct (or returns ImmutableJsonValue.Null
        // if the string is null).
        public static LdValue GetUserAttributeForEvaluation(User user, string attribute)
        {
            switch (attribute)
            {
            case "key":
                return(LdValue.Of(user.Key));

            case "secondary":
                return(LdValue.Of(user.Secondary));

            case "ip":
                return(LdValue.Of(user.IPAddress));

            case "email":
                return(LdValue.Of(user.Email));

            case "avatar":
                return(LdValue.Of(user.Avatar));

            case "firstName":
                return(LdValue.Of(user.FirstName));

            case "lastName":
                return(LdValue.Of(user.LastName));

            case "name":
                return(LdValue.Of(user.Name));

            case "country":
                return(LdValue.Of(user.Country));

            case "anonymous":
                if (user.Anonymous.HasValue)
                {
                    return(LdValue.Of(user.Anonymous.Value));
                }
                return(LdValue.Null);

            default:
                return(user.Custom.TryGetValue(attribute, out var customValue) ?
                       LdValue.FromSafeValue(customValue) :
                       LdValue.Null);
            }
        }
Ejemplo n.º 2
0
 public void Track(string name, User user, string data)
 {
     Track(name, user, LdValue.Of(data));
 }
Ejemplo n.º 3
0
 /// <inheritdoc/>
 public EvaluationDetail <string> StringVariationDetail(string key, User user, string defaultValue)
 {
     return(Evaluate(key, user, LdValue.Of(defaultValue), LdValue.Convert.String, true, EventFactory.DefaultWithReasons));
 }
Ejemplo n.º 4
0
 /// <inheritdoc/>
 public EvaluationDetail <float> FloatVariationDetail(string key, User user, float defaultValue)
 {
     return(Evaluate(key, user, LdValue.Of(defaultValue), LdValue.Convert.Float, true, EventFactory.DefaultWithReasons));
 }
Ejemplo n.º 5
0
 /// <inheritdoc/>
 public EvaluationDetail <bool> BoolVariationDetail(string key, User user, bool defaultValue)
 {
     return(Evaluate(key, user, LdValue.Of(defaultValue), LdValue.Convert.Bool, true, EventFactory.DefaultWithReasons));
 }
Ejemplo n.º 6
0
 /// <inheritdoc/>
 public string StringVariation(string key, User user, string defaultValue)
 {
     return(Evaluate(key, user, LdValue.Of(defaultValue), LdValue.Convert.String, true, EventFactory.Default).Value);
 }
Ejemplo n.º 7
0
 /// <inheritdoc/>
 public float FloatVariation(string key, User user, float defaultValue)
 {
     return(Evaluate(key, user, LdValue.Of(defaultValue), LdValue.Convert.Float, true, EventFactory.Default).Value);
 }
Ejemplo n.º 8
0
 /// <inheritdoc/>
 public int IntVariation(string key, User user, int defaultValue)
 {
     return(Evaluate(key, user, LdValue.Of(defaultValue), LdValue.Convert.Int, true, EventFactory.Default).Value);
 }
Ejemplo n.º 9
0
 /// <inheritdoc/>
 public bool BoolVariation(string key, User user, bool defaultValue = false)
 {
     return(Evaluate(key, user, LdValue.Of(defaultValue), LdValue.Convert.Bool, true, EventFactory.Default).Value);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Adds a key-value pair to the object being built.
 /// </summary>
 /// <param name="key">the key to add</param>
 /// <param name="value">the value to add</param>
 /// <returns>the same builder</returns>
 public ObjectBuilder Add(string key, string value)
 {
     _builder.Add(key, LdValue.Of(value));
     return(this);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Adds a value to the array being built.
 /// </summary>
 /// <param name="value">the value to add</param>
 /// <returns>the same builder</returns>
 public ArrayBuilder Add(string value)
 {
     _builder.Add(LdValue.Of(value));
     return(this);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Adds a value to the array being built.
 /// </summary>
 /// <param name="value">the value to add</param>
 /// <returns>the same builder</returns>
 public ArrayBuilder Add(double value)
 {
     _builder.Add(LdValue.Of(value));
     return(this);
 }
Ejemplo n.º 13
0
 public IUserBuilderCanMakeAttributePrivate Custom(string name, float value)
 {
     return(Custom(name, LdValue.Of(value)));
 }