Skip to content

Instantly share code, notes, and snippets.

@dnstommy
Last active May 6, 2018 15:33
Show Gist options
  • Save dnstommy/23bd860af5c2a85e2e9cec1bfe5f2443 to your computer and use it in GitHub Desktop.
Save dnstommy/23bd860af5c2a85e2e9cec1bfe5f2443 to your computer and use it in GitHub Desktop.
/// <summary>Defines the run class.</summary>
/// <typeparam name="T">The rule context.</typeparam>
public class ApplyProfileValue<T> : RuleAction<T> where T : RuleContext
{
/// <summary>Gets or sets the script id.</summary>
/// <value>The script id.</value>
public string Profilecardkey { get; set; }
/// <summary>Executes the specified rule context.</summary>
/// <param name="ruleContext">The rule context.</param>
public override void Apply(T ruleContext)
{
Assert.ArgumentNotNull((object)ruleContext, "ruleContext");
var ruleItem = ruleContext.Item;
var profile = ruleItem?.Database.GetItem(this.Profilecardkey);
if (profile == null)
return;
ProcessProfile(profile);
}
private static void ProcessProfile(BaseItem profileItem)
{
var isActive = Tracker.Current != null && Tracker.Current.IsActive;
if (!isActive) return;
var trackingFields = new List<TrackingField>
{
new TrackingField(profileItem.Fields[Templates.ProfileCard.Fields.ProfileCardValue])
};
var fields = (IEnumerable<TrackingField>)trackingFields;
var interaction = Tracker.Current?.Session?.Interaction;
if (interaction == null) return;
TrackingFieldProcessor.ProcessProfiles(interaction, fields.FirstOrDefault());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment