Esempio n. 1
0
        // Access workflow process to get info
        public void Process(WorkflowPipelineArgs args)
        {
            ProcessorItem processorItem = args.ProcessorItem;

            // If item is not in processor and item doesn't have page layout, retrun
            if (processorItem == null)
            {
                return;
            }

            Item innerItem = processorItem.InnerItem;

            // Check the condition before excuting
            Assert.ArgumentNotNull((object)args, "args");

            string fullPath    = innerItem.Paths.FullPath;
            string fromAddress = "*****@*****.**";
            string toAddress   = User.Current.Profile.Email;

            if (String.IsNullOrEmpty(toAddress))
            {
                return;
            }

            string subject = this.GetText(innerItem, "subject", args);
            string message = this.GetText(innerItem, "message", args);

            Error.Assert(toAddress.Length > 0, "The 'To' field is not specified in the mail action item: " + fullPath);
            Error.Assert(subject.Length > 0, "The 'Subject' field is not specified in the mail action item: " + fullPath);
            Error.Assert(message.Length > 0, "The 'Message' field is not specified in the mail action item: " + fullPath);

            try
            {
                if (!String.IsNullOrEmpty(toAddress.Trim()) && !String.IsNullOrEmpty(fromAddress.Trim()))
                {
                    // Send email if no issue found
                    if (Util.sendEmail(toAddress, subject, message, fromAddress, "", "", true))
                    {
                        Sitecore.Diagnostics.Log.Info("Begin Blog info", this);
                        Sitecore.Diagnostics.Log.Info("fromAddress " + fromAddress, this);
                        Sitecore.Diagnostics.Log.Info("toAddress " + toAddress, this);
                        Sitecore.Diagnostics.Log.Info("subject " + subject, this);
                        Sitecore.Diagnostics.Log.Info("message " + message, this);
                        Sitecore.Diagnostics.Log.Info("End info", this);
                        Sitecore.Diagnostics.Log.Info("Email Successfully Sent!!", this);
                    }
                    else
                    {
                        SheerResponse.ShowError("Sending Email Failed. Please try to approve again", "");
                        args.AbortPipeline();
                    }
                }
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error("Sending Email Failed - Exception Error", ex, this);
            }
        }
