Created
December 19, 2017 16:22
-
-
Save enkelmedia/47936872d00c98c2f06afbe1197c80d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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