public override IEnumerable <LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) { var body = activityContext.GetState <string>("Body"); var subject = activityContext.GetState <string>("Subject"); var recipients = activityContext.GetState <string>("Recipients"); var replyTo = activityContext.GetState <string>("ReplyTo"); var bcc = activityContext.GetState <string>("Bcc"); var cc = activityContext.GetState <string>("CC"); var parameters = new Dictionary <string, object> { { "Subject", subject }, { "Body", body }, { "Recipients", recipients }, { "ReplyTo", replyTo }, { "Bcc", bcc }, { "CC", cc } }; var queued = activityContext.GetState <bool>("Queued"); if (!queued) { _messageService.Send(SmtpMessageChannel.MessageType, parameters); } else { var priority = activityContext.GetState <int>("Priority"); _jobsQueueService.Enqueue("IMessageService.Send", new { type = SmtpMessageChannel.MessageType, parameters = parameters }, priority); } yield return(T("Done")); }
public ActionResult Enqueue(int id) { ConfigurationPart part; ApiRequest request; var query = _transformalize.GetQuery(); foreach (var rejection in _apiService.Rejections(id, out request, out part)) { return(rejection.ContentResult( query["format"], query["flavor"] )); } request.RequestType = ApiRequestType.Enqueue; var args = string.Concat(part.Id, ",", query["mode"]); var parameters = new Dictionary <string, object> { { "args", args } }; _jobQueueService.Enqueue("ITransformalizeJobService.Run", parameters, _jobPriority--); return(new ApiResponse(request, part.Configuration).ContentResult( query["format"], query["flavor"] )); }
private bool SendEmail(dynamic contentModel, int templateId, IEnumerable <string> sendTo, IEnumerable <string> cc, IEnumerable <string> bcc, bool NotifyReadEmail, string fromEmail = null, string replyTo = null, IEnumerable <string> attachments = null, bool queued = false, int priority = 0) { var template = _templateServices.GetTemplate(templateId); var body = _templateServices.RitornaParsingTemplate(contentModel, template.Id); if (body.StartsWith("Error On Template")) { _notifier.Add(NotifyType.Error, T("Error on template, mail not sent")); return(false); } var data = new Dictionary <string, object>(); var smtp = _orchardServices.WorkContext.CurrentSite.As <SmtpSettingsPart>(); var recipient = sendTo != null ? sendTo : new List <string> { smtp.Address }; data.Add("Subject", template.Subject); data.Add("Body", body); data.Add("Recipients", String.Join(",", recipient)); if (cc != null) { data.Add("CC", String.Join(",", cc)); } if (bcc != null) { data.Add("Bcc", String.Join(",", bcc)); } if (fromEmail != null) { data.Add("FromEmail", fromEmail); } if (replyTo != null) { data.Add("ReplyTo", replyTo); } data.Add("NotifyReadEmail", NotifyReadEmail); if (attachments != null) { if (attachments.Count() > 0) { data.Add("Attachments", attachments); } } if (!queued) { _messageService.Send(SmtpMessageChannel.MessageType, data); } else { _jobsQueueService.Enqueue("IMessageService.Send", new { type = SmtpMessageChannel.MessageType, parameters = data }, priority); } return(true); }
/// <summary> /// Creates new indexing tasks to update the index document for these content items /// </summary> private void CreateIndexingTasks() { if (!_tasksCreated) { // Creating tasks with Jobs is needed because editing content type settings for a type with many items causes OutOfMemoryException, see issue: https://github.com/OrchardCMS/Orchard/issues/4729 _jobsQueueService.Enqueue("ICreateUpdateIndexTaskService.CreateNextIndexingTaskBatch", new Dictionary <string, object> { { "contentTypeName", _contentTypeName }, { "currentBatchIndex", "0" } }, CreateUpdateIndexTaskService.JobPriority); _tasksCreated = true; } }
public void CreateNextIndexingTaskBatch(string contentTypeName, string currentBatchIndex) { var contentItems = _contentManager.Query(contentTypeName).Slice(int.Parse(currentBatchIndex), BatchSize).ToList(); foreach (var contentItem in contentItems) { _indexingTaskManager.CreateUpdateIndexTask(contentItem); } if (contentItems.Count == BatchSize) { _jobsQueueService.Enqueue("ICreateUpdateIndexTaskService.CreateNextIndexingTaskBatch", new Dictionary <string, object> { { "contentTypeName", contentTypeName }, { "currentBatchIndex", (int.Parse(currentBatchIndex) + BatchSize).ToString() } }, JobPriority); } }
public override IEnumerable <LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) { var body = activityContext.GetState <string>("Body"); var subject = activityContext.GetState <string>("Subject"); var recipients = activityContext.GetState <string>("Recipients"); var replyTo = activityContext.GetState <string>("ReplyTo"); var bcc = activityContext.GetState <string>("Bcc"); var cc = activityContext.GetState <string>("CC"); var notifyReadEmail = activityContext.GetState <bool>("NotifyReadEmail"); var parameters = new Dictionary <string, object> { { "Subject", subject }, { "Body", body }, { "Recipients", recipients }, { "ReplyTo", replyTo }, { "Bcc", bcc }, { "CC", cc }, { "NotifyReadEmail", notifyReadEmail } }; if (string.IsNullOrWhiteSpace(recipients)) { Logger.Error("Email message doesn't have any recipient for Workflow {0}", workflowContext.Record.WorkflowDefinitionRecord.Name); yield return(T("Failed")); } else { var queued = activityContext.GetState <bool>("Queued"); if (!queued) { _messageService.Send(SmtpMessageChannel.MessageType, parameters); } else { var priority = activityContext.GetState <int>("Priority"); _jobsQueueService.Enqueue("IMessageService.Send", new { type = SmtpMessageChannel.MessageType, parameters = parameters }, priority); } yield return(T("Done")); } }
public bool SendTemplatedEmail(dynamic contentModel, int templateId, IEnumerable <string> sendTo, IEnumerable <string> bcc, Dictionary <string, object> viewBag = null, bool queued = true, List <TemplatePlaceHolderViewModel> listaPH = null) { var template = GetTemplate(templateId); string body = RitornaParsingTemplate(contentModel, templateId, viewBag); if (body.StartsWith("Error On Template")) { _notifier.Add(NotifyType.Error, T("Error on template, mail not sent")); return(false); } // Place Holder - es. [UNSUBSCRIBE] if (listaPH != null) { foreach (TemplatePlaceHolderViewModel ph in listaPH) { if (body.Contains(ph.Name)) { body = body.Replace(ph.Name, ph.Value); } else { if (ph.ShowForce) { body += "<br /><br />" + ph.Value; } } } } var data = new Dictionary <string, object>(); var smtp = _services.WorkContext.CurrentSite.As <SmtpSettingsPart>(); var recipient = sendTo != null ? sendTo : new List <string> { smtp.Address }; data.Add("Subject", template.Subject); data.Add("Body", body); data.Add("Recipients", String.Join(",", recipient)); if (bcc != null) { data.Add("Bcc", String.Join(",", bcc)); } //var watch = Stopwatch.StartNew(); //int msgsent = 0; //for(int i=0;i<20;i++) { // msgsent++; // data["Subject"] = msgsent.ToString(); // data["Bcc"] = "*****@*****.**"; // _messageService.Send(SmtpMessageChannel.MessageType, data); //} //watch.Stop(); //_notifier.Add(NotifyType.Information, T("Sent " + msgsent.ToString()+" email in Milliseconds:" + watch.ElapsedMilliseconds.ToString())); if (!queued) { _messageService.Send(SmtpMessageChannel.MessageType, data); } else { var priority = 0;//normal 50 to hight -50 to low _jobsQueueService.Enqueue("IMessageService.Send", new { type = SmtpMessageChannel.MessageType, parameters = data }, priority); } return(true); }