コード例 #1
0
        /// <summary>
        /// Sends test bulk email message with dynamic content. Sends all replicas if
        /// <see cref="SendTestMessageData.ReplicaMasks"/> property of the parameter <paramref name="data"/>
        /// is null or empty, or chosen replicas in another case.
        /// </summary>
        /// <param name="data">Data required for test message sending.</param>
        /// <returns>Results of successful sending for each replica.</returns>
        public SendTestMessageResult Send(SendTestMessageData data)
        {
            var bulkEmailId = data.BulkEmailId;
            var bulkEmail   = GetBulkEmailFromDB(bulkEmailId);

            RegisterSenderDomain(bulkEmail.SenderEmail);
            var messageData         = CreateSendMessageData(bulkEmail);
            var templateReadOptions = new DCRepositoryReadOptions <DCTemplateModel, DCReplicaModel> {
                TemplateReadOptions = DCTemplateReadOption.None
            };
            var dcTemplateModel = GetDcTemplateModel(bulkEmail.Id, templateReadOptions);
            var replicasToSend  = GetReplicasByMasks(dcTemplateModel, data.ReplicaMasks).ToArray();

            return(ExecuteDCTestMessageSending(data, bulkEmail, messageData, replicasToSend));
        }
コード例 #2
0
        private SendTestMessageResult ExecuteDCTestMessageSending(SendTestMessageData data, BulkEmail bulkEmail,
                                                                  SendMessageData messageData, IEnumerable <DCReplicaModel> replicas)
        {
            var sentReplicaMasks   = new List <int>();
            var failedReplicaMasks = new List <int>();
            var templates          = TemplateFactory.CreateInstances(_userConnection, bulkEmail, replicas, BulkEmailMacroParser);
            var templatesWithMasks = templates.Select(t => new {
                Template    = t,
                ReplicaMask = replicas.First(replica => replica.Id == ((IMailingTemplateReplica)t).ReplicaId).Mask
            });
            var macroComposer = GetMacroComposer(data.ContactId, bulkEmail.Id);

            foreach (var template in templatesWithMasks)
            {
                var sentSuccessfully = SendTestMessageTemplate(bulkEmail.Id, data.ContactId, data.EmailRecipients,
                                                               template.Template, messageData, macroComposer);
                if (sentSuccessfully)
                {
                    sentReplicaMasks.Add(template.ReplicaMask);
                }
                else
                {
                    failedReplicaMasks.Add(template.ReplicaMask);
                }
            }
            if (data.ReplicaMasks == null)
            {
                return(new SendTestMessageResult {
                    Success = sentReplicaMasks.Count > 0,
                    SentReplicaMasks = sentReplicaMasks.ToArray(),
                    FailedReplicaMasks = failedReplicaMasks.ToArray()
                });
            }
            foreach (var mask in data.ReplicaMasks)
            {
                if (!sentReplicaMasks.Contains(mask) && !failedReplicaMasks.Contains(mask))
                {
                    failedReplicaMasks.Add(mask);
                }
            }
            return(new SendTestMessageResult {
                Success = sentReplicaMasks.Count > 0,
                SentReplicaMasks = sentReplicaMasks.ToArray(),
                FailedReplicaMasks = failedReplicaMasks.ToArray()
            });
        }
コード例 #3
0
        public SendTestMessageResponse SendDCTestMessage(SendTestMessageRequest data)
        {
            SendTestMessageResponse response;

            if (_mailingProvider is ITestMessageProvider testMessageProvider)
            {
                SendTestMessageData   sendTestMessageData = CreateSendTestMessageData(data);
                SendTestMessageResult result = testMessageProvider.SendDCTestMessage(sendTestMessageData);
                int sentReplicasCount        = result.SentReplicaMasks?.Length ?? 0;
                int failedReplicasCount      = result.FailedReplicaMasks?.Length ?? 0;
                response = CreateSendTestMessageResponse(result.Success, sentReplicasCount + failedReplicasCount,
                                                         sentReplicasCount);
            }
            else
            {
                bool   result  = SendTestMessage(data.BulkEmailId, data.ContactId, data.EmailRecipients);
                string message = result
                                        ? new LocalizableString(UserConnection.Workspace.ResourceStorage,
                                                                "MailingService", "LocalizableStrings.TestMessageProviderErrorMessage.Value")
                                        : null;
                response = CreateSendTestMessageResponse(result, 0, 0, message);
            }
            return(response);
        }