我无法在我的工作流程的代码活动中获取工作流实例。我能得到它吗?我确实检查了WorkflowEventArgs.WorkflowInstance Property,但在我的代码活动中,我没有 WorkflowEventArgs 。相反,我有 EventArgs 。
我要做的是:
基本上,我需要访问Workflow队列数据以获取队列中的值。在上面的url中,代码是相同的但是,它不在代码活动中?访问队列的正确方法是什么?
答案 0 :(得分:2)
来自Getting Your Workflow Instance:
public sealed class LogState : CodeActivity
{
protected override void Execute(CodeActivityContext context)
{
Guid instanceId = context.WorkflowInstanceId;
var connection = ConfigurationManager.ConnectionStrings["ConnectionString"];
WorkflowInstanceProxy proxy = context.GetExtension<WorkflowInstanceInfo>().GetProxy();
//...
}
protected override void CacheMetadata(CodeActivityMetadata metadata)
{
base.CacheMetadata(metadata);
metadata.AddDefaultExtensionProvider<WorkflowInstanceInfo>(() => new WorkflowInstanceInfo());
}
public class WorkflowInstanceInfo : IWorkflowInstanceExtension
{
WorkflowInstanceProxy proxy;
public IEnumerable<object> GetAdditionalExtensions()
{
yield break;
}
public void SetInstance(WorkflowInstanceProxy instance)
{
this.proxy = instance;
}
public WorkflowInstanceProxy GetProxy() { return proxy; }
}
答案 1 :(得分:1)
我对你的问题感到有些困惑。这是你想要的吗?
public sealed class GetWorkflowIdActivity : CodeActivity<string>
{
protected override string Execute(CodeActivityContext context)
{
return context.WorkflowInstanceId.ToString();
}
}