Пример #1
0
        private CopyItem GetCopyItem(TemplateEmail email, Guid?affiliateId, TemplateContentItem templateContentItem, IDictionary <Guid, CopyItemEngine> copyItemEngines)
        {
            // Check the collection first.

            CopyItemEngine copyItemEngine;

            if (!copyItemEngines.TryGetValue(affiliateId ?? Guid.Empty, out copyItemEngine))
            {
                // Get a new one.

                templateContentItem.VerticalId = affiliateId;
                copyItemEngine = _templateEngine.GetCopyItemEngine(templateContentItem);
                copyItemEngines[affiliateId ?? Guid.Empty] = copyItemEngine;
            }

            // Query the template engine for the copy.

            var context = new TemplateContext {
                Id = email.Id, UserId = email.To.Id
            };
            var item = _templateEngine.GetCopyItem(copyItemEngine, context, email.Properties, null);

            if (item == null)
            {
                throw new ApplicationException("Failed to find a copy item for '" + email.Definition + "'.");
            }
            return(item);
        }
Пример #2
0
        Communication IEmailsCommand.GeneratePreview(TemplateEmail email, TemplateContentItem templateContentItem)
        {
            var copyItemEngine = _templateEngine.GetCopyItemEngine(templateContentItem);
            var context        = new TemplateContext {
                Id = email.Id
            };
            var copyItem = _templateEngine.GetCopyItem(copyItemEngine, context, email.Properties, null);

            return(email.CreateCommunication(copyItem));
        }
Пример #3
0
        private int TrySend(IEnumerable <TemplateEmail> emails, TemplateContentItem templateContentItem, bool ignorechecks, DateTime?notIfLastSentLaterThanThis)
        {
            const string method = "Send";

            // Keep track of engines.

            var totalSent       = 0;
            var definitions     = new Dictionary <string, Definition>();
            var categories      = new Dictionary <Guid, Category>();
            var copyItemEngines = new Dictionary <Guid, CopyItemEngine>();

            foreach (var email in emails)
            {
                try
                {
                    var affiliateId = _affiliateEmailsQuery.GetAffiliateId(email);
                    SetContacts(email, affiliateId);

                    // Get the definition for this communication.

                    var definition = GetDefinition(email.Definition, definitions);
                    var category   = GetCategory(email.Category, definition, categories);

                    // If the user who is being sent the communication is not enabled then they should not get it.

                    if (_userEmailsQuery.ShouldSend(email.To, definition, category, email.RequiresActivation, ignorechecks, notIfLastSentLaterThanThis))
                    {
                        // To include the unsubscribe piece there must be a category and a user.

                        email.Properties.Add("Category", category == null ? string.Empty : category.Name);
                        email.Properties.Add("IncludeUnsubscribe", category != null && email.To.Id != Guid.Empty);

                        // Get the copy for the various parts of the communication.

                        var copyItem = templateContentItem == null
                            ? GetCopyItem(email, definition.Name, category == null?null : category.Name, affiliateId)
                            : GetCopyItem(email, affiliateId, templateContentItem, copyItemEngines);

                        // Send it.

                        Send(email.CreateCommunication(copyItem), definition);
                        ++totalSent;
                    }
                }
                catch (Exception ex)
                {
                    EventSource.Raise(Event.Error, method, "Cannot send a communication.", ex, null, Event.Arg("Id", email.To.Id), Event.Arg("EmailType", email.GetType().FullName));
                }
            }

            return(totalSent);
        }
Пример #4
0
        protected override ITextTemplateEngine CreateTextTemplateEngine(Guid?verticalId, TemplateContentItem contentItem)
        {
            if (_settings == null)
            {
                _settings = CreateSettings(verticalId);
            }
            var settings = CreateSettings(_settings);

            return(new WebSiteTextTemplateEngine(verticalId, MediaTypeNames.Text.Plain, contentItem.Subject, settings, WebSite.LinkMe, _webSiteQuery, _tinyUrlCommand));
        }
Пример #5
0
 CopyItemEngine ITemplateEngine.GetCopyItemEngine(TemplateContentItem templateContentItem)
 {
     throw new NotSupportedException();
 }
Пример #6
0
 int IEmailsCommand.TrySend(IEnumerable <TemplateEmail> emails, TemplateContentItem templateContentItem, DateTime?notIfLastSentLaterThanThis)
 {
     return(TrySend(emails, templateContentItem, false, notIfLastSentLaterThanThis));
 }
Пример #7
0
 int IEmailsCommand.TrySend(IEnumerable <TemplateEmail> emails, TemplateContentItem templateContentItem, bool ignoreChecks)
 {
     return(TrySend(emails, templateContentItem, ignoreChecks, null));
 }