internal bool MatchesUser(User user) { var userValue = user.GetValueForEvaluation(Attribute); if (userValue == null) { return(false); } if (userValue is JArray) { var array = userValue as JArray; foreach (var element in array) { if (!(element is JValue)) { Logger.LogError("Invalid custom attribute value in user object: " + element); return(false); } if (MatchAny(element as JValue)) { return(MaybeNegate(true)); } } return(MaybeNegate(false)); } else if (userValue is JValue) { return(MaybeNegate(MatchAny(userValue as JValue))); } Logger.LogWarning("Got unexpected user attribute type: " + userValue.Type + " for user key: " + user.Key + " and attribute: " + Attribute); return(false); }
internal static float BucketUser(User user, string featureKey, string attr, string salt) { var idHash = BucketableStringValue(user.GetValueForEvaluation(attr)); if (idHash != null) { if (!string.IsNullOrEmpty(user.SecondaryKey)) { idHash += "." + user.SecondaryKey; } var hash = Hash(String.Format("{0}.{1}.{2}", featureKey, salt, idHash)).Substring(0, 15); var longValue = long.Parse(hash, NumberStyles.HexNumber); return(longValue / longScale); } return(0F); }
private float BucketUser(User user, string featureKey, string attr, string salt) { var userValue = user.GetValueForEvaluation(attr); if (userValue != null && userValue.Type.Equals(JTokenType.String)) { var idHash = userValue.Value <string>(); if (!string.IsNullOrEmpty(user.SecondaryKey)) { idHash += "." + user.SecondaryKey; } var hash = Hash(String.Format("{0}.{1}.{2}", featureKey, salt, idHash)).Substring(0, 15); var longValue = long.Parse(hash, NumberStyles.HexNumber); return(longValue / longScale); } return(0F); }
internal bool MatchesUserNoSegments(User user) { var userValue = user.GetValueForEvaluation(Attribute); if (userValue == null) { return(false); } if (userValue is JArray) { var array = userValue as JArray; foreach (var element in array) { if (!(element is JValue)) { Log.ErrorFormat("Invalid custom attribute value in user object: {0}", element); return(false); } if (MatchAny(element as JValue)) { return(MaybeNegate(true)); } } return(MaybeNegate(false)); } else if (userValue is JValue) { return(MaybeNegate(MatchAny(userValue as JValue))); } Log.WarnFormat("Got unexpected user attribute type: {0} for user key: {1} and attribute: {2}", userValue.Type, user.Key, Attribute); return(false); }