public bool Evaluate(JToken conditions, UserAttributes userAttributes) { //Cloning is because it is reference type var conditionsArray = conditions.DeepClone() as JArray; if (conditionsArray != null) { switch (conditions[0].ToString()) { case AND_OPERATOR: conditionsArray.RemoveAt(0); return(AndEvaluator(conditionsArray, userAttributes)); case OR_OPERATOR: conditionsArray.RemoveAt(0); return(OrEvaluator(conditionsArray, userAttributes)); case NOT_OPERATOR: conditionsArray.RemoveAt(0); return(NotEvaluator(conditionsArray, userAttributes)); default: return(false); } } string conditionName = conditions["name"].ToString(); return(userAttributes != null && userAttributes.ContainsKey(conditionName) && userAttributes[conditionName] == conditions["value"].ToString()); }
/// <summary> /// Get Bucketing ID from user attributes. /// </summary> /// <param name = "userId" >User Identifier</param> /// <param name = "filteredAttributes" >The user's attributes.</param> /// <returns>User ID if bucketing Id is not provided in user attributes, bucketing Id otherwise.</returns> private string GetBucketingId(string userId, UserAttributes filteredAttributes) { string bucketingId = userId; // If the bucketing ID key is defined in attributes, then use that in place of the userID for the murmur hash key if (filteredAttributes != null && filteredAttributes.ContainsKey(RESERVED_ATTRIBUTE_KEY_BUCKETING_ID)) { bucketingId = filteredAttributes[RESERVED_ATTRIBUTE_KEY_BUCKETING_ID]; Logger.Log(LogLevel.DEBUG, string.Format("Setting the bucketing ID to \"{0}\"", bucketingId)); } return(bucketingId); }
/// <summary> /// Get Bucketing ID from user attributes. /// </summary> /// <param name = "userId" >User Identifier</param> /// <param name = "filteredAttributes" >The user's attributes.</param> /// <returns>Bucketing Id if it is a string type in attributes, user Id otherwise.</returns> private string GetBucketingId(string userId, UserAttributes filteredAttributes) { string bucketingId = userId; // If the bucketing ID key is defined in attributes, then use that in place of the userID for the murmur hash key if (filteredAttributes != null && filteredAttributes.ContainsKey(ControlAttributes.BUCKETING_ID_ATTRIBUTE)) { if (filteredAttributes[ControlAttributes.BUCKETING_ID_ATTRIBUTE] is string) { bucketingId = (string)filteredAttributes[ControlAttributes.BUCKETING_ID_ATTRIBUTE]; Logger.Log(LogLevel.DEBUG, $"BucketingId is valid: \"{bucketingId}\""); } else { Logger.Log(LogLevel.WARN, "BucketingID attribute is not a string. Defaulted to userId"); } } return(bucketingId); }
/// <summary> /// Get Bucketing ID from user attributes. /// </summary> /// <param name = "userId" >User Identifier</param> /// <param name = "filteredAttributes" >The user's attributes.</param> /// <returns>Bucketing Id if it is a string type in attributes, user Id otherwise.</returns> private Result <string> GetBucketingId(string userId, UserAttributes filteredAttributes) { var reasons = new DecisionReasons(); string bucketingId = userId; // If the bucketing ID key is defined in attributes, then use that in place of the userID for the murmur hash key if (filteredAttributes != null && filteredAttributes.ContainsKey(ControlAttributes.BUCKETING_ID_ATTRIBUTE)) { if (filteredAttributes[ControlAttributes.BUCKETING_ID_ATTRIBUTE] is string) { bucketingId = (string)filteredAttributes[ControlAttributes.BUCKETING_ID_ATTRIBUTE]; Logger.Log(LogLevel.DEBUG, $"BucketingId is valid: \"{bucketingId}\""); } else { Logger.Log(LogLevel.WARN, reasons.AddInfo("BucketingID attribute is not a string. Defaulted to userId")); } } return(Result <string> .NewResult(bucketingId, reasons)); }