向工作流设计器公开 NativeActivity 变量
我有一个 NativeActivity
,其中包含一个 Activity
主体。此活动的目的是在子活动期间将资源公开为变量
。我遇到的问题是 Variable
似乎无法在活动之外使用。我将使用 StreamReader
作为示例资源。
ResourceActivity.cs:
[Designer(typeof(ResourceActivityDesigner))]
public sealed class ResourceActivity : NativeActivity
{
[RequiredArgument]
public InArgument<string> Path { get; set; }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public Activity Body { get; set; }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public Variable<StreamReader> Resource { get; set; }
public ResourceActivity()
{
this.Resource = new Variable<StreamReader>
{
Default = null,
Name = "reader"
};
}
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
if (this.Path != null) metadata.AddArgument(this.Path);
if (this.Body != null) metadata.AddChild(this.Body);
if (this.Resource != null) metadata.AddVariable(this.Resource);
}
protected override void Execute(NativeActivityContext context)
{
this.Resource.Set(context, new StreamReader(this.Path.Get(context)));
context.ScheduleActivity(this.Body, new completionCallback(Done), new FaultCallback(Faulted));
}
private void Done(NativeActivityContext context, ActivityInstance instance)
{
var reader = this.Reader.Get(context);
if (reader != null) reader.Dispose();
}
private void Faulted(NativeActivityFaultContext context, Exception ex, ActivityInstance instance)
{
var reader = this.Reader.Get(context);
if (reader != null) reader.Dispose();
}
}
我无法在工作流设计器的变量列表中查看“资源”或“阅读器”。我是否在 CacheMetadata 中遗漏了某些内容?
I've got a NativeActivity
which contains an Activity
body. The purpose of this activity is to expose a resource for the duration of the child activity as a Variable
. The problem I've encountered is it appears the Variable
cannot be used outside the activity. I'll use StreamReader
as an example resource.
ResourceActivity.cs:
[Designer(typeof(ResourceActivityDesigner))]
public sealed class ResourceActivity : NativeActivity
{
[RequiredArgument]
public InArgument<string> Path { get; set; }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public Activity Body { get; set; }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public Variable<StreamReader> Resource { get; set; }
public ResourceActivity()
{
this.Resource = new Variable<StreamReader>
{
Default = null,
Name = "reader"
};
}
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
if (this.Path != null) metadata.AddArgument(this.Path);
if (this.Body != null) metadata.AddChild(this.Body);
if (this.Resource != null) metadata.AddVariable(this.Resource);
}
protected override void Execute(NativeActivityContext context)
{
this.Resource.Set(context, new StreamReader(this.Path.Get(context)));
context.ScheduleActivity(this.Body, new completionCallback(Done), new FaultCallback(Faulted));
}
private void Done(NativeActivityContext context, ActivityInstance instance)
{
var reader = this.Reader.Get(context);
if (reader != null) reader.Dispose();
}
private void Faulted(NativeActivityFaultContext context, Exception ex, ActivityInstance instance)
{
var reader = this.Reader.Get(context);
if (reader != null) reader.Dispose();
}
}
I cannot view "Resource" or "reader" in the Variables list in the Workflow Designer. Am I missing something in CacheMetadata
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来答案是向类添加一个
Collection
。CacheMetadata
是不必要的。编辑:不,现在出现错误,表明变量被定义了多次。如果我没有将资源添加到变量集合中,它就不会显示...
编辑#2:我将此作为 Microsoft Connect 上的错误提交,并被告知这是一个已知错误, 但它不是 VS 2010 中修复的目标。它已被推迟。
It appears the answer was adding an
Collection<Variable>
to the class.CacheMetadata
was unnecessary.EDIT: Nope, now an error occurs which states the Variable is defined multiple times. If I leave out adding the resource to the variables collection it just doesn't show up...
EDIT #2: I submitted this as a bug on Microsoft Connect and was told this is a known bug, but it is not targetted for a fix in VS 2010. It has been postponed.
如果您想在活动本身和子活动之间共享变量,则需要将 Body 定义为 ActivityAction 类型而不是 Activity 类型。请参阅这篇博客文章由马特·温克勒 (Matt Winkler) 撰写。
You need to define your Body as type ActivityAction instead of Activity if you want to share a variable between the activity itself and the children. See this blog post by Matt Winkler.