public override void Execute(System.Data.Common.DbTransaction tran, string WorkflowCode, string FromWorkflowStepCode, string ToWorkflowStepCode, string EntityID, string Comment, string UserName) { SmsService smsDB = new SmsService(); Workflow workflow = Workflow.GetWorkflowByCode(WorkflowCode); //select template Template contentTemplate = GetTemplate(tran, WorkflowCode, FromWorkflowStepCode, ToWorkflowStepCode, EntityID, Comment, UserName); DateMode dateMode = Configuration.GetInstance().App.DateMode; if (contentTemplate != null) { List <PhoneNumber> numbers = GetPhoneNumbers(tran, WorkflowCode, FromWorkflowStepCode, ToWorkflowStepCode, EntityID, Comment, UserName); Hashtable contentItems = GetContentItems(tran, contentTemplate, WorkflowCode, FromWorkflowStepCode, ToWorkflowStepCode, EntityID, Comment, UserName); //individual emails for each tos foreach (PhoneNumber phoneNo in numbers) { string messageText = GetMessageText(phoneNo, contentTemplate, contentItems); //create as many messages as needed in 160 chunks while (messageText.Length > 0) { string messagePart; if (messageText.Length > 160) { messagePart = messageText.Substring(0, 160); messageText = messageText.Substring(160); } else { messagePart = messageText; messageText = String.Empty; } string MessageID = smsDB.InsertMessage(dateMode, phoneNo.Phone, messagePart, contentTemplate.Name, workflow.EntityName, EntityID, null, null, null, UserName); } } } else { throw new ApplicationException("No SMS Template found"); } }
public override void Execute(System.Data.Common.DbTransaction tran, string workflowCode, string fromWorkflowStepCode, string toWorkflowStepCode, string entityID, string comment, string userName) { EmailAddress address = null; Workflow workflow = Workflow.GetWorkflowByCode(workflowCode); //select template Template contentTemplate = GetTemplate(tran, workflowCode, fromWorkflowStepCode, toWorkflowStepCode, entityID, comment, userName); DateMode dateMode = Configuration.GetInstance().App.DateMode; if (contentTemplate != null) { DataTable subjects = GetSubjects(tran, workflowCode, fromWorkflowStepCode, toWorkflowStepCode, entityID, comment, userName); DataTable from = GetAddresses(tran, "from", workflowCode, fromWorkflowStepCode, toWorkflowStepCode, entityID, comment, userName); DataTable cc = GetAddresses(tran, "cc", workflowCode, fromWorkflowStepCode, toWorkflowStepCode, entityID, comment, userName); DataTable bcc = GetAddresses(tran, "bcc", workflowCode, fromWorkflowStepCode, toWorkflowStepCode, entityID, comment, userName); DataTable to = GetAddresses(tran, "to", workflowCode, fromWorkflowStepCode, toWorkflowStepCode, entityID, comment, userName); DataTable replyto = GetAddresses(tran, "to", workflowCode, fromWorkflowStepCode, toWorkflowStepCode, entityID, comment, userName); DataTable attachments = GetAttachments(tran, workflowCode, fromWorkflowStepCode, toWorkflowStepCode, entityID, comment, userName); DataTable mailitems = GetMailItems(to); Hashtable contentItems = GetContentItems(tran, contentTemplate, workflowCode, fromWorkflowStepCode, toWorkflowStepCode, entityID, comment, userName); IEmailProvider email = null; //individual emails for each tos foreach (DataRow mail in mailitems.Rows) { EmailMessage message = new EmailMessage(); if (email == null) { //set connection message.EmailConnection = this.EmailConnection; email = EmailService.GetInstance().GetProvider(message); } message.Subject = GetSubject(mail, subjects); message.Body = GetBody(mail, contentTemplate, contentItems); message.EntityID = entityID; message.EntityType = workflow.EntityName; message.IsBodyHtml = this.IsBodyHtml; message.Priority = this.Priority; message.Template = contentTemplate.Name; //from DataRow[] fromList = from.Select(String.Format("(TO = '{0}') OR (TO IS NULL)", mail["TO"])); if (fromList.Length > 0) { DataRow a = fromList[0]; address = new EmailAddress(); address.DisplayName = a["DisplayName"].ToString(); address.Address = a["Address"].ToString(); message.From = address; } //to if (this.ToAddressSendMode == EmailAddressSendMode.Individual) { address = new EmailAddress(); address.DisplayName = mail["DisplayName"].ToString(); address.Address = mail["Address"].ToString(); message.To.Add(address); } else { foreach (DataRow a in to.Rows) { address = new EmailAddress(); address.DisplayName = a["DisplayName"].ToString(); address.Address = a["Address"].ToString(); message.To.Add(address); } } //cc foreach (DataRow a in cc.Select(String.Format("(TO = '{0}') OR (TO IS NULL)", mail["TO"]))) { address = new EmailAddress(); address.DisplayName = a["DisplayName"].ToString(); address.Address = a["Address"].ToString(); message.CC.Add(address); } //bcc foreach (DataRow a in bcc.Select(String.Format("(TO = '{0}') OR (TO IS NULL)", mail["TO"]))) { address = new EmailAddress(); address.DisplayName = a["DisplayName"].ToString(); address.Address = a["Address"].ToString(); message.BCC.Add(address); } foreach (DataRow a in replyto.Select(String.Format("(TO = '{0}') OR (TO IS NULL)", mail["TO"]))) { address = new EmailAddress(); address.DisplayName = a["DisplayName"].ToString(); address.Address = a["Address"].ToString(); message.ReplyTo.Add(address); } //attachments foreach (DataRow a in attachments.Select(String.Format("(TO = '{0}') OR (TO IS NULL)", mail["TO"]))) { EmailAttachment attachment = new EmailAttachment(); attachment.DocumentID = a["DocumentID"].ToString(); message.Attachments.Add(attachment); } email.Send(message); } } else { throw new ApplicationException("No Email Template found"); } }