向工作流设计器公开 NativeActivity 变量

发布于 2024-09-05 00:09:39 字数 1848 浏览 4 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌吟 2024-09-12 00:09:39

看来答案是向类添加一个CollectionCacheMetadata 是不必要的。

[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public Collection<Variable> Variables { get; private set; }

public ResourceActivity()
{
    this.Resource = new Variable<StreamReader> { Default = null, Name = "reader" };
    this.Variables = new Collection<Variable>(new [] { this.Resource });
}

编辑:不,现在出现错误,表明变量被定义了多次。如果我没有将资源添加到变量集合中,它就不会显示...

编辑#2:我将此作为 Microsoft Connect 上的错误提交,并被告知这是一个已知错误, 但它不是 VS 2010 中修复的目标。它已被推迟。

It appears the answer was adding an Collection<Variable> to the class. CacheMetadata was unnecessary.

[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public Collection<Variable> Variables { get; private set; }

public ResourceActivity()
{
    this.Resource = new Variable<StreamReader> { Default = null, Name = "reader" };
    this.Variables = new Collection<Variable>(new [] { this.Resource });
}

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.

少年亿悲伤 2024-09-12 00:09:39

如果您想在活动本身和子活动之间共享变量,则需要将 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文