Skip to content

Instantly share code, notes, and snippets.

@enkelmedia
Created December 19, 2017 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enkelmedia/47936872d00c98c2f06afbe1197c80d5 to your computer and use it in GitHub Desktop.
Save enkelmedia/47936872d00c98c2f06afbe1197c80d5 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Compilation;
//using NewsletterStudio.Model;
using NewsletterStudio.Bll;
using NewsletterStudio.Core.Model;
namespace NewsletterStudio.Services.RenderTasks.Tasks
{
public class InsertCustomDataRenderTask : RenderTask
{
private EmailTrackingItem _trackingItem;
public override void ProcessPreRender(RenderResult renderResult, RenderTaskParameters parameters)
{
}
public override void ProcessUniqueItem(RenderResult renderResult, RenderTaskUniqueItemParameters parameters)
{
// If no custom data is includded, lets just ignore this.
if (!ConfigManager.NewsletterStudio.ActivateCustomDataCollection)
return;
_trackingItem = parameters.EmailTrackingItem;
Regex regex = new Regex(@"\[#([^]]*)\]");
renderResult.MessageBody = regex.Replace(renderResult.MessageBody, GetCustomData);
}
private string GetCustomData(Match match)
{
string collectionKey = match.Groups[1].Value;
if (_trackingItem.Data.ContainsKey(collectionKey))
return _trackingItem.Data[collectionKey].ToString();
return string.Empty;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment