Exemple #1
0
        private void SetExpirationDate(BulkEmailRecipientInfo recipientInfo, IDataReader dataReader)
        {
            DateTime messageDate;
            var      bulkEmailCategoryId = _bulkEmail.CategoryId;

            if (bulkEmailCategoryId.Equals(MailingConsts.TriggeredEmailBulkEmailCategoryId))
            {
                var timestampColumnIndex = dataReader.GetOrdinal("Timestamp");
                if (dataReader[timestampColumnIndex] == DBNull.Value)
                {
                    return;
                }
                var timestamp = _userConnection.DBTypeConverter.DBValueToInt(dataReader[timestampColumnIndex]);
                if (timestamp == 0)
                {
                    return;
                }
                messageDate = Utilities.ConvertTimestampToDateTime(timestamp);
                messageDate = DateTime.SpecifyKind(messageDate, DateTimeKind.Utc);
            }
            else
            {
                var timezoneOffset = _userConnection.CurrentUser.TimeZone.GetUtcOffset(_bulkEmail.StartDate);
                if (_bulkEmail.StartDate.Year == DateTime.MinValue.Year)
                {
                    messageDate = DateTime.UtcNow;
                }
                else
                {
                    messageDate = _bulkEmail.StartDate.Add(-timezoneOffset);
                    messageDate = DateTime.SpecifyKind(messageDate, DateTimeKind.Utc);
                }
            }
            recipientInfo.ExpirationDate = messageDate.AddMinutes(_bulkEmailExpirationPeriod);
        }
Exemple #2
0
        private int GetInitialResponseCode(IDataReader reader, BulkEmailRecipientInfo recipientInfo,
                                           int responseCodeColumnIndex)
        {
            var initialResponseCode = reader.GetInt32(responseCodeColumnIndex);

            if (initialResponseCode != (int)MailingResponseCode.PostedProvider)
            {
                return(initialResponseCode);
            }
            if (!MailingUtilities.ValidateEmail(recipientInfo.EmailAddress))
            {
                initialResponseCode = (int)MailingResponseCode.CanceledIncorrectEmail;
            }
            else if (_limitedRecipients.Value.ContainsKey(recipientInfo.ContactId))
            {
                initialResponseCode = _limitedRecipients.Value[recipientInfo.ContactId];
            }
            else if (_duplicatingRecipients.Value.ContainsKey(recipientInfo.Id))
            {
                initialResponseCode = _duplicatingRecipients.Value[recipientInfo.Id];
            }
            else if (recipientInfo.ReplicaId == Guid.Empty)
            {
                initialResponseCode = (int)MailingResponseCode.CanceledTemplateNotFound;
            }
            return(initialResponseCode);
        }
        /// <summary>
        /// Returns personal macros of the contact.
        /// </summary>
        /// <param name="contactId">Unique identifier of Contact.</param>
        /// <param name="emailRecipient">Email address of recipients.</param>
        /// <param name="macrosCollection">Collection of macros.</param>
        /// <returns>The recipient macros.</returns>
        public rcpt_merge_var GetPersonalMergeVars(Guid contactId, string emailRecipient,
                                                   IEnumerable <MacrosInfo> macrosCollection)
        {
            Dictionary <string, string> macrosValues = GetPersonalMacrosValues(contactId, macrosCollection);
            IMessageRecipientInfo       recipient    = new BulkEmailRecipientInfo {
                EmailAddress = emailRecipient,
                ContactId    = contactId
            };

            return(CreateRecipientMergeVars(recipient, macrosValues));
        }
Exemple #4
0
        /// <summary>
        /// Gets the audience of the bulk email to send.
        /// </summary>
        /// <returns>List of <see cref="IMessageRecipientInfo"/>.</returns>
        public List <IMessageRecipientInfo> GetAudience()
        {
            if (PageNumber <= 0)
            {
                PageNumber = 1;
            }
            var recipientsSelect = GetRecipientsBatchSelect();
            var result           = new List <IMessageRecipientInfo>();

            using (var dbExecutor = _userConnection.EnsureDBConnection()) {
                using (var reader = recipientsSelect.ExecuteReader(dbExecutor)) {
                    var emailColumnIndex        = reader.GetOrdinal("EmailAddress");
                    var contactRIdColumnIndex   = reader.GetOrdinal("ContactRId");
                    var contactIdColumnIndex    = reader.GetOrdinal("ContactId");
                    var uidColumnIndex          = reader.GetOrdinal("RecipientUId");
                    var macrosColumnIndex       = reader.GetOrdinal("Macros");
                    var replicaIdColumnIndex    = reader.GetOrdinal("DCReplicaId");
                    var responseCodeColumnIndex = reader.GetOrdinal("InitialResponseCode");
                    while (reader.Read())
                    {
                        var address   = reader.GetString(emailColumnIndex).Trim();
                        var macros    = DeserializeMacrosFromReader(reader, macrosColumnIndex);
                        var replicaId = reader.IsDBNull(replicaIdColumnIndex)
                                                        ? Guid.Empty
                                                        : reader.GetGuid(replicaIdColumnIndex);
                        var recipientInfo = new BulkEmailRecipientInfo {
                            Id           = reader.GetGuid(uidColumnIndex),
                            ContactId    = reader.GetGuid(contactIdColumnIndex),
                            ContactRId   = reader.GetInt32(contactRIdColumnIndex),
                            EmailAddress = address,
                            Macros       = macros,
                            ReplicaId    = replicaId
                        };
                        var initialResponseCode = GetInitialResponseCode(reader, recipientInfo, responseCodeColumnIndex);
                        recipientInfo.InitialResponseCode = initialResponseCode;
                        SetExpirationDate(recipientInfo, reader);
                        result.Add(recipientInfo);
                    }
                }
            }
            if (result.Any())
            {
                LastBatchSize = result.Count;
            }
            return(result);
        }