/// <summary> /// Expands a set of scoped custom variable slots into a final array containing the custom variables and their scope. /// </summary> /// <param name="scopedCustomVariableSlots">Set of scoped custom variable slots to expand.</param> /// <returns>An array of custom variables with their scope indexed by slot.</returns> internal static ScopedCustomVariable[] GetFinalCustomVariables(params ScopedCustomVariableSlots[] scopedCustomVariableSlots) { var allSlots = scopedCustomVariableSlots.SelectMany(s => s.AllSlots).ToList(); var highestSlotIndex = allSlots.Any() ? allSlots.Max(s => s.Key) : 0; var finalCustomVariables = new ScopedCustomVariable[highestSlotIndex + 1]; foreach (var scopedSlots in scopedCustomVariableSlots.OrderByDescending(s => s.Scope)) foreach (var slot in scopedSlots.AllSlots) finalCustomVariables[slot.Key] = new ScopedCustomVariable(scopedSlots.Scope, slot.Value); return finalCustomVariables; }
/// <summary> /// Get parameters for a given set of custom variables. /// </summary> /// <param name="customVariables">Custom variables to obtain parameters from.</param> /// <returns>Enumerable of key/value pairs containing parameters for these custom variables.</returns> private static IEnumerable<KeyValuePair<string, string>> GetParameters(ScopedCustomVariable[] customVariables) { yield return KeyValuePair.Create("utme", EncodeCustomVariables(customVariables)); }
/// <summary> /// Encode custom variables into a single parameter string. /// </summary> /// <param name="customVariables">Custom variables to encode.</param> /// <returns>Encoded custom variables.</returns> internal static string EncodeCustomVariables(ScopedCustomVariable[] customVariables) { return UtmeEncoder.Encode("8", customVariables.Select(c => c == null ? null : c.Variable.Name).ToArray()) + UtmeEncoder.Encode("9", customVariables.Select(c => c == null ? null : c.Variable.Value).ToArray()) + UtmeEncoder.Encode("11", customVariables.Select(c => c == null ? null : GetScopeIdentity(c.Scope)).ToArray()); }