public CommunicationsFiller(ICreativeSettingsFinder finder, ICollection <ReusableValue> reusableValues) { Requires.NonNull(finder, nameof(finder)); Finder = finder; ReusableValueByKey = (reusableValues ?? ReusableValue.None).ToDictionaryOnConflictKeepLast(z => z.Key, z => z); }
public static void Fill( this MimeMessage message, ICreativeSettingsFinder finder, ICollection <ReusableValue> reusableValues, Creative creative, CommunicationTypes ct, ApplicationUser u, Contact c, object model) { Requires.NonNull(message, nameof(message)); Requires.NonNull(creative, nameof(creative)); var filler = new CommunicationsFiller(finder, reusableValues); if (c != null) { message.ContactId(c.ContactId); } else if (u != null) { message.ContactId(u.ContactId); } var context = new Dictionary <string, object> { { "User", u }, { "Contact", c }, { "Model", model } }; var compiledContext = new CommunicationsFiller.CompiledContext(context); var indexerByName = new Dictionary <string, IDictionary <string, string> >(); MimeEntity textPart = null; MimeEntity htmlPart = null; switch (ct) { case CommunicationTypes.Email: message.Subject = filler.Evaluate(creative, z => z.EmailSubject, compiledContext); textPart = new TextPart(TextFormat.Text) { Text = filler.Evaluate(creative, z => z.EmailTextBody, compiledContext) }; htmlPart = new TextPart(TextFormat.Html) { Text = filler.Evaluate(creative, z => z.EmailHtmlBody, compiledContext) }; break; case CommunicationTypes.Sms: textPart = new TextPart(TextFormat.Text) { Text = filler.Evaluate(creative, z => z.TextMessageBody, compiledContext) }; break; default: throw new UnexpectedSwitchValueException(ct); } if (textPart == null || htmlPart == null) { message.Body = textPart ?? htmlPart; } else { message.Body = new MultipartAlternative(textPart, htmlPart); } }
public SystemCommunicationCommunicationBlastFinder(TraffkTenantModelDbContext rdb, ICreativeSettingsFinder creativeSettingsFinder) { Requires.NonNull(rdb, nameof(rdb)); Rdb = rdb; CreativeSettingsFinder = creativeSettingsFinder; }