Esempio n. 2
0
        public virtual void Process(WorkflowPipelineArgs args)
        {
            ScribanMailActionItem actionItem = args.ProcessorItem.InnerItem;
            var mailTo = actionItem.To;

            if (string.IsNullOrWhiteSpace(mailTo))
            {
                Log.Error(GetType().FullName + " cannot be invoked with an empty 'To' field.", this);
                return;
            }

            var mailFrom = actionItem.From;

            if (string.IsNullOrWhiteSpace(mailFrom))
            {
                Log.Error(GetType().FullName + " cannot be invoked with an empty 'From' field.", this);
                return;
            }

            var mailSubject = actionItem.Subject;
            var mailBody    = actionItem.Message;

            var model = CreateModel(args);

            try
            {
                mailTo      = ProcessScribanTemplate(mailTo, model);
                mailFrom    = ProcessScribanTemplate(mailFrom, model);
                mailSubject = ProcessScribanTemplate(mailSubject, model);
                mailBody    = ProcessScribanTemplate(mailBody, model);
            }
            catch (Exception ex)
            {
                Log.Error("An error occurred whilst rendering a Scriban template in " + GetType().FullName, ex, this);
                return;
            }

            try
            {
                var message = new MailMessage(mailFrom, mailTo, mailSubject, mailBody);
                message.IsBodyHtml = true;

                using (var smtpClient = SmtpClientFactory.Invoke())
                {
                    smtpClient.Send(message);
                }
            }
            catch (Exception ex)
            {
                Log.Error("Exception while sending workflow email", ex, this);
                args.AbortPipeline();
            }
        }
        // Access workflow process to get info
        public void Process(WorkflowPipelineArgs args)
        {
            Item   currentPost    = args.DataItem;
            string titleField     = FieldValidation(currentPost, "Title");
            string thumbnailImage = FieldValidation(currentPost, "ThumbnailImage");
            string description    = FieldValidation(currentPost, "Description");
            string content        = FieldValidation(currentPost, "Content");
            string publishedDate  = FieldValidation(currentPost, "PubDate");

            // Validate required fields
            if (IsFieldAvailable(currentPost, "Title") && String.IsNullOrEmpty(titleField) ||
                IsFieldAvailable(currentPost, "ThumbnailImage") && String.IsNullOrEmpty(thumbnailImage) ||
                IsFieldAvailable(currentPost, "Description") && String.IsNullOrEmpty(description) ||
                IsFieldAvailable(currentPost, "Content") && String.IsNullOrEmpty(content))
            {
                Sitecore.Diagnostics.Log.Audit("Blog WP- One of required fields is empty. Stop submitting the request at " + currentPost.Paths.FullPath, this);
                SheerResponse.Alert("One of required fields is empty");
                args.AbortPipeline();
            }
            else
            {
                Sitecore.Data.Database webDb = Sitecore.Configuration.Factory.GetDatabase("web");

                // if the item has not been published
                if (currentPost != null && webDb.GetItem(currentPost.ID) == null)
                {
                    string sitecoreTime = Sitecore.DateUtil.ToIsoDate(DateTime.Now);

                    // Update publish date
                    using (new Sitecore.SecurityModel.SecurityDisabler())
                    {
                        currentPost.Editing.BeginEdit();
                        currentPost.Fields["__Display name"].Value = currentPost.DisplayName.Replace("_Draft", "");
                        // Update pubDate field for RSS Feed
                        currentPost.Fields["pubDate"].Value = sitecoreTime;
                        // Update __Created date field for Bucket Sync
                        currentPost.Fields["__Created"].Value = sitecoreTime;
                        currentPost.Editing.EndEdit();

                        // Bucket sync
                        BucketManager.Sync(currentPost.Database.GetItem(BlogSettings.ArticleRootPath.ID));
                    }

                    // Refresh the new post for  search index master
                    var    tempItem          = (SitecoreIndexableItem)currentPost;
                    string searchIndexMaster = BlogSettings.SearchIndexName;
                    Sitecore.ContentSearch.ContentSearchManager.GetIndex(searchIndexMaster).Refresh(tempItem);
                    Sitecore.Diagnostics.Log.Audit("Search Indexing: " + searchIndexMaster, this);
                }
            }
        }
        protected void CopyItemToMainSite(WorkflowPipelineArgs eventArgs)
        {
            var currentItem = eventArgs.DataItem;

            if (currentItem.Fields[HiddenFields.Templates.HiddenField.Fields.SourceId].HasValue)
            {
                Context.ClientPage.ClientResponse.Alert("This action can't be process. The content is belong to main site.");
                eventArgs.AbortPipeline();
                return;
            }
            try
            {
                using (new SecurityModel.SecurityDisabler())
                {
                    var copiedItem = this.mallSiteWorkflowRepository.GetCopiedItemInMainSite(currentItem);
                    if (copiedItem == null)
                    {
                        this.mallSiteWorkflowRepository.CopyItemToMainSite(currentItem, Constants.States.WaitingForMainSiteApproval);
                    }
                    else
                    {
                        var state = this.stateRepository.GetStateId(copiedItem);
                        ClientPipelineArgs cpa = new ClientPipelineArgs();
                        cpa.Parameters.Add("currentItemId", currentItem.ID.ToString());
                        cpa.Parameters.Add("copiedItemId", copiedItem.ID.ToString());
                        if (state.Equals(Constants.States.Draft) || state.Equals(Constants.States.WaitingForMainSiteApproval))
                        {
                            cpa.Parameters.Add("msg", "This item is already exists on main site. Do you want to replace?");
                            Context.ClientPage.Start(this, "CopyItemToMainSiteDialog", cpa);
                        }
                        if (state.Equals(Constants.States.Approved))
                        {
                            cpa.Parameters.Add("msg", "The item is approved by the main admin. Do you want to replace and turn back it into 'Waiting for approve'?");
                            Context.ClientPage.Start(this, "CopyItemToMainSiteDialog", cpa);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Context.ClientPage.ClientResponse.Alert(exception.Message);
            }
        }
Esempio n. 5
0
        // Access workflow process to get info
        public void Process(WorkflowPipelineArgs args)
        {
            ProcessorItem processorItem = Helper.ValidateArgsProcessorItem(args);

            if (processorItem == null)
            {
                return;
            }

            Item innerItem             = processorItem.InnerItem;
            UpdateWorkflowState update = new UpdateWorkflowState();

            User userWhoMadeUpdate = User.FromName(args.DataItem.Statistics.UpdatedBy, true);

            // Get "To Addresses" for rejection email
            string toAddress           = "";
            string listOfAuthorsEmails = Helper.GetToAddressesForApproveRejectEmail(User.Current, args.DataItem.Paths.FullPath);

            if (!String.IsNullOrEmpty(listOfAuthorsEmails))
            {
                toAddress = userWhoMadeUpdate.Profile.Email + ";" + listOfAuthorsEmails;
            }
            // no other author emails found, only send to contributor who made original update
            else
            {
                toAddress = userWhoMadeUpdate.Profile.Email;
            }

            string fullPath    = innerItem.Paths.FullPath;
            string fromAddress = User.Current.Profile.Email;
            string subject     = Helper.GetText(innerItem, "subject", args);
            string message     = Helper.GetText(innerItem, "message", args);

            Error.Assert(subject.Length > 0, "The 'Subject' field is not specified in the mail action item: " + fullPath);
            Error.Assert(message.Length > 0, "The 'Message' field is not specified in the mail action item: " + fullPath);

            // Update main page item and its resource folder
            update.ChangeWorkflowState(args.DataItem, "Working", true);

            // Find all controls on item
            foreach (string control in update.GetDatasourceValue(args, args.DataItem))
            {
                if (!String.IsNullOrEmpty(control))
                {
                    Item ctrl = args.DataItem.Database.GetItem(control);
                    if (ctrl != null)
                    {
                        update.ChangeWorkflowState(ctrl, "Working", false);
                    }
                }
            }

            try
            {
                if (!String.IsNullOrEmpty(toAddress.Trim()) && !String.IsNullOrEmpty(fromAddress.Trim()))
                {
                    // Send email if no issue found
                    if (Util.sendEmail(toAddress, subject, message, fromAddress, "", "", true))
                    {
                        if (fromAddress == "*****@*****.**")
                        {
                            fromAddress = "User doesn't have email address";
                        }
                        Sitecore.Diagnostics.Log.Info("Begin info", this);
                        Sitecore.Diagnostics.Log.Info("fromAddress " + fromAddress, this);
                        Sitecore.Diagnostics.Log.Info("toAddress " + toAddress, this);
                        Sitecore.Diagnostics.Log.Info("subject " + subject, this);
                        Sitecore.Diagnostics.Log.Info("message " + message, this);
                        Sitecore.Diagnostics.Log.Info("End info", this);
                        Sitecore.Diagnostics.Log.Info("Email Successfully Sent!!", this);
                    }
                    else
                    {
                        SheerResponse.ShowError("Sending Email Failed. Please try to reject again", "");
                        args.AbortPipeline();
                    }
                }
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error("Sending Email Failed - Exception Error", ex, this);
            }
        }
Esempio n. 6
0
        // Access workflow process to get info
        public void Process(WorkflowPipelineArgs args)
        {
            ProcessorItem processorItem = Helper.ValidateArgsProcessorItem(args);

            if (processorItem == null)
            {
                return;
            }

            Item innerItem             = processorItem.InnerItem;
            UpdateWorkflowState update = new UpdateWorkflowState();

            // Get "To Addresses" for request email
            string toAddress = Helper.GetToAddressesForRequestEmail(User.Current, args.DataItem.Paths.FullPath);

            if (String.IsNullOrEmpty(toAddress))
            {
                toAddress = Helper.GetText(innerItem, "to", args); // no emails found, send to default toAddress specified in workflow action
            }

            string fullPath    = innerItem.Paths.FullPath;
            string fromAddress = User.Current.Profile.Email;
            string subject     = Helper.GetText(innerItem, "subject", args);
            string message     = Helper.GetText(innerItem, "message", args);

            Sitecore.Diagnostics.Log.Info("HealthIS WP- " + fullPath + " - " + fromAddress + " - " + toAddress + " - " + subject, this);

            Error.Assert(toAddress.Length > 0, "The 'To' field is not specified in the mail action item: " + fullPath);
            Error.Assert(subject.Length > 0, "The 'Subject' field is not specified in the mail action item: " + fullPath);
            Error.Assert(message.Length > 0, "The 'Message' field is not specified in the mail action item: " + fullPath);

            // Update main page item and its resource folder
            update.ChangeWorkflowState(args.DataItem, "Awaiting Approval", true);

            // Find all controls on item
            foreach (string control in update.GetDatasourceValue(args, args.DataItem))
            {
                if (!String.IsNullOrEmpty(control))
                {
                    Item ctrl = args.DataItem.Database.GetItem(control);

                    if (ctrl != null)
                    {
                        update.ChangeWorkflowState(ctrl, "Awaiting Approval", false);
                    }
                }
            }

            try
            {
                // Post Slack Message
                PostSlackMessage.PostMessage(args.DataItem, User.Current, false, args.CommentFields["Comments"].ToString());

                if (!String.IsNullOrEmpty(toAddress.Trim()) && !String.IsNullOrEmpty(fromAddress.Trim()))
                {
                    // Send email if no issue found
                    if (Util.sendEmail(toAddress, subject, message, fromAddress, "", "", true))
                    {
                        Sitecore.Diagnostics.Log.Info("Begin info", this);
                        Sitecore.Diagnostics.Log.Info("fromAddress " + fromAddress, this);
                        Sitecore.Diagnostics.Log.Info("toAddress " + toAddress, this);
                        Sitecore.Diagnostics.Log.Info("subject " + subject, this);
                        Sitecore.Diagnostics.Log.Info("message " + message, this);
                        Sitecore.Diagnostics.Log.Info("End info", this);
                        Sitecore.Diagnostics.Log.Info("Email Successfully Sent!!", this);
                    }
                    else
                    {
                        SheerResponse.ShowError("Sending Email Failed. Please try to save and submit again", "");
                        args.AbortPipeline();
                    }
                }
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error("Sending Email Failed - Exception Error", ex, this);
            }
        }