从Action调用中获取命令

时间:2016-05-03 22:01:14

标签: sitecore sitecore7

作为Sitecore工作流程的一部分,如何获取执行操作的命令名称?例如,

我有3种状态:接受,草稿,审核以及草稿和审核都有自定义电子邮件操作,应根据执行的命令查看不同的字典项目(在起草状态下保存或提交以及批准或拒绝审查状态)。我想使用当前的工作流状态和命令来确定要拉出哪个字典项,我该怎么做?这是我正在使用的功能。

 public void Process(WorkflowPipelineArgs args)
    {
        Assert.ArgumentNotNull(args, "args");

        var processorItem = args.ProcessorItem;

        if (processorItem == null)
        {
            return;
        }

        var currentItem = args.DataItem;

        var innerItem = processorItem.InnerItem;

        var fullPath = innerItem.Paths.FullPath;

        var recipient = currentItem.Fields["Primary Email"].Value;

        var candidateName = currentItem.Fields["Candidate Name"].Value;
        var formName = currentItem.Name;

        if (string.IsNullOrEmpty(recipient)) return;

        var from = GetText(innerItem, "from", args);
        var mailServer = GetText(innerItem, "mail server", args);

        var currentWorkflowState = currentItem.Fields[FieldIDs.WorkflowState].Value;

        var subject = string.Format(Translate.Text("cb-candidate-submission-subject"), formName);
        var message = string.Format(Translate.Text("cb-candidate-submission-body"), candidateName, formName);

        Error.Assert(@from.Length > 0, "The 'From' 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(mailServer.Length > 0,
            "The 'Mail server' field is not specified in the mail action item: " + fullPath);

        var mailMessage = new MailMessage();

        mailMessage.To.Add(recipient);
        mailMessage.From = new MailAddress(@from);
        mailMessage.Subject = subject;
        mailMessage.Body = message;

        var client = new SmtpClient(mailServer) { EnableSsl = false };

        try
        {
            client.Send(mailMessage);
        }
        catch (Exception ex)
        {
            Log.Error("EmailExAction Threw An Exception", ex, this);
        }
    }

2 个答案:

答案 0 :(得分:0)

WorkflowPipeleneArgs 具有公共属性: ID NextStateId WorkflowState PreviousState Item CommandItem 。您可以使用它们来定义项目状态。

答案 1 :(得分:0)

WorkflowPipelineArgs具有CommandItem,此项目具有当前状态和当前命令详细信息。

var currentCommandName = arg.CommandItem.Name;